mirror of
git://source.winehq.org/git/wine.git
synced 2024-10-31 12:54:13 +00:00
kernel: Fixed regression in atom handling.
Added proper tests (local & global functions).
This commit is contained in:
parent
2d0ad0944c
commit
dccd41a88a
3 changed files with 46 additions and 1 deletions
|
@ -485,12 +485,15 @@ UINT WINAPI GlobalGetAtomNameW( ATOM atom, LPWSTR buffer, INT count )
|
|||
{
|
||||
length = min( abi->NameLength / sizeof(WCHAR), count);
|
||||
memcpy( buffer, abi->Name, length * sizeof(WCHAR) );
|
||||
/* yes, the string will not be null terminated if the passed buffer
|
||||
* is one WCHAR too small (and it's not an error)
|
||||
*/
|
||||
if (length < abi->NameLength / sizeof(WCHAR))
|
||||
{
|
||||
SetLastError( ERROR_MORE_DATA );
|
||||
length = count;
|
||||
}
|
||||
else buffer[length] = '\0';
|
||||
else if (length < count) buffer[length] = '\0';
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
|
|
@ -220,6 +220,21 @@ static void test_get_atom_name(void)
|
|||
}
|
||||
}
|
||||
|
||||
memset( buf, '.', sizeof(buf) );
|
||||
len = GlobalGetAtomNameA( atom, buf, 6 );
|
||||
ok( len == 0, "bad length %d\n", len );
|
||||
ok( !memcmp( buf, "fooba\0....", 10 ), "bad buffer contents\n");
|
||||
if (unicode_OS)
|
||||
{
|
||||
static const WCHAR resW[] = {'f','o','o','b','a','r','.','.','.','.'};
|
||||
for (len = 0; len < 10; len++) bufW[len] = '.';
|
||||
SetLastError(0xdeadbeef);
|
||||
len = GlobalGetAtomNameW( atom, bufW, 6 );
|
||||
ok( len && GetLastError() == 0xdeadbeef, "GlobalGetAtomNameW failed\n" );
|
||||
ok( len == lstrlenW(foobarW), "bad length %d\n", len );
|
||||
ok( !memcmp( bufW, resW, 10*sizeof(WCHAR) ), "bad buffer contents\n" );
|
||||
}
|
||||
|
||||
/* test string limits & overflow */
|
||||
do_initA(in, "abcdefghij", 255);
|
||||
atom = GlobalAddAtomA(in);
|
||||
|
@ -428,6 +443,24 @@ static void test_local_get_atom_name(void)
|
|||
ok( !memcmp( bufW, resultW, 10*sizeof(WCHAR) ), "bad buffer contents\n" );
|
||||
}
|
||||
|
||||
/* Get the name of the atom we added above */
|
||||
memset( buf, '.', sizeof(buf) );
|
||||
len = GetAtomNameA( atom, buf, 6 );
|
||||
ok( len == 5, "bad length %d\n", len );
|
||||
ok( !memcmp( buf, "fooba\0....", 10 ), "bad buffer contents\n" );
|
||||
|
||||
/* Repeat, unicode-style */
|
||||
if (unicode_OS)
|
||||
{
|
||||
WCHAR resW[] = {'f','o','o','b','a','\0','.','.','.','.'};
|
||||
for (i = 0; i < 10; i++) bufW[i] = '.';
|
||||
SetLastError( 0xdeadbeef );
|
||||
len = GetAtomNameW( atom, bufW, 6 );
|
||||
ok( len && GetLastError() == 0xdeadbeef, "GlobalGetAtomNameW failed\n" );
|
||||
ok( len == 5, "bad length %d\n", len );
|
||||
ok( !memcmp( bufW, resW, 10*sizeof(WCHAR) ), "bad buffer contents\n" );
|
||||
}
|
||||
|
||||
/* Check error code returns */
|
||||
memset(buf, '.', 10);
|
||||
ok( !GetAtomNameA( atom, buf, 0 ), "succeeded\n" );
|
||||
|
|
|
@ -207,6 +207,15 @@ static void test_NtAtom(void)
|
|||
ok(!Name[3], "wrong string termination\n");
|
||||
ok(Name[4] == 0x55AA, "buffer overwrite\n");
|
||||
|
||||
Len = lstrlenW(testAtom2) * sizeof(WCHAR);
|
||||
memset(Name, '.', sizeof(Name));
|
||||
res = pRtlQueryAtomInAtomTable( AtomTable, Atom2, NULL, NULL, Name, &Len );
|
||||
ok(!res, "query atom %lx\n", res);
|
||||
ok(Len == (lstrlenW(testAtom2) - 1) * sizeof(WCHAR), "wrong length %lu\n", Len);
|
||||
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");
|
||||
|
||||
res = pRtlLookupAtomInAtomTable(AtomTable, testAtom2, &testAtom);
|
||||
ok(!res, "We can't find our pinned atom!! retval: %lx\n", res);
|
||||
ok(testAtom == Atom2, "We found wrong atom!!!\n");
|
||||
|
|
Loading…
Reference in a new issue