]> git.sur5r.net Git - cc65/blob - test/val/lib_common_strchr.c
goto.c warning fix for implicit truncation
[cc65] / test / val / lib_common_strchr.c
1 #include <string.h>
2 #include "unittest.h"
3
4                                                         
5 /* Test string. Must NOT have duplicate characters! */
6 static char S[] = "Helo wrd!\n";
7
8 static char Found[256];
9
10
11
12 TEST
13 {
14     unsigned Len;
15     unsigned I;
16     char*    P;
17
18     /* Get the length of the string */
19     Len = strlen (S);
20
21     /* Search for all characters in the string, including the terminator */
22     for (I = 0; I < Len+1; ++I)
23     {
24         /* Search for this char */
25         P = strchr (S, S[I]);
26
27         /* Check if we found it */
28         ASSERT_IsFalse(P == 0 || (P - S) != I, "For code 0x%02X, offset %u!\nP = %04X offset = %04X\n" COMMA S[I] COMMA I COMMA P COMMA P-S);
29         /* Mark the char as checked */
30         Found[S[I]] = 1;
31     }
32
33     /* Search for all other characters and make sure they aren't found */
34     for (I = 0; I < 256; ++I)
35     {
36         if (Found[I] == 0)
37         {
38             ASSERT_IsFalse(strchr (S, (char)I), "Failed for code 0x%02X\n" COMMA I);
39         }
40     }
41 }
42 ENDTEST