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** Check three cases of searching for a string within a string. First when
11** the string is contained, check that the pointer returned points to it.
12** Then when it isn't contained, ensure it returns null. And when the string
13** we're searching for is empty, it should return a pointer to the string
14** we're searching through.Test #1 for the strstr function
15**
16**
17**==========================================================================*/
18
19
20
21#include <palsuite.h>
22
23
24struct testCase
25{
26 char *result;
27 char *string1;
28 char *string2;
29
30};
31
32int __cdecl main(int argc, char *argv[])
33{
34 int i=0;
35 char *ptr=NULL;
36
37 struct testCase testCases[]=
38 {
39 {"is is a test", "This is a test","is"},
40 {"fghijkl","abcdefghijkl","fgh"},
41 {NULL,"aabbccddeeffgg","h"},
42 {NULL,"aabb", "eeeeeee"},
43 {"AAA", "BBddfdaaaaAAA","A"},
44 {"fdaaaaAAA", "BBddfdaaaaAAA","f"},
45 {"aadfsadfas","aadfsadfas",""},
46 {NULL,"","ccc"}
47 };
48
49 /*
50 * Initialize the PAL
51 */
52 if (0 != PAL_Initialize(argc, argv))
53 {
54 return FAIL;
55 }
56
57 for (i=0; i<sizeof(testCases)/sizeof(struct testCase); i++)
58 {
59 ptr = strstr(testCases[i].string1,testCases[i].string2);
60 if (ptr==NULL)
61 {
62 if (testCases[i].result != NULL)
63 {
64 Fail("ERROR: strstr returned incorrect value\n"
65 "Expected a pointer to \"%s\" , got a pointer to NULL\n",
66 testCases[i].result);
67 }
68 }
69 else
70 {
71 if (strcmp(testCases[i].result,ptr) != 0)
72 {
73 Fail("ERROR: strstr returned incorrect value\n"
74 "Expected a pointer to \"%s\" , got a pointer to \"%s\"\n",
75 testCases[i].result, ptr);
76 }
77 }
78 }
79
80 PAL_Terminate();
81 return PASS;
82}
83
84