]> git.sur5r.net Git - cc65/blob - testcode/lib/strchr-test.c
Adjusted C declarations to the changed static driver names.
[cc65] / testcode / lib / strchr-test.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5
6                                                         
7 /* Test string. Must NOT have duplicate characters! */
8 static char S[] = "Helo wrd!\n";
9
10 static char Found[256];
11
12
13
14 int main (void)
15 {
16     unsigned Len;
17     unsigned I;
18     char*    P;
19
20     /* Print a header */
21     printf ("strchr(): ");
22
23     /* Get the length of the string */
24     Len = strlen (S);
25
26     /* Search for all characters in the string, including the terminator */
27     for (I = 0; I < Len+1; ++I) {
28
29         /* Search for this char */
30         P = strchr (S, S[I]);
31
32         /* Check if we found it */
33         if (P == 0 || (P - S) != I) {
34             printf ("Failed for code 0x%02X, offset %u!\n", S[I], I);
35             printf ("P = %04X offset = %04X\n", P, P-S);
36             exit (EXIT_FAILURE);
37         }
38
39         /* Mark the char as checked */
40         Found[S[I]] = 1;
41     }
42
43     /* Search for all other characters and make sure they aren't found */
44     for (I = 0; I < 256; ++I) {
45         if (Found[I] == 0) {
46             if (strchr (S, (char)I) != 0) {
47                 printf ("Failed for code 0x%02X\n", I);
48                 exit (EXIT_FAILURE);
49             }
50         }
51     }
52
53     /* Test passed */
54     printf ("Passed\n");
55     return EXIT_SUCCESS;
56 }
57
58
59