@@ -69,6 +69,15 @@ const char *context = "";
6969 } \
7070 } while (0)
7171
72+ #define TEST_XSTR (strcmp , type , x , expect , fmt ) do { \
73+ const type *str = (x); \
74+ tests++; \
75+ if (!str || strcmp(str, (expect))) { \
76+ fails++; \
77+ printf("%s:%d: %sexpected \"" fmt "\", got \"" fmt "\"\n", __FILE__, __LINE__, context, (expect), str); \
78+ } \
79+ } while (0)
80+
7281#define TEST_FLT (x , expect ) do { \
7382 tests++; \
7483 if ((x) != (expect)) { \
@@ -470,6 +479,36 @@ void test_strings() {
470479#endif
471480}
472481
482+ void test_tokenize () {
483+ #define TEST_STRTOK (strtok , type , prefix , strcmp , fmt ) do { \
484+ type buf[] = prefix ## " foo bar baz "; \
485+ TEST_XSTR(strcmp, type, strtok(buf, prefix ## " "), prefix ## "foo", fmt); \
486+ TEST_XSTR(strcmp, type, strtok(NULL, prefix ## " "), prefix ## "bar", fmt); \
487+ TEST_XSTR(strcmp, type, strtok(NULL, prefix ## " "), prefix ## "baz", fmt); \
488+ TEST(strtok(NULL, prefix ## " ") == NULL); \
489+ } while (0)
490+ #define TEST_STRTOK_R (strtok_r , type , prefix , strcmp , fmt ) do { \
491+ type buf[] = prefix ## " foo bar baz "; \
492+ type *ptr; \
493+ TEST_XSTR(strcmp, type, strtok_r(buf, prefix ## " ", &ptr), prefix ## "foo", fmt); \
494+ TEST_XSTR(strcmp, type, strtok_r(NULL, prefix ## " ", &ptr), prefix ## "bar", fmt); \
495+ TEST_XSTR(strcmp, type, strtok_r(NULL, prefix ## " ", &ptr), prefix ## "baz", fmt); \
496+ TEST(strtok_r(NULL, prefix ## " ", &ptr) == NULL); \
497+ } while (0)
498+ TEST_STRTOK (strtok , char , , strcmp , "%s" );
499+ #ifndef _MSC_VER
500+ TEST_STRTOK_R (strtok_r , char , , strcmp , "%s" );
501+ #endif
502+ TEST_STRTOK_R (wcstok , wchar_t , L , wcscmp , "%ls" );
503+ #ifdef _WIN32
504+ TEST_STRTOK (_wcstok , wchar_t , L , wcscmp , "%ls" );
505+ TEST_STRTOK_R (wcstok_s , wchar_t , L , wcscmp , "%ls" );
506+ #ifdef __cplusplus
507+ TEST_STRTOK (wcstok , wchar_t , L , wcscmp , "%ls" );
508+ #endif
509+ #endif
510+ }
511+
473512void test_parse_numbers () {
474513#ifdef _WIN32
475514 _set_invalid_parameter_handler (invalid_parameter );
@@ -2161,6 +2200,7 @@ void test_win32_intrinsics() {
21612200
21622201int main (int argc , char * argv []) {
21632202 test_strings ();
2203+ test_tokenize ();
21642204 test_parse_numbers ();
21652205 test_environment ();
21662206 test_math_rounding ();
0 commit comments