2005-05-11 17:56:09 +02:00
|
|
|
/* Unit test suite for Ntdll atom API functions
|
|
|
|
*
|
|
|
|
* Copyright 2003 Gyorgy 'Nog' Jeney
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-05-11 17:56:09 +02:00
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* We use function pointers here as there is no import library for NTDLL on
|
|
|
|
* windows.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
2005-08-11 19:04:07 +02:00
|
|
|
|
|
|
|
#include "ntstatus.h"
|
|
|
|
/* Define WIN32_NO_STATUS so MSVC does not give us duplicate macro
|
|
|
|
* definition errors when we get to winnt.h
|
|
|
|
*/
|
|
|
|
#define WIN32_NO_STATUS
|
|
|
|
|
2005-05-11 17:56:09 +02:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winreg.h"
|
|
|
|
#include "winnls.h"
|
2001-09-17 00:00:00 +02:00
|
|
|
#include "winuser.h"
|
2005-05-11 17:56:09 +02:00
|
|
|
#include "wine/test.h"
|
|
|
|
#include "winternl.h"
|
|
|
|
|
2005-08-11 19:04:07 +02:00
|
|
|
#ifndef __WINE_WINTERNL_H
|
|
|
|
typedef unsigned short RTL_ATOM, *PRTL_ATOM;
|
|
|
|
typedef struct atom_table *RTL_ATOM_TABLE, **PRTL_ATOM_TABLE;
|
|
|
|
#endif
|
|
|
|
|
2005-05-11 17:56:09 +02:00
|
|
|
/* Function pointers for ntdll calls */
|
|
|
|
static HMODULE hntdll = 0;
|
|
|
|
static NTSTATUS (WINAPI *pRtlCreateAtomTable)(ULONG,PRTL_ATOM_TABLE);
|
|
|
|
static NTSTATUS (WINAPI *pRtlDestroyAtomTable)(RTL_ATOM_TABLE);
|
|
|
|
static NTSTATUS (WINAPI *pRtlEmptyAtomTable)(RTL_ATOM_TABLE,BOOLEAN);
|
|
|
|
static NTSTATUS (WINAPI *pRtlAddAtomToAtomTable)(RTL_ATOM_TABLE,PCWSTR,PRTL_ATOM);
|
|
|
|
static NTSTATUS (WINAPI *pRtlDeleteAtomFromAtomTable)(RTL_ATOM_TABLE,RTL_ATOM);
|
|
|
|
static NTSTATUS (WINAPI *pRtlLookupAtomInAtomTable)(RTL_ATOM_TABLE,PCWSTR,PRTL_ATOM);
|
|
|
|
static NTSTATUS (WINAPI *pRtlPinAtomInAtomTable)(RTL_ATOM_TABLE,RTL_ATOM);
|
|
|
|
static NTSTATUS (WINAPI *pRtlQueryAtomInAtomTable)(RTL_ATOM_TABLE,RTL_ATOM,PULONG,PULONG,PWSTR,PULONG);
|
|
|
|
|
2006-01-03 17:34:43 +01:00
|
|
|
static NTSTATUS (WINAPI* pNtAddAtom)(LPCWSTR,ULONG,RTL_ATOM*);
|
2008-11-10 11:57:26 +01:00
|
|
|
static NTSTATUS (WINAPI* pNtAddAtomNT4)(LPCWSTR,RTL_ATOM*);
|
2006-01-03 17:34:43 +01:00
|
|
|
static NTSTATUS (WINAPI* pNtQueryInformationAtom)(RTL_ATOM,DWORD,void*,ULONG,PULONG);
|
|
|
|
|
2005-05-11 17:56:09 +02:00
|
|
|
static const WCHAR EmptyAtom[] = {0};
|
|
|
|
static const WCHAR testAtom1[] = {'H','e','l','l','o',' ','W','o','r','l','d',0};
|
|
|
|
static const WCHAR testAtom2[] = {'H','e','l','l','o',' ','W','o','r','l','d','2',0};
|
|
|
|
static const WCHAR testAtom3[] = {'H','e','l','l','o',' ','W','o','r','l','d','3',0};
|
|
|
|
|
|
|
|
static const WCHAR testAtom1Cap[] = {'H','E','L','L','O',' ','W','O','R','L','D',0};
|
|
|
|
static const WCHAR testAtom1Low[] = {'h','e','l','l','o',' ','w','o','r','l','d',0};
|
|
|
|
|
|
|
|
static const WCHAR testAtomInt[] = {'#','1','3','2',0};
|
|
|
|
static const WCHAR testAtomIntInv[] = {'#','2','3','4','z',0};
|
|
|
|
static const WCHAR testAtomOTT[] = {'#','1','2','3',0};
|
|
|
|
|
|
|
|
static void InitFunctionPtr(void)
|
|
|
|
{
|
|
|
|
hntdll = LoadLibraryA("ntdll.dll");
|
|
|
|
ok(hntdll != 0, "Unable to load ntdll.dll\n");
|
|
|
|
|
|
|
|
if (hntdll)
|
|
|
|
{
|
|
|
|
pRtlCreateAtomTable = (void *)GetProcAddress(hntdll, "RtlCreateAtomTable");
|
|
|
|
pRtlDestroyAtomTable = (void *)GetProcAddress(hntdll, "RtlDestroyAtomTable");
|
|
|
|
pRtlEmptyAtomTable = (void *)GetProcAddress(hntdll, "RtlEmptyAtomTable");
|
|
|
|
pRtlAddAtomToAtomTable = (void *)GetProcAddress(hntdll, "RtlAddAtomToAtomTable");
|
|
|
|
pRtlDeleteAtomFromAtomTable = (void *)GetProcAddress(hntdll, "RtlDeleteAtomFromAtomTable");
|
|
|
|
pRtlLookupAtomInAtomTable = (void *)GetProcAddress(hntdll, "RtlLookupAtomInAtomTable");
|
|
|
|
pRtlPinAtomInAtomTable = (void *)GetProcAddress(hntdll, "RtlPinAtomInAtomTable");
|
|
|
|
pRtlQueryAtomInAtomTable = (void *)GetProcAddress(hntdll, "RtlQueryAtomInAtomTable");
|
2006-01-03 17:34:43 +01:00
|
|
|
|
|
|
|
pNtAddAtom = (void *)GetProcAddress(hntdll, "NtAddAtom");
|
|
|
|
pNtQueryInformationAtom = (void *)GetProcAddress(hntdll, "NtQueryInformationAtom");
|
2005-05-11 17:56:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-10 20:54:16 +02:00
|
|
|
static DWORD WINAPI RtlAtomTestThread(LPVOID Table)
|
2005-05-11 17:56:09 +02:00
|
|
|
{
|
|
|
|
RTL_ATOM_TABLE AtomTable = *(PRTL_ATOM_TABLE)Table;
|
|
|
|
RTL_ATOM Atom;
|
|
|
|
NTSTATUS res;
|
|
|
|
ULONG RefCount = 0, PinCount = 0, Len = 0;
|
|
|
|
WCHAR Name[64];
|
|
|
|
|
|
|
|
res = pRtlLookupAtomInAtomTable(AtomTable, testAtom1, &Atom);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "Unable to find atom from another thread, retval: %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
|
|
|
|
res = pRtlLookupAtomInAtomTable(AtomTable, testAtom2, &Atom);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "Unable to lookup pinned atom in table, retval: %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
|
|
|
|
res = pRtlQueryAtomInAtomTable(AtomTable, Atom, &RefCount, &PinCount, Name, &Len);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(res == STATUS_BUFFER_TOO_SMALL, "We got wrong retval: %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
|
|
|
|
Len = 64;
|
|
|
|
res = pRtlQueryAtomInAtomTable(AtomTable, Atom, &RefCount, &PinCount, Name, &Len);
|
2011-08-03 23:50:18 +02:00
|
|
|
ok(!res, "Failed with long enough buffer, retval: %x\n", res);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(RefCount == 1, "Refcount was not 1 but %x\n", RefCount);
|
|
|
|
ok(PinCount == 1, "Pincount was not 1 but %x\n", PinCount);
|
2006-05-24 18:05:09 +02:00
|
|
|
ok(!lstrcmpW(Name, testAtom2), "We found wrong atom!!\n");
|
2006-10-13 23:33:02 +02:00
|
|
|
ok((lstrlenW(testAtom2) * sizeof(WCHAR)) == Len, "Returned wrong length %d\n", Len);
|
2005-05-11 17:56:09 +02:00
|
|
|
|
|
|
|
Len = 64;
|
|
|
|
res = pRtlQueryAtomInAtomTable(AtomTable, Atom, NULL, NULL, Name, &Len);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "RtlQueryAtomInAtomTable with optional args invalid failed, retval: %x\n", res);
|
2006-05-24 18:05:09 +02:00
|
|
|
ok(!lstrcmpW(Name, testAtom2), "Found Wrong atom!\n");
|
2006-10-13 23:33:02 +02:00
|
|
|
ok((lstrlenW(testAtom2) * sizeof(WCHAR)) == Len, "Returned wrong length %d\n", Len);
|
2005-05-11 17:56:09 +02:00
|
|
|
|
|
|
|
res = pRtlPinAtomInAtomTable(AtomTable, Atom);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "Unable to pin atom in atom table, retval: %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_NtAtom(void)
|
|
|
|
{
|
|
|
|
RTL_ATOM_TABLE AtomTable = NULL;
|
|
|
|
NTSTATUS res;
|
|
|
|
RTL_ATOM Atom1, Atom2, Atom3, testEAtom, testAtom;
|
|
|
|
HANDLE testThread;
|
|
|
|
ULONG RefCount = 0, PinCount = 0, Len = 0;
|
|
|
|
WCHAR Name[64];
|
|
|
|
|
|
|
|
/* If we pass a non-null string to create atom table, then it thinks that we
|
|
|
|
* have passed it an already allocated atom table */
|
|
|
|
res = pRtlCreateAtomTable(0, &AtomTable);
|
|
|
|
ok(!res, "RtlCreateAtomTable should succeed with an atom table size of 0\n");
|
|
|
|
|
|
|
|
if (!res)
|
|
|
|
{
|
|
|
|
res = pRtlDestroyAtomTable(AtomTable);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "We could create the atom table, but we couldn't destroy it! retval: %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
AtomTable = NULL;
|
|
|
|
res = pRtlCreateAtomTable(37, &AtomTable);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "We're unable to create an atom table with a valid table size retval: %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
if (!res)
|
|
|
|
{
|
|
|
|
res = pRtlAddAtomToAtomTable(AtomTable, testAtom1, &Atom1);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "We were unable to add a simple atom to the atom table, retval: %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
|
|
|
|
res = pRtlLookupAtomInAtomTable(AtomTable, testAtom1Cap, &testAtom);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "We were unable to find capital version of the atom, retval: %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
ok(Atom1 == testAtom, "Found wrong atom in table when querying capital atom\n");
|
|
|
|
|
|
|
|
res = pRtlLookupAtomInAtomTable(AtomTable, testAtom1Low, &testAtom);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "Unable to find lowercase version of the atom, retval: %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
ok(testAtom == Atom1, "Found wrong atom when querying lowercase atom\n");
|
|
|
|
|
|
|
|
res = pRtlAddAtomToAtomTable(AtomTable, EmptyAtom, &testEAtom);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(res == STATUS_OBJECT_NAME_INVALID, "Got wrong retval, retval: %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
|
|
|
|
res = pRtlLookupAtomInAtomTable(AtomTable, testAtom1, &testAtom);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "Failed to find totally legitimate atom, retval: %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
ok(testAtom == Atom1, "Found wrong atom!\n");
|
|
|
|
|
|
|
|
res = pRtlAddAtomToAtomTable(AtomTable, testAtom2, &Atom2);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "Unable to add other legitimate atom to table, retval: %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
|
|
|
|
res = pRtlPinAtomInAtomTable(AtomTable, Atom2);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "Unable to pin atom in atom table, retval: %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
|
2007-05-10 20:54:16 +02:00
|
|
|
testThread = CreateThread(NULL, 0, RtlAtomTestThread, &AtomTable, 0, NULL);
|
2005-05-11 17:56:09 +02:00
|
|
|
WaitForSingleObject(testThread, INFINITE);
|
2018-01-04 10:22:52 +01:00
|
|
|
CloseHandle(testThread);
|
2005-05-11 17:56:09 +02:00
|
|
|
|
|
|
|
Len = 64;
|
|
|
|
res = pRtlQueryAtomInAtomTable(AtomTable, Atom2, &RefCount, &PinCount, Name, &Len);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "Unable to query atom in atom table, retval: %x\n", res);
|
|
|
|
ok(RefCount == 1, "RefCount is not 1 but %x\n", RefCount);
|
|
|
|
ok(PinCount == 1, "PinCount is not 1 but %x\n", PinCount);
|
2006-05-24 18:05:09 +02:00
|
|
|
ok(!lstrcmpW(Name, testAtom2), "We found wrong atom\n");
|
2006-10-13 23:33:02 +02:00
|
|
|
ok((lstrlenW(testAtom2) * sizeof(WCHAR)) == Len, "Returned wrong length %d\n", Len);
|
2005-05-11 17:56:09 +02:00
|
|
|
|
|
|
|
res = pRtlEmptyAtomTable(AtomTable, FALSE);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "Unable to empty atom table, retval %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
|
|
|
|
Len = 64;
|
|
|
|
res = pRtlQueryAtomInAtomTable(AtomTable, Atom2, &RefCount, &PinCount, Name, &Len);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "It seems RtlEmptyAtomTable deleted our pinned atom eaven though we asked it not to, retval: %x\n", res);
|
|
|
|
ok(RefCount == 1, "RefCount is not 1 but %x\n", RefCount);
|
|
|
|
ok(PinCount == 1, "PinCount is not 1 but %x\n", PinCount);
|
2006-05-24 18:05:09 +02:00
|
|
|
ok(!lstrcmpW(Name, testAtom2), "We found wrong atom\n");
|
2006-10-13 23:33:02 +02:00
|
|
|
ok((lstrlenW(testAtom2) * sizeof(WCHAR)) == Len, "Returned wrong length %d\n", Len);
|
2005-05-11 17:56:09 +02:00
|
|
|
|
2006-01-03 17:34:43 +01:00
|
|
|
Len = 8;
|
2008-03-05 12:04:35 +01:00
|
|
|
Name[0] = Name[1] = Name[2] = Name[3] = Name[4] = 0x1337;
|
2006-01-03 17:34:43 +01:00
|
|
|
res = pRtlQueryAtomInAtomTable(AtomTable, Atom2, NULL, NULL, Name, &Len);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "query atom %x\n", res);
|
|
|
|
ok(Len == 6, "wrong length %u\n", Len);
|
2006-01-03 17:34:43 +01:00
|
|
|
ok(!memcmp(Name, testAtom2, Len), "wrong atom string\n");
|
|
|
|
ok(!Name[3], "wrong string termination\n");
|
2008-03-05 12:04:35 +01:00
|
|
|
ok(Name[4] == 0x1337, "buffer overwrite\n");
|
2006-01-03 17:34:43 +01:00
|
|
|
|
2006-02-06 11:26:57 +01:00
|
|
|
Len = lstrlenW(testAtom2) * sizeof(WCHAR);
|
|
|
|
memset(Name, '.', sizeof(Name));
|
|
|
|
res = pRtlQueryAtomInAtomTable( AtomTable, Atom2, NULL, NULL, Name, &Len );
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "query atom %x\n", res);
|
|
|
|
ok(Len == (lstrlenW(testAtom2) - 1) * sizeof(WCHAR), "wrong length %u\n", Len);
|
2006-02-06 11:26:57 +01:00
|
|
|
ok(!memcmp(testAtom2, Name, (lstrlenW(testAtom2) - 1) * sizeof(WCHAR)), "wrong atom name\n");
|
|
|
|
ok(Name[lstrlenW(testAtom2) - 1] == '\0', "wrong char\n");
|
|
|
|
ok(Name[lstrlenW(testAtom2)] == ('.' << 8) + '.', "wrong char\n");
|
|
|
|
|
2005-05-11 17:56:09 +02:00
|
|
|
res = pRtlLookupAtomInAtomTable(AtomTable, testAtom2, &testAtom);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "We can't find our pinned atom!! retval: %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
ok(testAtom == Atom2, "We found wrong atom!!!\n");
|
|
|
|
|
|
|
|
res = pRtlLookupAtomInAtomTable(AtomTable, testAtom1, &testAtom);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(res == STATUS_OBJECT_NAME_NOT_FOUND, "We found the atom in our table eaven though we asked RtlEmptyAtomTable to remove it, retval: %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
|
|
|
|
res = pRtlAddAtomToAtomTable(AtomTable, testAtom3, &Atom3);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "Unable to add atom to table, retval: %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
|
|
|
|
res = pRtlEmptyAtomTable(AtomTable, TRUE);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "Unable to empty atom table, retval: %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
|
|
|
|
res = pRtlLookupAtomInAtomTable(AtomTable, testAtom2, &testAtom);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(res == STATUS_OBJECT_NAME_NOT_FOUND, "The pinned atom should be removed, retval: %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
|
|
|
|
res = pRtlLookupAtomInAtomTable(AtomTable, testAtom3, &testAtom);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(res == STATUS_OBJECT_NAME_NOT_FOUND, "Non pinned atom should also be removed, retval: %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
|
|
|
|
res = pRtlDestroyAtomTable(AtomTable);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "Can't destroy atom table, retval: %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
AtomTable = NULL;
|
|
|
|
res = pRtlCreateAtomTable(37, &AtomTable);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "Unable to create atom table, retval: %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
|
|
|
|
if (!res)
|
|
|
|
{
|
|
|
|
res = pRtlLookupAtomInAtomTable(AtomTable, testAtom1, &testAtom);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(res == STATUS_OBJECT_NAME_NOT_FOUND, "Didn't get expected retval with querying an empty atom table, retval: %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
|
|
|
|
res = pRtlAddAtomToAtomTable(AtomTable, testAtom1, &Atom1);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "Unable to add atom to atom table, retval %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
|
|
|
|
res = pRtlLookupAtomInAtomTable(AtomTable, testAtom1, &testAtom);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "Can't find previously added atom in table, retval: %x\n", res);
|
|
|
|
ok(testAtom == Atom1, "Found wrong atom! retval: %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
|
|
|
|
res = pRtlDeleteAtomFromAtomTable(AtomTable, Atom1);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "Unable to delete atom from table, retval: %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
|
|
|
|
res = pRtlLookupAtomInAtomTable(AtomTable, testAtom1, &testAtom);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(res == STATUS_OBJECT_NAME_NOT_FOUND, "Able to find previously deleted atom in table, retval: %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
|
|
|
|
res = pRtlAddAtomToAtomTable(AtomTable, testAtom1, &Atom1);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "Unable to add atom to atom table, retval: %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
|
|
|
|
Len = 0;
|
|
|
|
res = pRtlQueryAtomInAtomTable(AtomTable, Atom1, NULL, NULL, Name, &Len);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(res == STATUS_BUFFER_TOO_SMALL, "Got wrong retval, retval: %x\n", res);
|
2008-11-10 11:57:26 +01:00
|
|
|
ok((lstrlenW(testAtom1) * sizeof(WCHAR)) == Len || broken(!Len) /* nt4 */, "Got wrong length %x\n", Len);
|
|
|
|
if (!Len) pNtAddAtomNT4 = (void *)pNtAddAtom;
|
2005-05-11 17:56:09 +02:00
|
|
|
|
|
|
|
res = pRtlPinAtomInAtomTable(AtomTable, Atom1);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "Unable to pin atom in atom table, retval: %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
|
|
|
|
res = pRtlLookupAtomInAtomTable(AtomTable, testAtom1, &testAtom);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "Unable to find atom in atom table, retval: %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
ok(testAtom == Atom1, "Wrong atom found\n");
|
|
|
|
|
|
|
|
res = pRtlDeleteAtomFromAtomTable(AtomTable, Atom1);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(res == STATUS_WAS_LOCKED, "Unable to delete atom from table, retval: %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
|
|
|
|
res = pRtlLookupAtomInAtomTable(AtomTable, testAtom1, &testAtom);
|
|
|
|
ok(!res, "Able to find deleted atom in table\n");
|
|
|
|
|
|
|
|
res = pRtlDestroyAtomTable(AtomTable);
|
|
|
|
ok(!res, "Unable to destroy atom table\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Test Adding integer atoms to atom table */
|
|
|
|
static void test_NtIntAtom(void)
|
|
|
|
{
|
|
|
|
NTSTATUS res;
|
|
|
|
RTL_ATOM_TABLE AtomTable;
|
|
|
|
RTL_ATOM testAtom;
|
|
|
|
ULONG RefCount = 0, PinCount = 0;
|
2009-01-03 20:14:01 +01:00
|
|
|
INT_PTR i;
|
2005-05-11 17:56:09 +02:00
|
|
|
WCHAR Name[64];
|
|
|
|
ULONG Len;
|
|
|
|
|
|
|
|
AtomTable = NULL;
|
|
|
|
res = pRtlCreateAtomTable(37, &AtomTable);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "Unable to create atom table, %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
|
|
|
|
if (!res)
|
|
|
|
{
|
2008-04-08 23:22:43 +02:00
|
|
|
/* According to the kernel32 functions, integer atoms are only allowed from
|
2005-05-11 17:56:09 +02:00
|
|
|
* 0x0001 to 0xbfff and not 0xc000 to 0xffff, which is correct */
|
2008-12-01 11:10:18 +01:00
|
|
|
res = pRtlAddAtomToAtomTable(AtomTable, NULL, &testAtom);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(res == STATUS_INVALID_PARAMETER, "Didn't get expected result from adding 0 int atom, retval: %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
for (i = 1; i <= 0xbfff; i++)
|
|
|
|
{
|
2009-01-03 20:14:01 +01:00
|
|
|
res = pRtlAddAtomToAtomTable(AtomTable, (LPWSTR)i, &testAtom);
|
|
|
|
ok(!res, "Unable to add valid integer atom %li, retval: %x\n", i, res);
|
2005-05-11 17:56:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 1; i <= 0xbfff; i++)
|
|
|
|
{
|
2009-01-03 20:14:01 +01:00
|
|
|
res = pRtlLookupAtomInAtomTable(AtomTable, (LPWSTR)i, &testAtom);
|
|
|
|
ok(!res, "Unable to find int atom %li, retval: %x\n", i, res);
|
2005-05-11 17:56:09 +02:00
|
|
|
if (!res)
|
|
|
|
{
|
|
|
|
res = pRtlPinAtomInAtomTable(AtomTable, testAtom);
|
2009-01-03 20:14:01 +01:00
|
|
|
ok(!res, "Unable to pin int atom %li, retval: %x\n", i, res);
|
2005-05-11 17:56:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0xc000; i <= 0xffff; i++)
|
|
|
|
{
|
2009-01-03 20:14:01 +01:00
|
|
|
res = pRtlAddAtomToAtomTable(AtomTable, (LPWSTR)i, &testAtom);
|
|
|
|
ok(res, "Able to illeageal integer atom %li, retval: %x\n", i, res);
|
2005-05-11 17:56:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
res = pRtlDestroyAtomTable(AtomTable);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "Unable to destroy atom table, retval: %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
AtomTable = NULL;
|
|
|
|
res = pRtlCreateAtomTable(37, &AtomTable);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "Unable to create atom table, %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
if (!res)
|
|
|
|
{
|
|
|
|
res = pRtlLookupAtomInAtomTable(AtomTable, (PWSTR)123, &testAtom);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "Unable to query atom in atom table, retval: %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
|
|
|
|
res = pRtlAddAtomToAtomTable(AtomTable, testAtomInt, &testAtom);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "Unable to add int atom to table, retval: %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
|
|
|
|
res = pRtlAddAtomToAtomTable(AtomTable, testAtomIntInv, &testAtom);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "Unable to add int atom to table, retval: %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
|
|
|
|
res = pRtlAddAtomToAtomTable(AtomTable, (PWSTR)123, &testAtom);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "Unable to add int atom to table, retval: %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
|
|
|
|
res = pRtlAddAtomToAtomTable(AtomTable, (PWSTR)123, &testAtom);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "Unable to re-add int atom to table, retval: %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
|
|
|
|
Len = 64;
|
|
|
|
res = pRtlQueryAtomInAtomTable(AtomTable, testAtom, &RefCount, &PinCount, Name, &Len);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "Unable to query atom in atom table, retval: %x\n", res);
|
|
|
|
ok(PinCount == 1, "Expected pincount 1 but got %x\n", PinCount);
|
|
|
|
ok(RefCount == 1, "Expected refcount 1 but got %x\n", RefCount);
|
2006-05-24 18:05:09 +02:00
|
|
|
ok(!lstrcmpW(testAtomOTT, Name), "Got wrong atom name\n");
|
2006-10-13 23:33:02 +02:00
|
|
|
ok((lstrlenW(testAtomOTT) * sizeof(WCHAR)) == Len, "Got wrong len %d\n", Len);
|
2005-05-11 17:56:09 +02:00
|
|
|
|
|
|
|
res = pRtlPinAtomInAtomTable(AtomTable, testAtom);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "Unable to pin int atom, retval: %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
|
|
|
|
res = pRtlPinAtomInAtomTable(AtomTable, testAtom);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "Unable to pin int atom, retval: %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
|
|
|
|
res = pRtlQueryAtomInAtomTable(AtomTable, testAtom, &RefCount, &PinCount, NULL, NULL);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "Unable to query atom in atom table, retval: %x\n", res);
|
|
|
|
ok(PinCount == 1, "Expected pincount 1 but got %x\n", PinCount);
|
|
|
|
ok(RefCount == 1, "Expected refcount 1 but got %x\n", RefCount);
|
2005-05-11 17:56:09 +02:00
|
|
|
|
|
|
|
res = pRtlDestroyAtomTable(AtomTable);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "Unable to destroy atom table, retval: %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Tests to see how the pincount and refcount actually works */
|
|
|
|
static void test_NtRefPinAtom(void)
|
|
|
|
{
|
|
|
|
RTL_ATOM_TABLE AtomTable;
|
|
|
|
RTL_ATOM Atom;
|
|
|
|
ULONG PinCount = 0, RefCount = 0;
|
|
|
|
NTSTATUS res;
|
|
|
|
|
|
|
|
AtomTable = NULL;
|
|
|
|
res = pRtlCreateAtomTable(37, &AtomTable);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "Unable to create atom table, %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
|
|
|
|
if (!res)
|
|
|
|
{
|
|
|
|
res = pRtlAddAtomToAtomTable(AtomTable, testAtom1, &Atom);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "Unable to add our atom to the atom table, retval: %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
|
|
|
|
res = pRtlAddAtomToAtomTable(AtomTable, testAtom1, &Atom);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "Unable to add our atom to the atom table, retval: %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
|
|
|
|
res = pRtlAddAtomToAtomTable(AtomTable, testAtom1, &Atom);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "Unable to add our atom to the atom table, retval: %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
|
|
|
|
res = pRtlQueryAtomInAtomTable(AtomTable, Atom, &RefCount, &PinCount, NULL, NULL);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "Unable to query atom in atom table, retval: %x\n", res);
|
|
|
|
ok(PinCount == 0, "Expected pincount 0 but got %x\n", PinCount);
|
|
|
|
ok(RefCount == 3, "Expected refcount 3 but got %x\n", RefCount);
|
2005-05-11 17:56:09 +02:00
|
|
|
|
|
|
|
res = pRtlPinAtomInAtomTable(AtomTable, Atom);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "Unable to pin atom in atom table, retval: %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
|
|
|
|
res = pRtlPinAtomInAtomTable(AtomTable, Atom);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "Unable to pin atom in atom table, retval: %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
|
|
|
|
res = pRtlPinAtomInAtomTable(AtomTable, Atom);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "Unable to pin atom in atom table, retval: %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
|
|
|
|
res = pRtlQueryAtomInAtomTable(AtomTable, Atom, &RefCount, &PinCount, NULL, NULL);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "Unable to query atom in atom table, retval: %x\n", res);
|
|
|
|
ok(PinCount == 1, "Expected pincount 1 but got %x\n", PinCount);
|
|
|
|
ok(RefCount == 3, "Expected refcount 3 but got %x\n", RefCount);
|
2005-05-11 17:56:09 +02:00
|
|
|
|
|
|
|
res = pRtlDestroyAtomTable(AtomTable);
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "Unable to destroy atom table, retval: %x\n", res);
|
2005-05-11 17:56:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-03 17:34:43 +01:00
|
|
|
static void test_Global(void)
|
|
|
|
{
|
|
|
|
NTSTATUS res;
|
|
|
|
RTL_ATOM atom;
|
2015-04-21 17:14:08 +02:00
|
|
|
ULONG ptr[(sizeof(ATOM_BASIC_INFORMATION) + 255 * sizeof(WCHAR)) / sizeof(ULONG)];
|
2006-01-03 17:34:43 +01:00
|
|
|
ATOM_BASIC_INFORMATION* abi = (ATOM_BASIC_INFORMATION*)ptr;
|
2015-04-21 17:14:08 +02:00
|
|
|
ULONG ptr_size = sizeof(ptr);
|
2006-01-03 17:34:43 +01:00
|
|
|
|
2008-11-10 11:57:26 +01:00
|
|
|
if (pNtAddAtomNT4)
|
|
|
|
res = pNtAddAtomNT4(testAtom1, &atom);
|
|
|
|
else
|
|
|
|
res = pNtAddAtom(testAtom1, lstrlenW(testAtom1) * sizeof(WCHAR), &atom);
|
|
|
|
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "Added atom (%x)\n", res);
|
2006-01-03 17:34:43 +01:00
|
|
|
|
2011-10-20 12:36:02 +02:00
|
|
|
memset( ptr, 0xcc, sizeof(ptr) );
|
2006-01-03 17:34:43 +01:00
|
|
|
res = pNtQueryInformationAtom( atom, AtomBasicInformation, (void*)ptr, ptr_size, NULL );
|
|
|
|
ok(!res, "atom lookup\n");
|
|
|
|
ok(!lstrcmpW(abi->Name, testAtom1), "ok strings\n");
|
|
|
|
ok(abi->NameLength == lstrlenW(testAtom1) * sizeof(WCHAR), "wrong string length\n");
|
|
|
|
ok(abi->Name[lstrlenW(testAtom1)] == 0, "wrong string termination %x\n", abi->Name[lstrlenW(testAtom1)]);
|
2008-03-05 12:04:35 +01:00
|
|
|
ok(abi->Name[lstrlenW(testAtom1) + 1] == 0xcccc, "buffer overwrite %x\n", abi->Name[lstrlenW(testAtom1) + 1]);
|
2006-01-03 17:34:43 +01:00
|
|
|
|
|
|
|
ptr_size = sizeof(ATOM_BASIC_INFORMATION);
|
|
|
|
res = pNtQueryInformationAtom( atom, AtomBasicInformation, (void*)ptr, ptr_size, NULL );
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(res == STATUS_BUFFER_TOO_SMALL, "wrong return status (%x)\n", res);
|
2008-11-10 11:57:26 +01:00
|
|
|
ok(abi->NameLength == lstrlenW(testAtom1) * sizeof(WCHAR) || broken(abi->NameLength == sizeof(WCHAR)), /* nt4 */
|
|
|
|
"string length %u\n",abi->NameLength);
|
2006-01-03 17:34:43 +01:00
|
|
|
|
2011-10-20 12:36:02 +02:00
|
|
|
memset( ptr, 0xcc, sizeof(ptr) );
|
2006-01-03 17:34:43 +01:00
|
|
|
ptr_size = sizeof(ATOM_BASIC_INFORMATION) + lstrlenW(testAtom1) * sizeof(WCHAR);
|
|
|
|
res = pNtQueryInformationAtom( atom, AtomBasicInformation, (void*)ptr, ptr_size, NULL );
|
2006-10-13 23:33:02 +02:00
|
|
|
ok(!res, "atom lookup %x\n", res);
|
2006-01-03 17:34:43 +01:00
|
|
|
ok(!lstrcmpW(abi->Name, testAtom1), "strings don't match\n");
|
|
|
|
ok(abi->NameLength == lstrlenW(testAtom1) * sizeof(WCHAR), "wrong string length\n");
|
|
|
|
ok(abi->Name[lstrlenW(testAtom1)] == 0, "buffer overwrite %x\n", abi->Name[lstrlenW(testAtom1)]);
|
2008-03-05 12:04:35 +01:00
|
|
|
ok(abi->Name[lstrlenW(testAtom1) + 1] == 0xcccc, "buffer overwrite %x\n", abi->Name[lstrlenW(testAtom1) + 1]);
|
2006-01-03 17:34:43 +01:00
|
|
|
|
2011-10-20 12:36:02 +02:00
|
|
|
memset( ptr, 0xcc, sizeof(ptr) );
|
2006-01-03 17:34:43 +01:00
|
|
|
ptr_size = sizeof(ATOM_BASIC_INFORMATION) + 4 * sizeof(WCHAR);
|
|
|
|
res = pNtQueryInformationAtom( atom, AtomBasicInformation, (void*)ptr, ptr_size, NULL );
|
|
|
|
ok(!res, "couldn't find atom\n");
|
|
|
|
ok(abi->NameLength == 8, "wrong string length %u\n", abi->NameLength);
|
|
|
|
ok(!memcmp(abi->Name, testAtom1, 8), "strings don't match\n");
|
|
|
|
}
|
|
|
|
|
2005-05-11 17:56:09 +02:00
|
|
|
START_TEST(atom)
|
|
|
|
{
|
|
|
|
InitFunctionPtr();
|
|
|
|
if (pRtlCreateAtomTable)
|
|
|
|
{
|
2001-09-17 00:00:00 +02:00
|
|
|
/* Global atom table seems to be available to GUI apps only in
|
|
|
|
Win7, so let's turn this app into a GUI app */
|
|
|
|
GetDesktopWindow();
|
|
|
|
|
2005-05-11 17:56:09 +02:00
|
|
|
test_NtAtom();
|
|
|
|
test_NtIntAtom();
|
|
|
|
test_NtRefPinAtom();
|
2006-01-03 17:34:43 +01:00
|
|
|
test_Global();
|
2005-05-11 17:56:09 +02:00
|
|
|
}
|
2008-09-21 20:11:40 +02:00
|
|
|
else
|
|
|
|
win_skip("Needed atom functions are not available\n");
|
|
|
|
|
|
|
|
FreeLibrary(hntdll);
|
2005-05-11 17:56:09 +02:00
|
|
|
}
|