msvcrt/tests : add some tests for strtok()
Rein Klazes
wijn at online.nl
Thu Apr 16 04:28:17 CDT 2009
---
dlls/msvcrt/tests/string.c | 61 +++++++++++++++++++++++++++++++++++++++----
1 files changed, 55 insertions(+), 6 deletions(-)
diff --git a/dlls/msvcrt/tests/string.c b/dlls/msvcrt/tests/string.c
index 45c40d5..9f13301 100644
--- a/dlls/msvcrt/tests/string.c
+++ b/dlls/msvcrt/tests/string.c
@@ -619,6 +619,50 @@ static void test_mbcjisjms(void)
} while(jisjms[i++][0] != 0);
}
+struct {
+ const char* string;
+ const char* delimiter;
+ int exp_offsetret1; /* returned offset from string after first call to strtok()
+ -1 means NULL */
+ int exp_offsetret2; /* returned offset from string after second call to strtok()
+ -1 means NULL */
+ int exp_offsetret3; /* returned offset from string after third call to strtok()
+ -1 means NULL */
+} testcases_strtok[] = {
+ { "red cabernet", " ", 0, 4, -1 },
+ { "sparkling white riesling", " ", 0, 10, 16 },
+ { " pale cream sherry", "e ", 1, 6, 9 },
+ /* end mark */
+ { 0}
+};
+
+void test_strtok()
+{
+ int i;
+ char *strret;
+ char teststr[100];
+ for( i = 0; testcases_strtok[i].string; i++){
+ strcpy( teststr, testcases_strtok[i].string);
+ strret = strtok( teststr, testcases_strtok[i].delimiter);
+ ok( (int)(strret - teststr) == testcases_strtok[i].exp_offsetret1 ||
+ (!strret && testcases_strtok[i].exp_offsetret1 == -1),
+ "string (%p) \'%s\' return %p\n",
+ teststr, testcases_strtok[i].string, strret);
+ if( !strret) continue;
+ strret = strtok( NULL, testcases_strtok[i].delimiter);
+ ok( (int)(strret - teststr) == testcases_strtok[i].exp_offsetret2 ||
+ (!strret && testcases_strtok[i].exp_offsetret2 == -1),
+ "second call string (%p) \'%s\' return %p\n",
+ teststr, testcases_strtok[i].string, strret);
+ if( !strret) continue;
+ strret = strtok( NULL, testcases_strtok[i].delimiter);
+ ok( (int)(strret - teststr) == testcases_strtok[i].exp_offsetret3 ||
+ (!strret && testcases_strtok[i].exp_offsetret3 == -1),
+ "third call string (%p) \'%s\' return %p\n",
+ teststr, testcases_strtok[i].string, strret);
+ }
+}
+
START_TEST(string)
{
char mem[100];
@@ -637,20 +681,25 @@ START_TEST(string)
pstrcat_s = (void *)GetProcAddress( hMsvcrt,"strcat_s" );
p_mbsnbcpy_s = (void *)GetProcAddress( hMsvcrt,"_mbsnbcpy_s" );
p_wcscpy_s = (void *)GetProcAddress( hMsvcrt,"wcscpy_s" );
-
/* MSVCRT memcpy behaves like memmove for overlapping moves,
MFC42 CString::Insert seems to rely on that behaviour */
strcpy(mem,xilstring);
nLen=strlen(xilstring);
- pmemcpy(mem+5, mem,nLen+1);
- ok(pmemcmp(mem+5,xilstring, nLen) == 0,
- "Got result %s\n",mem+5);
+ if( pmemcpy) {
+ pmemcpy(mem+5, mem,nLen+1);
+ ok(pmemcmp(mem+5,xilstring, nLen) == 0,
+ "Got result %s\n",mem+5);
+ } else
+ skip("memcpy not found\n");
/* Test _swab function */
test_swab();
/* Test ismbblead*/
- test_mbcp();
+ if( p__mb_cur_max)
+ test_mbcp();
+ else
+ skip( "__mb_cur_max not found\n");
/* test _mbsspn */
test_mbsspn();
test_mbsspnp();
@@ -660,6 +709,6 @@ START_TEST(string)
test_strcat_s();
test__mbsnbcpy_s();
test_mbcjisjms();
-
+ test_strtok();
test_wcscpy_s();
}
--
1.6.2.1
More information about the wine-patches
mailing list