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** Tests that wcsstr correctly find substrings in wide stings, including
11** returning NULL when the substring can't be found.
12**
13**
14**==========================================================================*/
15
16#include <palsuite.h>
17
18int __cdecl main(int argc, char *argv[])
19{
20 WCHAR *string;
21 WCHAR *key1;
22 WCHAR *key2;
23 WCHAR key3[] = { 0 };
24 WCHAR *key4;
25 WCHAR *result;
26
27 if (PAL_Initialize(argc, argv))
28 {
29 return FAIL;
30 }
31
32 string = convert("foo bar baz bar");
33 key1 = convert("bar");
34 key2 = convert("Bar");
35 key4 = convert("arggggh!");
36
37 result = wcsstr(string, key1);
38 if (result != string + 4)
39 {
40 Fail("ERROR: Got incorrect result in scanning \"%s\" for \"%s\".\n"
41 "Expected to get pointer to %#p, got %#p\n", convertC(string),
42 convertC(key1), string + 4, result);
43 }
44
45
46 result = wcsstr(string, key2);
47 if (result != NULL)
48 {
49 Fail("ERROR: Got incorrect result in scanning \"%s\" for \"%s\".\n"
50 "Expected to get pointer to %#p, got %#p\n", convertC(string),
51 convertC(key2), NULL, result);
52 }
53
54 result = wcsstr(string, key3);
55 if (result != string)
56 {
57 Fail("ERROR: Got incorrect result in scanning \"%s\" for \"%s\".\n"
58 "Expected to get pointer to %#p, got %#p\n", convertC(string),
59 convertC(key3), string, result);
60 }
61
62 result = wcsstr(string, key4);
63 if (result != nullptr)
64 {
65 Fail("ERROR: Got incorrect result in scanning \"%s\" for \"%s\".\n"
66 "Expected to get pointer to null, got %#p\n", convertC(string),
67 convertC(key4), result);
68 }
69
70 PAL_Terminate();
71 return PASS;
72}
73