]>
git.saurik.com Git - apple/libc.git/blob - tests/rpmatch.c
7 #include <darwintest.h>
9 static char *expectations
[] = {
10 "inclonclusive", /* -1 */
16 dumb_strescape(char * dst
, const char * in
, size_t len
) {
19 while (*in
&& count
+ 3 < len
) {
56 /* There are many more special cases */
59 count
+= (size_t)snprintf(dst
, len
- count
, "\\%03o", *in
);
73 rpmatch_testcase(const char * response
, int expectation
) {
74 const char * expect_msg
= expectations
[expectation
+1];
76 char escaped_response
[16];
77 dumb_strescape(escaped_response
, response
, sizeof(escaped_response
)/sizeof(char));
79 /* darwintest should escape special characters in message strings */
80 T_EXPECT_EQ(rpmatch(response
), expectation
, "'%s' is %s in the %s locale", escaped_response
, expect_msg
, setlocale(LC_ALL
, NULL
));
83 T_DECL(rpmatch
, "Ensure rpmatch responds to locales")
85 setlocale(LC_ALL
, "C");
87 /* Check several single character variants */
88 rpmatch_testcase("y", 1);
89 rpmatch_testcase("Y", 1);
90 rpmatch_testcase("j", -1); /* becomes afirmative in german */
91 rpmatch_testcase("J", -1);
92 rpmatch_testcase("x", -1);
93 rpmatch_testcase(" ", -1);
94 rpmatch_testcase("", -1);
95 rpmatch_testcase("n", 0);
96 rpmatch_testcase("N", 0);
98 /* A few full words */
99 rpmatch_testcase("yes", 1);
100 rpmatch_testcase("ja", -1);
101 rpmatch_testcase("no", 0);
103 /* Check each variant with a newline */
104 rpmatch_testcase("y\n", 1);
105 rpmatch_testcase("Y\n", 1);
106 rpmatch_testcase("j\n", -1);
107 rpmatch_testcase("J\n", -1);
108 rpmatch_testcase("x\n", -1);
109 rpmatch_testcase(" \n", -1);
110 rpmatch_testcase("\n", -1);
111 rpmatch_testcase("n\n", 0);
112 rpmatch_testcase("N\n", 0);
114 rpmatch_testcase("yes\n", 1);
115 rpmatch_testcase("ja\n", -1);
116 rpmatch_testcase("no\n", 0);
118 /* Do it all again in a german locale */
119 setlocale(LC_ALL
, "de_DE.ISO8859-1");
121 if (strcmp(setlocale(LC_ALL
, NULL
), "de_DE.ISO8859-1") != 0) {
122 T_LOG("This system does not have a de_DE.ISO8859-1 locale");
126 /* Check several single character variants */
127 rpmatch_testcase("y", 1);
128 rpmatch_testcase("Y", 1);
129 rpmatch_testcase("j", 1); /* now afirmative */
130 rpmatch_testcase("J", 1);
131 rpmatch_testcase("x", -1);
132 rpmatch_testcase(" ", -1);
133 rpmatch_testcase("", -1);
134 rpmatch_testcase("n", 0);
135 rpmatch_testcase("N", 0);
137 /* A few full words */
138 rpmatch_testcase("yes", 1);
139 rpmatch_testcase("ja", 1);
140 rpmatch_testcase("xx", -1);
141 rpmatch_testcase("no", 0);
143 /* Check each variant with a newline */
144 rpmatch_testcase("y\n", 1);
145 rpmatch_testcase("Y\n", 1);
146 rpmatch_testcase("j\n", 1);
147 rpmatch_testcase("J\n", 1);
148 rpmatch_testcase("x\n", -1);
149 rpmatch_testcase(" \n", -1);
150 rpmatch_testcase("\n", -1);
151 rpmatch_testcase("n\n", 0);
152 rpmatch_testcase("N\n", 0);
154 rpmatch_testcase("yes\n", 1);
155 rpmatch_testcase("ja\n", 1);
156 rpmatch_testcase("xx\n", -1);
157 rpmatch_testcase("no\n", 0);