@@ -66,6 +66,15 @@ const char *context = "";
6666 } \
6767 } while (0)
6868
69+ #define TEST_XSTR (strcmp , type , x , expect , fmt ) do { \
70+ const type *str = (x); \
71+ tests++; \
72+ if (!str || strcmp(str, (expect))) { \
73+ fails++; \
74+ printf("%s:%d: %sexpected \"" fmt "\", got \"" fmt "\"\n", __FILE__, __LINE__, context, (expect), str); \
75+ } \
76+ } while (0)
77+
6978#define TEST_FLT (x , expect ) do { \
7079 tests++; \
7180 if ((x) != (expect)) { \
@@ -467,6 +476,36 @@ void test_strings() {
467476#endif
468477}
469478
479+ void test_tokenize () {
480+ #define TEST_STRTOK (strtok , type , prefix , strcmp , fmt ) do { \
481+ type buf[] = prefix ## " foo bar baz "; \
482+ TEST_XSTR(strcmp, type, strtok(buf, prefix ## " "), prefix ## "foo", fmt); \
483+ TEST_XSTR(strcmp, type, strtok(NULL, prefix ## " "), prefix ## "bar", fmt); \
484+ TEST_XSTR(strcmp, type, strtok(NULL, prefix ## " "), prefix ## "baz", fmt); \
485+ TEST(strtok(NULL, prefix ## " ") == NULL); \
486+ } while (0)
487+ #define TEST_STRTOK_R (strtok_r , type , prefix , strcmp , fmt ) do { \
488+ type buf[] = prefix ## " foo bar baz "; \
489+ type *ptr; \
490+ TEST_XSTR(strcmp, type, strtok_r(buf, prefix ## " ", &ptr), prefix ## "foo", fmt); \
491+ TEST_XSTR(strcmp, type, strtok_r(NULL, prefix ## " ", &ptr), prefix ## "bar", fmt); \
492+ TEST_XSTR(strcmp, type, strtok_r(NULL, prefix ## " ", &ptr), prefix ## "baz", fmt); \
493+ TEST(strtok_r(NULL, prefix ## " ", &ptr) == NULL); \
494+ } while (0)
495+ TEST_STRTOK (strtok , char , , strcmp , "%s" );
496+ #ifndef _MSC_VER
497+ TEST_STRTOK_R (strtok_r , char , , strcmp , "%s" );
498+ #endif
499+ TEST_STRTOK_R (wcstok , wchar_t , L , wcscmp , "%ls" );
500+ #ifdef _WIN32
501+ TEST_STRTOK (_wcstok , wchar_t , L , wcscmp , "%ls" );
502+ TEST_STRTOK_R (wcstok_s , wchar_t , L , wcscmp , "%ls" );
503+ #ifdef __cplusplus
504+ TEST_STRTOK (wcstok , wchar_t , L , wcscmp , "%ls" );
505+ #endif
506+ #endif
507+ }
508+
470509void test_parse_numbers () {
471510#ifdef _WIN32
472511 _set_invalid_parameter_handler (invalid_parameter );
@@ -2150,6 +2189,7 @@ void test_win32_intrinsics() {
21502189
21512190int main (int argc , char * argv []) {
21522191 test_strings ();
2192+ test_tokenize ();
21532193 test_parse_numbers ();
21542194 test_environment ();
21552195 test_math_rounding ();
0 commit comments