| 1 | // Licensed to the .NET Foundation under one or more agreements. |
| 2 | // The .NET Foundation licenses this file to you under the MIT license. |
| 3 | // See the LICENSE file in the project root for more information. |
| 4 | |
| 5 | /*============================================================================ |
| 6 | ** |
| 7 | ** Source: test1.c |
| 8 | ** |
| 9 | ** Purpose: |
| 10 | ** Search for a number of tokens within strings. Check that the return values |
| 11 | ** are what is expect, and also that the strings match up with our expected |
| 12 | ** results. |
| 13 | ** |
| 14 | ** |
| 15 | **==========================================================================*/ |
| 16 | |
| 17 | #include <palsuite.h> |
| 18 | |
| 19 | |
| 20 | int __cdecl main(int argc, char *argv[]) |
| 21 | { |
| 22 | char str[] = "foo bar baz" ; |
| 23 | char *result1= "foo \0ar baz" ; |
| 24 | char *result2= "foo \0a\0 baz" ; |
| 25 | int len = strlen(str) + 1; |
| 26 | char *ptr; |
| 27 | |
| 28 | |
| 29 | if (PAL_Initialize(argc, argv)) |
| 30 | { |
| 31 | return FAIL; |
| 32 | } |
| 33 | |
| 34 | |
| 35 | ptr = strtok(str, "bz" ); |
| 36 | if (ptr != str) |
| 37 | { |
| 38 | Fail("Expected strtok() to return %p, got %p!\n" , str, ptr); |
| 39 | } |
| 40 | if (memcmp(str, result1, len) != 0) |
| 41 | { |
| 42 | Fail("strtok altered the string in an unexpeced way!\n" ); |
| 43 | } |
| 44 | |
| 45 | ptr = strtok(NULL, "r " ); |
| 46 | if (ptr != str + 5) |
| 47 | { |
| 48 | Fail("Expected strtok() to return %p, got %p!\n" , str+5, ptr); |
| 49 | } |
| 50 | if (memcmp(str, result2, len) != 0) |
| 51 | { |
| 52 | Fail("strtok altered the string in an unexpeced way!\n" ); |
| 53 | } |
| 54 | |
| 55 | |
| 56 | ptr = strtok(NULL, "X" ); |
| 57 | if (ptr != str + 7) |
| 58 | { |
| 59 | Fail("Expected strtok() to return %p, got %p!\n" , str + 7, ptr); |
| 60 | } |
| 61 | if (memcmp(str, result2, len) != 0) |
| 62 | { |
| 63 | Fail("strtok altered the string in an unexpeced way!\n" ); |
| 64 | } |
| 65 | |
| 66 | ptr = strtok(NULL, "X" ); |
| 67 | if (ptr != NULL) |
| 68 | { |
| 69 | Fail("Expected strtok() to return %p, got %p!\n" , NULL, ptr); |
| 70 | } |
| 71 | if (memcmp(str, result2, len) != 0) |
| 72 | { |
| 73 | Fail("strtok altered the string in an unexpeced way!\n" ); |
| 74 | } |
| 75 | |
| 76 | PAL_Terminate(); |
| 77 | return PASS; |
| 78 | } |
| 79 | |