Pin down LoadStringA behaviour on different buffer lengths.

This commit is contained in:
Ferenc Wagner 2004-01-09 00:36:51 +00:00 committed by Alexandre Julliard
parent 2a2cd4db76
commit 88bc174873
4 changed files with 86 additions and 0 deletions

View File

@ -4,6 +4,8 @@ generated.ok
input.ok
listbox.ok
msg.ok
resource.ok
resource.res
sysparams.ok
testlist.c
user32_test.exe.spec.c

View File

@ -11,10 +11,13 @@ CTESTS = \
input.c \
listbox.c \
msg.c \
resource.c \
sysparams.c \
win.c \
wsprintf.c
RC_SRCS = resource.rc
@MAKE_TEST_RULES@
### Dependencies:

View File

@ -0,0 +1,59 @@
/* Unit test suite for resources.
*
* Copyright 2004 Ferenc Wagner
*
* 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 <assert.h>
#include <windows.h>
#include "wine/test.h"
void
test_LoadStringA (void)
{
HINSTANCE hInst = GetModuleHandle (NULL);
const char str[] = "String resource"; /* same in resource.rc */
char buf[128];
struct string_test {
int bufsiz;
int expected;
};
struct string_test tests[] = {{sizeof buf, sizeof str - 1},
{sizeof str, sizeof str - 1},
{sizeof str - 1, sizeof str - 2}};
int i;
assert (sizeof str < sizeof buf);
for (i = 0; i < sizeof tests / sizeof tests[0]; i++) {
const int bufsiz = tests[i].bufsiz;
const int expected = tests[i].expected;
const int len = LoadStringA (hInst, 0, buf, bufsiz);
ok (len == expected, "bufsiz=%d: got %d, expected %d",
bufsiz, len, expected);
ok (!memcmp (buf, str, len),
"bufsiz=%d: got '%s', expected '%.*s'",
bufsiz, buf, len, str);
ok (buf[len] == 0, "bufsiz=%d: NUL termination missing",
bufsiz);
}
}
START_TEST(resource)
{
test_LoadStringA ();
}

View File

@ -0,0 +1,22 @@
/* Unit test suite for resources.
*
* Copyright 2004 Ferenc Wagner
*
* 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
*/
STRINGTABLE {
0 "String resource"
}