Added a bunch of test cases for atoms.

This commit is contained in:
Eric Pouech 2005-09-28 11:58:20 +00:00 committed by Alexandre Julliard
parent 1d34b3a99c
commit c43e416bc3

View file

@ -25,11 +25,53 @@
#include "windef.h"
#include "winbase.h"
#include "winerror.h"
#include "winuser.h"
#define DOUBLE(x) (WCHAR)((x<<8)|(x))
static const WCHAR foobarW[] = {'f','o','o','b','a','r',0};
static const WCHAR FOOBARW[] = {'F','O','O','B','A','R',0};
static const WCHAR _foobarW[] = {'_','f','o','o','b','a','r',0};
static void do_initA(char* tmp, const char* pattern, int len)
{
const char* p = pattern;
while (len--)
{
*tmp++ = *p++;
if (!*p) p = pattern;
}
*tmp = '\0';
}
static void do_initW(WCHAR* tmp, const char* pattern, int len)
{
const char* p = pattern;
while (len--)
{
*tmp++ = *p++;
if (!*p) p = pattern;
}
*tmp = '\0';
}
static void print_integral( WCHAR* buffer, int atom )
{
BOOL first = TRUE;
#define X(v) { if (atom >= v) {*buffer++ = '0' + atom / v; first = FALSE; } else if (!first || v == 1) *buffer++ = '0'; atom %= v; }
*buffer++ = '#';
X(10000);
X(1000);
X(100);
X(10);
X(1);
*buffer = '\0';
#undef X
}
static BOOL unicode_OS;
static void test_add_atom(void)
@ -111,6 +153,8 @@ static void test_get_atom_name(void)
int i;
UINT len;
static const WCHAR resultW[] = {'f','o','o','b','a','r',0,'.','.','.'};
char in[257], out[257];
WCHAR inW[257], outW[257];
ATOM atom = GlobalAddAtomA( "foobar" );
@ -160,6 +204,109 @@ static void test_get_atom_name(void)
}
else
ok( !len, "bad length %d\n", len );
SetLastError(0xdeadbeef);
len = GlobalGetAtomNameA( (ATOM)i, buf, 2);
if (!len) /* the NT way */
{
ok(GetLastError() == (i ? ERROR_MORE_DATA : ERROR_INVALID_PARAMETER),
"wrong error conditions %lu for %u\n", GetLastError(), i);
}
else /* the Win 9x way */
{
ok(GetLastError() == 0xdeadbeef,
"wrong error conditions %lu for %u\n", GetLastError(), i);
}
}
/* test string limits & overflow */
do_initA(in, "abcdefghij", 255);
atom = GlobalAddAtomA(in);
ok(atom, "couldn't add atom for %s\n", in);
len = GlobalGetAtomNameA(atom, out, sizeof(out));
ok(len == 255, "length mismatch (%u instead of 255)\n", len);
for (i = 0; i < 255; i++)
{
ok(out[i] == "abcdefghij"[i % 10], "wrong string at %i (%c instead of %c)\n", i, out[i], "abcdefghij"[i % 10]);
}
ok(out[255] == '\0', "wrong end of string\n");
memset(out, '.', sizeof(out));
SetLastError(0xdeadbeef);
len = GlobalGetAtomNameA(atom, out, 10);
if (!len) /* the NT way */
{
ok(GetLastError() == ERROR_MORE_DATA, "wrong error code (%lu instead of %u)\n", GetLastError(), ERROR_MORE_DATA);
}
else /* the Win9x way */
{
ok(GetLastError() == 0xdeadbeef, "wrong error code (%lu instead of %u)\n", GetLastError(), 0xdeadbeef);
}
for (i = 0; i < 9; i++)
{
ok(out[i] == "abcdefghij"[i % 10], "wrong string at %i (%c instead of %c)\n", i, out[i], "abcdefghij"[i % 10]);
}
ok(out[9] == '\0', "wrong end of string\n");
ok(out[10] == '.', "wrote after end of buf\n");
do_initA(in, "abcdefghij", 256);
atom = GlobalAddAtomA(in);
ok(!atom, "succeeded\n");
if (unicode_OS)
{
/* test integral atoms */
for (i = 0; i <= 0xbfff; i++)
{
memset(outW, 'a', sizeof(outW));
len = GlobalGetAtomNameW( (ATOM)i, outW, 10 );
if (i)
{
WCHAR res[20];
if (len < 7) /* FIXME: temporary before we fix it */
ok( (len > 1) && (len < 7), "bad length %d\n", len );
else
todo_wine ok( (len > 1) && (len < 7), "bad length %d\n", len );
print_integral( res, i );
memset( res + lstrlenW(res) + 1, 'a', 10 * sizeof(WCHAR));
ok( !memcmp( res, outW, 10 * sizeof(WCHAR) ), "bad buffer contents for %d\n", i );
}
else
ok( !len, "bad length %d\n", len );
memset(outW, '.', sizeof(outW));
len = GlobalGetAtomNameW( (ATOM)i, outW, 1);
if (i)
{
todo_wine ok(len == 1, "succeed (got %u instead of 1)\n", len);
ok(outW[1] == DOUBLE('.'), "buffer overwrite\n");
}
else ok(len == 0 && GetLastError() == ERROR_INVALID_PARAMETER, "0 badly handled\n");
}
do_initW(inW, "abcdefghij", 255);
atom = GlobalAddAtomW(inW);
ok(atom, "couldn't add atom for %s\n", in);
len = GlobalGetAtomNameW(atom, outW, sizeof(outW));
ok(len == 255, "length mismatch (%u instead of 255)\n", len);
for (i = 0; i < 255; i++)
{
ok(outW[i] == "abcdefghij"[i % 10], "wrong string at %i (%c instead of %c)\n", i, outW[i], "abcdefghij"[i % 10]);
}
ok(outW[255] == '\0', "wrong end of string\n");
memset(outW, '.', sizeof(outW));
len = GlobalGetAtomNameW(atom, outW, 10);
todo_wine ok(len == 10, "succeeded\n");
for (i = 0; i < 10; i++)
{
if (i < 9) /* FIXME: temporary */
ok(outW[i] == "abcdefghij"[i % 10], "wrong string at %i (%c instead of %c)\n", i, outW[i], "abcdefghij"[i % 10]);
else
todo_wine ok(outW[i] == "abcdefghij"[i % 10], "wrong string at %i (%c instead of %c)\n", i, outW[i], "abcdefghij"[i % 10]);
}
ok(outW[10] == DOUBLE('.'), "wrote after end of buf\n");
do_initW(inW, "abcdefghij", 256);
atom = GlobalAddAtomW(inW);
ok(!atom, "succeeded\n");
ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error code\n");
}
}
@ -257,8 +404,8 @@ static void test_local_add_atom(void)
static void test_local_get_atom_name(void)
{
char buf[10];
WCHAR bufW[10];
char buf[10], in[257], out[257];
WCHAR bufW[10], inW[257], outW[257];
int i;
UINT len;
static const WCHAR resultW[] = {'f','o','o','b','a','r',0,'.','.','.'};
@ -304,13 +451,96 @@ static void test_local_get_atom_name(void)
if (i)
{
char res[20];
ok( (len > 1) && (len < 7), "bad length %d\n", len );
ok( (len > 1) && (len < 7), "bad length %d for %s\n", len, buf );
sprintf( res, "#%d", i );
memset( res + strlen(res) + 1, 'a', 10 );
ok( !memcmp( res, buf, 10 ), "bad buffer contents %s\n", buf );
}
else
ok( !len, "bad length %d\n", len );
len = GetAtomNameA( (ATOM)i, buf, 1);
ok(!len, "succeed\n");
if (i)
todo_wine ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER, "wrong error conditions %lu for %u\n", GetLastError(), i);
else
ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error conditions %lu for %u\n", GetLastError(), i);
}
/* test string limits & overflow */
do_initA(in, "abcdefghij", 255);
atom = AddAtomA(in);
ok(atom, "couldn't add atom for %s\n", in);
len = GetAtomNameA(atom, out, sizeof(out));
ok(len == 255, "length mismatch (%u instead of 255)\n", len);
for (i = 0; i < 255; i++)
{
ok(out[i] == "abcdefghij"[i % 10], "wrong string at %i (%c instead of %c)\n", i, out[i], "abcdefghij"[i % 10]);
}
ok(out[255] == '\0', "wrong end of string\n");
memset(out, '.', sizeof(out));
len = GetAtomNameA(atom, out, 10);
todo_wine ok(len == 9, "succeeded %d\n", len);
for (i = 0; i < 9; i++)
{
ok(out[i] == "abcdefghij"[i % 10], "wrong string at %i (%c instead of %c)\n", i, out[i], "abcdefghij"[i % 10]);
}
ok(out[9] == '\0', "wrong end of string\n");
ok(out[10] == '.', "buffer overwrite\n");
do_initA(in, "abcdefghij", 256);
atom = AddAtomA(in);
ok(!atom, "succeeded\n");
ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error code (%lu)\n", GetLastError());
if (unicode_OS)
{
/* test integral atoms */
for (i = 0; i <= 0xbfff; i++)
{
memset(outW, 'a', sizeof(outW));
len = GetAtomNameW( (ATOM)i, outW, 10 );
if (i)
{
WCHAR res[20];
if (len < 7) /* FIXME: temporary before we fix it */
ok( (len > 1) && (len < 7), "bad length %d\n", len );
else
todo_wine ok( (len > 1) && (len < 7), "bad length %d\n", len );
print_integral( res, i );
memset( res + lstrlenW(res) + 1, 'a', 10 * sizeof(WCHAR));
ok( !memcmp( res, outW, 10 * sizeof(WCHAR) ), "bad buffer contents for %d\n", i );
}
else
ok( !len, "bad length %d\n", len );
len = GetAtomNameW( (ATOM)i, outW, 1);
ok(!len, "succeed\n");
ok(GetLastError() == (i ? ERROR_INSUFFICIENT_BUFFER : ERROR_INVALID_PARAMETER),
"wrong error conditions %lu for %u\n", GetLastError(), i);
}
do_initW(inW, "abcdefghij", 255);
atom = AddAtomW(inW);
ok(atom, "couldn't add atom for %s\n", in);
len = GetAtomNameW(atom, outW, sizeof(outW));
ok(len == 255, "length mismatch (%u instead of 255)\n", len);
for (i = 0; i < 255; i++)
{
ok(outW[i] == "abcdefghij"[i % 10], "wrong string at %i (%c instead of %c)\n", i, outW[i], "abcdefghij"[i % 10]);
}
ok(outW[255] == '\0', "wrong end of string\n");
memset(outW, '.', sizeof(outW));
len = GetAtomNameW(atom, outW, 10);
todo_wine ok(len == 9, "succeeded %d\n", len);
for (i = 0; i < 9; i++)
{
ok(outW[i] == "abcdefghij"[i % 10], "wrong string at %i (%c instead of %c)\n", i, outW[i], "abcdefghij"[i % 10]);
}
ok(outW[9] == '\0', "wrong end of string\n");
ok(outW[10] == DOUBLE('.'), "buffer overwrite\n");
do_initW(inW, "abcdefghij", 256);
atom = AddAtomW(inW);
ok(!atom, "succeeded\n");
ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error code (%lu)\n", GetLastError());
}
}
@ -334,7 +564,6 @@ static void test_local_error_handling(void)
}
}
START_TEST(atom)
{
test_add_atom();