]> git.sur5r.net Git - cc65/blob - test/val/lib_common_strrchr.c
Changes due to code review.
[cc65] / test / val / lib_common_strrchr.c
1 #include <string.h>
2 #include "unittest.h"
3                                                     
4 static char TestString[] = "01234567890123456789";  // two times the same string
5 static char Found[256];
6
7 TEST
8 {
9     unsigned len;
10     unsigned i;
11     char*    p;
12
13     len = strlen(TestString)/2; // test only one half of the string, to find last appearance
14
15     /* Search for all characters in the string, including the terminator */
16     for (i = 0; i < len; ++i)
17     {
18         /* Search for this char */
19         p = strrchr (TestString, TestString[i]);
20         ASSERT_AreEqual(i+len, p-TestString, "%u", "Unexpected location of character '%c' found!" COMMA TestString[i]);
21
22         /* Mark the char as checked */
23         Found[TestString[i]] = 1;
24     }
25
26     /* Search for all other characters and make sure they aren't found */
27     for (i = 0; i < 256; ++i)
28     {
29         if (!Found[i])
30         {
31             p = strrchr (TestString, i);
32             ASSERT_IsFalse(p, "Unexpected location of character '%c' found!" COMMA TestString[i]);
33         }
34     }
35 }
36 ENDTEST
37
38