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** Test this on a character which is in a string, and ensure the pointer
11** points to that character. Then check the string for the null character,
12** which the return pointer should point to. Then search for a character not
13** in the string and check that the return value is NULL.
14**
15**
16**==========================================================================*/
17
18#include <palsuite.h>
19
20struct testCase
21{
22 int result;
23 char string[50];
24 int character;
25};
26
27
28
29int __cdecl main(int argc, char *argv[])
30{
31 int i = 0;
32 char *result;
33
34 /*
35 * this structure includes several strings to be tested with
36 * strchr function and the expected results
37 */
38
39 struct testCase testCases[]=
40 {
41 {22,"corn cup cat cream coast",'s'},
42 {10,"corn cup cat cream coast",'a'},
43 {2,"This is a test",'i'},
44 {10,"This is a test",'t'},
45 {'\0',"This is a test",'b'},/* zero used instead of NULL */
46 {'\0',"This is a test",121},/* zero used instead of NULL */
47 {4,"This is a test of the function",' '},
48 {25,"This is a test of the function",'c'},
49 {'\0',"This is a test of the function",'C'},
50 {24,"corn cup cat cream coast", '\0'}/* zero used instead of NULL */
51 };
52
53 if (0 != PAL_Initialize(argc, argv))
54 {
55 return FAIL;
56 }
57
58
59 /* Loop through the structure and test each case */
60
61 for (i=0; i< sizeof(testCases)/sizeof(struct testCase); i++)
62 {
63 result = strchr(testCases[i].string,testCases[i].character);
64 if (result==NULL)
65 {
66 if (testCases[i].result != (int) NULL)
67 {
68 Fail("Expected strchr() to return \"%s\" instead of NULL!\n",
69 testCases[i].string + testCases[i].result);
70 }
71 }
72 else
73 {
74 if (result != testCases[i].string + testCases[i].result)
75 {
76 Fail("Expected strchr() to return \"%s\" instead of \"%s\"!\n",
77 testCases[i].string + testCases[i].result, result);
78 }
79 }
80
81 }
82
83 PAL_Terminate();
84
85 return PASS;
86}
87