Added some regression tests from patch #2321830
[fw/sdcc] / support / regression / tests / strtok.c
1 /** tests for strtok
2 */
3 #include <testfwk.h>
4 #include <string.h>
5
6 static void 
7 teststrtok(void)
8 {
9   static char str[] = "?a???b,,,#c";
10   const char str2[] = "axaaba";
11   char *token = strtok(str, "?"); // 'token' points to the token "a"
12   ASSERT( token == &str[1] && 0 == strcmp(token,"a"));
13   token = strtok(NULL, ","); // 'token' points to the token "??b"
14   ASSERT( token == &str[3]&& 0 == strcmp(token,"??b"));
15   token = strtok(NULL, "#,"); // 'token' points to the token "c"
16   ASSERT( token == &str[10] && 0 == strcmp(token,"c"));
17   token = strtok(NULL, "?"); // 'token' is a null pointer
18   ASSERT( token == NULL);
19   
20   token = strtok (str2, "ab");
21   ASSERT( token && 0 == strcmp (token, "x"));
22   token = strtok(NULL, "ab");
23   ASSERT( token == NULL);
24   token = strtok(NULL, "a");
25   ASSERT( token == NULL);
26
27 }