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: Tests the PAL implementation of the isalnum function |
10 | ** Check that a number of characters return the correct |
11 | ** values for whether they are alpha/numeric or not. |
12 | ** |
13 | ** |
14 | **===================================================================*/ |
15 | |
16 | #include <palsuite.h> |
17 | |
18 | |
19 | struct testCase |
20 | { |
21 | int CorrectResult; |
22 | int character; |
23 | }; |
24 | |
25 | int __cdecl main(int argc, char **argv) |
26 | { |
27 | |
28 | int result; |
29 | int i; |
30 | |
31 | struct testCase testCases[] = |
32 | { |
33 | {1, 'a'}, |
34 | {1, 'z'}, |
35 | {1, 'B'}, |
36 | {1, '5'}, |
37 | {1, '0'}, |
38 | {0, '?'}, |
39 | {0, 230} |
40 | }; |
41 | |
42 | if (PAL_Initialize(argc, argv)) |
43 | { |
44 | return FAIL; |
45 | } |
46 | |
47 | |
48 | /* Loop through each case. Check to see if each is alpha/numeric or |
49 | not. |
50 | */ |
51 | |
52 | for(i = 0; i < sizeof(testCases) / sizeof(struct testCase); i++) |
53 | { |
54 | |
55 | result = isalnum(testCases[i].character); |
56 | |
57 | /* The return value is 'non-zero' for success. This if condition |
58 | * will still work if that non-zero isn't just 1 |
59 | */ |
60 | if ( ((testCases[i].CorrectResult == 1) && (result == 0)) || |
61 | ( (testCases[i].CorrectResult == 0) && (result != 0) )) |
62 | { |
63 | Fail("ERROR: isalnum returned %i instead of %i for character " |
64 | " %c.\n" , |
65 | result, |
66 | testCases[i].CorrectResult, |
67 | testCases[i].character); |
68 | } |
69 | |
70 | } |
71 | |
72 | |
73 | PAL_Terminate(); |
74 | return PASS; |
75 | } |
76 | |
77 | |
78 | |
79 | |
80 | |
81 | |
82 | |
83 | |
84 | |
85 | |
86 | |
87 | |
88 | |
89 | |