Rewrote atom test in C.

This commit is contained in:
Alexandre Julliard 2002-07-31 17:45:00 +00:00
parent 530d50c827
commit 69b2201883
3 changed files with 216 additions and 175 deletions

View File

@ -41,6 +41,7 @@ EXTRASUBDIRS = \
CTESTS = \ CTESTS = \
tests/alloc.c \ tests/alloc.c \
tests/atom.c \
tests/directory.c \ tests/directory.c \
tests/file.c \ tests/file.c \
tests/locale.c \ tests/locale.c \
@ -48,9 +49,6 @@ CTESTS = \
tests/process.c \ tests/process.c \
tests/thread.c tests/thread.c
PLTESTS = \
tests/atom.pl
@MAKE_DLL_RULES@ @MAKE_DLL_RULES@
kernel.res: $(MC_SRCS:.mc=.mc.rc) kernel.res: $(MC_SRCS:.mc=.mc.rc)

215
dlls/kernel/tests/atom.c Normal file
View File

@ -0,0 +1,215 @@
/*
* Unit tests for atom functions
*
* Copyright (c) 2002 Alexandre Julliard
*
* 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
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdio.h>
#include "wine/test.h"
#include "winbase.h"
#include "winerror.h"
#include "wine/unicode.h"
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 test_add_atom(void)
{
ATOM atom, w_atom;
int i;
SetLastError( 0xdeadbeef );
atom = GlobalAddAtomA( "foobar" );
ok( (atom >= 0xc000) && (atom <= 0xffff), "bad atom id %x", atom );
ok( GetLastError() == 0xdeadbeef, "GlobalAddAtomA set last error" );
/* Verify that it can be found (or not) appropriately */
ok( GlobalFindAtomA( "foobar" ) == atom, "could not find atom foobar" );
ok( GlobalFindAtomA( "FOOBAR" ) == atom, "could not find atom FOOBAR" );
ok( !GlobalFindAtomA( "_foobar" ), "found _foobar" );
/* Add the same atom, specifying string as unicode; should
* find the first one, not add a new one */
SetLastError( 0xdeadbeef );
w_atom = GlobalAddAtomW( foobarW );
ok( w_atom == atom, "Unicode atom does not match ASCII" );
ok( GetLastError() == 0xdeadbeef, "GlobalAddAtomW set last error" );
/* Verify that it can be found (or not) appropriately via unicode name */
ok( GlobalFindAtomW( foobarW ) == atom, "could not find atom foobar" );
ok( GlobalFindAtomW( FOOBARW ) == atom, "could not find atom FOOBAR" );
ok( !GlobalFindAtomW( _foobarW ), "found _foobar" );
/* Test integer atoms
* (0x0000 .. 0xbfff) should be valid;
* (0xc000 .. 0xffff) should be invalid */
todo_wine
{
SetLastError( 0xdeadbeef );
ok( GlobalAddAtomA(0) == 0 && GetLastError() == 0xdeadbeef, "failed to add atom 0" );
SetLastError( 0xdeadbeef );
ok( GlobalAddAtomW(0) == 0 && GetLastError() == 0xdeadbeef, "failed to add atom 0" );
}
SetLastError( 0xdeadbeef );
for (i = 1; i <= 0xbfff; i++)
{
SetLastError( 0xdeadbeef );
ok( GlobalAddAtomA((LPCSTR)i) == i && GetLastError() == 0xdeadbeef,
"failed to add atom %x", i );
ok( GlobalAddAtomW((LPCWSTR)i) == i && GetLastError() == 0xdeadbeef,
"failed to add atom %x", i );
}
for (i = 0xc000; i <= 0xffff; i++)
{
SetLastError( 0xdeadbeef );
ok( !GlobalAddAtomA((LPCSTR)i) && (GetLastError() == ERROR_INVALID_PARAMETER),
"succeeded adding %x", i );
SetLastError( 0xdeadbeef );
ok( !GlobalAddAtomW((LPCWSTR)i) && (GetLastError() == ERROR_INVALID_PARAMETER),
"succeeded adding %x", i );
}
}
static void test_get_atom_name(void)
{
char buf[10];
WCHAR bufW[10];
int i, len;
static const char resultW[] = {'f','o','o','b','a','r',0,'.','.','.'};
ATOM atom = GlobalAddAtomA( "foobar" );
/* Get the name of the atom we added above */
memset( buf, '.', sizeof(buf) );
len = GlobalGetAtomNameA( atom, buf, 10 );
ok( len == strlen("foobar"), "bad length %d", len );
ok( !memcmp( buf, "foobar\0...", 10 ), "bad buffer contents" );
ok( !GlobalGetAtomNameA( atom, buf, 3 ), "GlobalGetAtomNameA succeeded on short buffer" );
/* Repeat, unicode-style */
for (i = 0; i < 10; i++) bufW[i] = '.';
len = GlobalGetAtomNameW( atom, bufW, 10 );
ok( len == strlenW(foobarW), "bad length %d", len );
todo_wine
{
ok( !memcmp( bufW, resultW, 10*sizeof(WCHAR) ), "bad buffer contents" );
}
ok( !GlobalGetAtomNameW( atom, bufW, 3 ), "GlobalGetAtomNameW succeeded on short buffer" );
/* Check error code returns */
SetLastError( 0xdeadbeef );
ok( !GlobalGetAtomNameA( atom, buf, 0 ) && GetLastError() == ERROR_MORE_DATA, "succeded" );
SetLastError( 0xdeadbeef );
ok( !GlobalGetAtomNameA( atom, buf, -1 ) && GetLastError() == ERROR_MORE_DATA, "succeded" );
SetLastError( 0xdeadbeef );
ok( !GlobalGetAtomNameW( atom, bufW, 0 ) && GetLastError() == ERROR_MORE_DATA, "succeded" );
SetLastError( 0xdeadbeef );
ok( !GlobalGetAtomNameW( atom, bufW, -1 ) && GetLastError() == ERROR_MORE_DATA, "succeded" );
/* Test integer atoms */
for (i = 0; i <= 0xbfff; i++)
{
memset( buf, 'a', 10 );
len = GlobalGetAtomNameA( i, buf, 10 );
if (i)
{
char res[20];
ok( (len > 1) && (len < 7), "bad length %d", len );
sprintf( res, "#%d", i );
memset( res + strlen(res) + 1, 'a', 10 );
ok( !memcmp( res, buf, 10 ), "bad buffer contents %s", buf );
}
else todo_wine
{
char res[20];
ok( (len > 1) && (len < 7), "bad length %d", len );
sprintf( res, "#%d", i );
memset( res + strlen(res) + 1, 'a', 10 );
ok( !memcmp( res, buf, 10 ), "bad buffer contents %s", buf );
}
}
}
static void test_delete_atom(void)
{
ATOM atom;
int i;
/* First make sure it doesn't exist */
atom = GlobalAddAtomA( "foobar" );
while (!GlobalDeleteAtom( atom ));
/* Now add it a number of times */
for (i = 0; i < 10; i++) atom = GlobalAddAtomA( "foobar" );
/* Make sure it's here */
ok( GlobalFindAtomA( "foobar" ), "foobar not found" );
ok( GlobalFindAtomW( foobarW ), "foobarW not found" );
/* That many deletions should succeed */
for (i = 0; i < 10; i++)
ok( !GlobalDeleteAtom( atom ), "delete atom failed" );
/* It should be gone now */
ok( !GlobalFindAtomA( "foobar" ), "still found it" );
ok( !GlobalFindAtomW( foobarW ), "still found it" );
/* So this one should fail */
SetLastError( 0xdeadbeef );
ok( GlobalDeleteAtom( atom ) == atom && GetLastError() == ERROR_INVALID_HANDLE,
"delete failed" );
}
static void test_error_handling(void)
{
char buffer[260];
WCHAR bufferW[260];
ATOM atom;
int i;
memset( buffer, 'a', 255 );
buffer[255] = 0;
ok( atom = GlobalAddAtomA( buffer ), "add failed" );
ok( !GlobalDeleteAtom( atom ), "delete failed" );
buffer[255] = 'a';
buffer[256] = 0;
SetLastError( 0xdeadbeef );
ok( !GlobalAddAtomA(buffer) && GetLastError() == ERROR_INVALID_PARAMETER, "add succeded" );
SetLastError( 0xdeadbeef );
ok( !GlobalFindAtomA(buffer) && GetLastError() == ERROR_INVALID_PARAMETER, "find succeded" );
for (i = 0; i < 255; i++) bufferW[i] = 'b';
bufferW[255] = 0;
ok( atom = GlobalAddAtomW( bufferW ), "add failed" );
ok( !GlobalDeleteAtom( atom ), "delete failed" );
bufferW[255] = 'b';
bufferW[256] = 0;
SetLastError( 0xdeadbeef );
ok( !GlobalAddAtomW(bufferW) && GetLastError() == ERROR_INVALID_PARAMETER, "add succeded" );
SetLastError( 0xdeadbeef );
ok( !GlobalFindAtomW(bufferW) && GetLastError() == ERROR_INVALID_PARAMETER, "find succeded" );
}
START_TEST(atom)
{
test_add_atom();
test_get_atom_name();
test_delete_atom();
test_error_handling();
}

View File

@ -1,172 +0,0 @@
################################################################
# Tests for atom API calls
#
# Copyright 2001 Alexandre Julliard
#
# 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
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
use wine;
use winerror;
use kernel32;
my $name = "foobar";
################################################################
# GlobalAddAtom/GlobalFindAtom
# Add an atom
my $atom = GlobalAddAtomA( $name );
ok( ($atom >= 0xc000) && ($atom <= 0xffff) && !defined($wine::err) );
# Verify that it can be found (or not) appropriately
ok( GlobalFindAtomA($name) == $atom );
ok( GlobalFindAtomA(uc $name) == $atom );
ok( !GlobalFindAtomA( "_" . $name ) );
# Add the same atom, specifying string as unicode; should
# find the first one, not add a new one
my $w_atom = GlobalAddAtomW( wc($name) );
ok( $w_atom == $atom && !defined($wine::err) );
# Verify that it can be found (or not) appropriately via
# unicode name
ok( GlobalFindAtomW( wc($name)) == $atom );
ok( GlobalFindAtomW( wc(uc($name)) ) == $atom );
ok( !GlobalFindAtomW( wc("_" . $name) ) );
# Test integer atoms
#
# (0x0000 .. 0xbfff) should be valid;
# (0xc000 .. 0xffff) should be invalid
# test limits
todo_wine
{
ok( GlobalAddAtomA(0) == 0 && !defined($wine::err) );
ok( GlobalAddAtomW(0) == 0 && !defined($wine::err) );
};
ok( GlobalAddAtomA(1) == 1 && !defined($wine::err) );
ok( GlobalAddAtomW(1) == 1 && !defined($wine::err) );
ok( GlobalAddAtomA(0xbfff) == 0xbfff && !defined($wine::err) );
ok( GlobalAddAtomW(0xbfff) == 0xbfff && !defined($wine::err) );
ok( !GlobalAddAtomA(0xc000) && ($wine::err == ERROR_INVALID_PARAMETER) );
ok( !GlobalAddAtomW(0xc000) && ($wine::err == ERROR_INVALID_PARAMETER) );
ok( !GlobalAddAtomA(0xffff) && ($wine::err == ERROR_INVALID_PARAMETER) );
ok( !GlobalAddAtomW(0xffff) && ($wine::err == ERROR_INVALID_PARAMETER) );
# test some in between
for ($i = 0x0001; ($i <= 0xbfff); $i += 27)
{
ok( GlobalAddAtomA($i) && !defined($wine::err) );
ok( GlobalAddAtomW($i) && !defined($wine::err) );
}
for ($i = 0xc000; ($i <= 0xffff); $i += 29)
{
ok( !GlobalAddAtomA($i) && ($wine::err == ERROR_INVALID_PARAMETER) );
ok( !GlobalAddAtomW($i) && ($wine::err == ERROR_INVALID_PARAMETER) );
}
################################################################
# GlobalGetAtomName
# Get the name of the atom we added above
my $buf = "." x 20;
my $len = GlobalGetAtomNameA( $atom, \$buf, length ($buf) );
ok( $len == length ($name) );
ok( $buf eq ($name . "\x00" . ("." x (length ($buf) - length ($name) - 1))) );
$buf = "." x 20;
ok( !GlobalGetAtomNameA( $atom, \$buf, 3 ) );
# Repeat, unicode-style
$buf = wc("." x 20);
$len = GlobalGetAtomNameW( $atom, \$buf, length ($buf) / 2 );
ok( $len == wclen (wc ($name)) );
todo_wine
{
ok( $buf eq (wc ($name) . "\x00\x00" . ("." x (20 - 2 * (wclen (wc ($name)) + 1) ))) );
};
$buf = wc("." x 20);
ok( !GlobalGetAtomNameW( $atom, \$buf, 3 ) );
# Check error code returns
ok( !GlobalGetAtomNameA( $atom, $buf, 0 ) && $wine::err == ERROR_MORE_DATA );
ok( !GlobalGetAtomNameA( $atom, $buf, -1 ) && $wine::err == ERROR_MORE_DATA );
ok( !GlobalGetAtomNameW( $atom, $buf, 0 ) && $wine::err == ERROR_MORE_DATA );
ok( !GlobalGetAtomNameW( $atom, $buf, -1 ) && $wine::err == ERROR_MORE_DATA );
# Test integer atoms
$buf = "a" x 10;
for ($i = 0; ($i <= 0xbfff); $i += 37)
{
$len = GlobalGetAtomNameA( $i, \$buf, length ($buf) );
if ($i)
{
ok( ($len > 1) && ($len < 7) );
ok( $buf eq ("#$i\x00" . "a" x (10 - $len - 1) ));
}
else
{
todo_wine
{
ok( ($len > 1) && ($len < 7) );
ok( $buf eq ("#$i\x00" . "a" x (10 - $len - 1) ));
};
}
}
################################################################
# GlobalDeleteAtom
$name = "barkbar";
$n = 5;
# First make sure it doesn't exist
$atom = GlobalAddAtomA( $name );
while (!GlobalDeleteAtom( $atom )) { }
# Now add it a number of times
for (1 .. $n) { $atom = GlobalAddAtomA( $name ); }
# Make sure it's here
ok( GlobalFindAtomA( $name ));
ok( GlobalFindAtomW( wc($name) ));
# That many deletions should succeed
for (1 .. $n) { ok( !GlobalDeleteAtom( $atom ) ); }
# It should be gone now
ok( !GlobalFindAtomA($name) );
ok( !GlobalFindAtomW( wc($name) ));
# So this one should fail
ok( GlobalDeleteAtom( $atom ) == $atom && $wine::err == ERROR_INVALID_HANDLE );
################################################################
# Test error handling
# ASCII
ok( ($atom = GlobalAddAtomA("a" x 255)) );
ok( !GlobalDeleteAtom($atom) );
ok( !GlobalAddAtomA( "a" x 256 ) && $wine::err == ERROR_INVALID_PARAMETER );
ok( !GlobalFindAtomA( "b" x 256 ) && $wine::err == ERROR_INVALID_PARAMETER );
# Unicode
ok( ($atom = GlobalAddAtomW( wc("a" x 255) )) );
ok( !GlobalDeleteAtom($atom) );
ok( !GlobalAddAtomW( wc("a" x 256) ) && $wine::err == ERROR_INVALID_PARAMETER );
ok( !GlobalFindAtomW( wc("b" x 256) ) && $wine::err == ERROR_INVALID_PARAMETER );