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 a string for characters in a given character set and ensure the |
11 | ** pointer returned points to the first occurance. Check to see that the |
12 | ** function returns NULL if the character is not found. |
13 | ** |
14 | ** |
15 | **==========================================================================*/ |
16 | |
17 | #include <palsuite.h> |
18 | |
19 | struct testCase |
20 | { |
21 | char *result; |
22 | char *string1; |
23 | char *string2; |
24 | }; |
25 | |
26 | int __cdecl main(int argc, char *argv[]) |
27 | { |
28 | char *ptr = NULL; |
29 | int i = 0; |
30 | |
31 | /* |
32 | * this structure includes several strings to be tested with |
33 | * strpbk function and the expected results |
34 | */ |
35 | |
36 | struct testCase testCases[] = |
37 | { |
38 | {"t cream coast" ,"corn cup cat cream coast" ,"sit" }, |
39 | {"eam coast" ,"corn cup cat cream coast" ,"like" }, |
40 | {"is is a test" ,"This is a test" ,"circle" }, |
41 | {"a test" ,"This is a test" ,"way" }, |
42 | {NULL,"This is a test" ,"boo" }, |
43 | {NULL,"This is a test" ,"123" }, |
44 | {" is a test of the function" ,"This is a test of the function" , |
45 | "zzz xx" } |
46 | }; |
47 | |
48 | |
49 | if (0 != PAL_Initialize(argc, argv)) |
50 | { |
51 | return FAIL; |
52 | } |
53 | |
54 | /* A loop to go through the testcases in the structure */ |
55 | |
56 | for (i=0; i< sizeof(testCases)/sizeof(struct testCase); i++) |
57 | { |
58 | ptr = strpbrk(testCases[i].string1,testCases[i].string2); |
59 | if (ptr==NULL) |
60 | { |
61 | if (testCases[i].result != NULL) |
62 | { |
63 | Fail("Expected strpbrk() to return %s, got NULL!\n" , |
64 | testCases[i].result); |
65 | } |
66 | } |
67 | else |
68 | { |
69 | if (strcmp(ptr,testCases[i].result)!=0 ) |
70 | |
71 | { |
72 | Fail("Expected strpbrk() to return %s, got %s!\n" , |
73 | testCases[i].result,ptr); |
74 | } |
75 | |
76 | } |
77 | |
78 | } |
79 | |
80 | |
81 | PAL_Terminate(); |
82 | |
83 | return PASS; |
84 | } |
85 | |
86 | |