xref: /minix3/external/bsd/atf/dist/atf-c/detail/text_test.c (revision 11be35a165022172ed3cea20f2b5df0307540b0e)
1*11be35a1SLionel Sambuc /*
2*11be35a1SLionel Sambuc  * Automated Testing Framework (atf)
3*11be35a1SLionel Sambuc  *
4*11be35a1SLionel Sambuc  * Copyright (c) 2008 The NetBSD Foundation, Inc.
5*11be35a1SLionel Sambuc  * All rights reserved.
6*11be35a1SLionel Sambuc  *
7*11be35a1SLionel Sambuc  * Redistribution and use in source and binary forms, with or without
8*11be35a1SLionel Sambuc  * modification, are permitted provided that the following conditions
9*11be35a1SLionel Sambuc  * are met:
10*11be35a1SLionel Sambuc  * 1. Redistributions of source code must retain the above copyright
11*11be35a1SLionel Sambuc  *    notice, this list of conditions and the following disclaimer.
12*11be35a1SLionel Sambuc  * 2. Redistributions in binary form must reproduce the above copyright
13*11be35a1SLionel Sambuc  *    notice, this list of conditions and the following disclaimer in the
14*11be35a1SLionel Sambuc  *    documentation and/or other materials provided with the distribution.
15*11be35a1SLionel Sambuc  *
16*11be35a1SLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17*11be35a1SLionel Sambuc  * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18*11be35a1SLionel Sambuc  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19*11be35a1SLionel Sambuc  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20*11be35a1SLionel Sambuc  * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21*11be35a1SLionel Sambuc  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22*11be35a1SLionel Sambuc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23*11be35a1SLionel Sambuc  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24*11be35a1SLionel Sambuc  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25*11be35a1SLionel Sambuc  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26*11be35a1SLionel Sambuc  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27*11be35a1SLionel Sambuc  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*11be35a1SLionel Sambuc  */
29*11be35a1SLionel Sambuc 
30*11be35a1SLionel Sambuc #include <stdio.h>
31*11be35a1SLionel Sambuc #include <stdlib.h>
32*11be35a1SLionel Sambuc #include <string.h>
33*11be35a1SLionel Sambuc 
34*11be35a1SLionel Sambuc #include <atf-c.h>
35*11be35a1SLionel Sambuc 
36*11be35a1SLionel Sambuc #include "sanity.h"
37*11be35a1SLionel Sambuc #include "test_helpers.h"
38*11be35a1SLionel Sambuc #include "text.h"
39*11be35a1SLionel Sambuc 
40*11be35a1SLionel Sambuc /* ---------------------------------------------------------------------
41*11be35a1SLionel Sambuc  * Auxiliary functions.
42*11be35a1SLionel Sambuc  * --------------------------------------------------------------------- */
43*11be35a1SLionel Sambuc 
44*11be35a1SLionel Sambuc #define REQUIRE_ERROR(exp) \
45*11be35a1SLionel Sambuc     do { \
46*11be35a1SLionel Sambuc         atf_error_t err = exp; \
47*11be35a1SLionel Sambuc         ATF_REQUIRE(atf_is_error(err)); \
48*11be35a1SLionel Sambuc         atf_error_free(err); \
49*11be35a1SLionel Sambuc     } while (0)
50*11be35a1SLionel Sambuc 
51*11be35a1SLionel Sambuc static
52*11be35a1SLionel Sambuc size_t
array_size(const char * words[])53*11be35a1SLionel Sambuc array_size(const char *words[])
54*11be35a1SLionel Sambuc {
55*11be35a1SLionel Sambuc     size_t count;
56*11be35a1SLionel Sambuc     const char **word;
57*11be35a1SLionel Sambuc 
58*11be35a1SLionel Sambuc     count = 0;
59*11be35a1SLionel Sambuc     for (word = words; *word != NULL; word++)
60*11be35a1SLionel Sambuc         count++;
61*11be35a1SLionel Sambuc 
62*11be35a1SLionel Sambuc     return count;
63*11be35a1SLionel Sambuc }
64*11be35a1SLionel Sambuc 
65*11be35a1SLionel Sambuc static
66*11be35a1SLionel Sambuc void
check_split(const char * str,const char * delim,const char * words[])67*11be35a1SLionel Sambuc check_split(const char *str, const char *delim, const char *words[])
68*11be35a1SLionel Sambuc {
69*11be35a1SLionel Sambuc     atf_list_t list;
70*11be35a1SLionel Sambuc     const char **word;
71*11be35a1SLionel Sambuc     size_t i;
72*11be35a1SLionel Sambuc 
73*11be35a1SLionel Sambuc     printf("Splitting '%s' with delimiter '%s'\n", str, delim);
74*11be35a1SLionel Sambuc     CE(atf_text_split(str, delim, &list));
75*11be35a1SLionel Sambuc 
76*11be35a1SLionel Sambuc     printf("Expecting %zd words\n", array_size(words));
77*11be35a1SLionel Sambuc     ATF_CHECK_EQ(atf_list_size(&list), array_size(words));
78*11be35a1SLionel Sambuc 
79*11be35a1SLionel Sambuc     for (word = words, i = 0; *word != NULL; word++, i++) {
80*11be35a1SLionel Sambuc         printf("Word at position %zd should be '%s'\n", i, words[i]);
81*11be35a1SLionel Sambuc         ATF_CHECK_STREQ((const char *)atf_list_index_c(&list, i), words[i]);
82*11be35a1SLionel Sambuc     }
83*11be35a1SLionel Sambuc 
84*11be35a1SLionel Sambuc     atf_list_fini(&list);
85*11be35a1SLionel Sambuc }
86*11be35a1SLionel Sambuc 
87*11be35a1SLionel Sambuc static
88*11be35a1SLionel Sambuc atf_error_t
word_acum(const char * word,void * data)89*11be35a1SLionel Sambuc word_acum(const char *word, void *data)
90*11be35a1SLionel Sambuc {
91*11be35a1SLionel Sambuc     char *acum = data;
92*11be35a1SLionel Sambuc 
93*11be35a1SLionel Sambuc     strcat(acum, word);
94*11be35a1SLionel Sambuc 
95*11be35a1SLionel Sambuc     return atf_no_error();
96*11be35a1SLionel Sambuc }
97*11be35a1SLionel Sambuc 
98*11be35a1SLionel Sambuc static
99*11be35a1SLionel Sambuc atf_error_t
word_count(const char * word ATF_DEFS_ATTRIBUTE_UNUSED,void * data)100*11be35a1SLionel Sambuc word_count(const char *word ATF_DEFS_ATTRIBUTE_UNUSED, void *data)
101*11be35a1SLionel Sambuc {
102*11be35a1SLionel Sambuc     size_t *counter = data;
103*11be35a1SLionel Sambuc 
104*11be35a1SLionel Sambuc     (*counter)++;
105*11be35a1SLionel Sambuc 
106*11be35a1SLionel Sambuc     return atf_no_error();
107*11be35a1SLionel Sambuc }
108*11be35a1SLionel Sambuc 
109*11be35a1SLionel Sambuc struct fail_at {
110*11be35a1SLionel Sambuc     int failpos;
111*11be35a1SLionel Sambuc     int curpos;
112*11be35a1SLionel Sambuc };
113*11be35a1SLionel Sambuc 
114*11be35a1SLionel Sambuc static
115*11be35a1SLionel Sambuc atf_error_t
word_fail_at(const char * word ATF_DEFS_ATTRIBUTE_UNUSED,void * data)116*11be35a1SLionel Sambuc word_fail_at(const char *word ATF_DEFS_ATTRIBUTE_UNUSED, void *data)
117*11be35a1SLionel Sambuc {
118*11be35a1SLionel Sambuc     struct fail_at *fa = data;
119*11be35a1SLionel Sambuc     atf_error_t err;
120*11be35a1SLionel Sambuc 
121*11be35a1SLionel Sambuc     if (fa->failpos == fa->curpos)
122*11be35a1SLionel Sambuc         err = atf_no_memory_error(); /* Just a random error. */
123*11be35a1SLionel Sambuc     else {
124*11be35a1SLionel Sambuc         fa->curpos++;
125*11be35a1SLionel Sambuc         err = atf_no_error();
126*11be35a1SLionel Sambuc     }
127*11be35a1SLionel Sambuc 
128*11be35a1SLionel Sambuc     return err;
129*11be35a1SLionel Sambuc }
130*11be35a1SLionel Sambuc 
131*11be35a1SLionel Sambuc /* ---------------------------------------------------------------------
132*11be35a1SLionel Sambuc  * Test cases for the free functions.
133*11be35a1SLionel Sambuc  * --------------------------------------------------------------------- */
134*11be35a1SLionel Sambuc 
135*11be35a1SLionel Sambuc ATF_TC(for_each_word);
ATF_TC_HEAD(for_each_word,tc)136*11be35a1SLionel Sambuc ATF_TC_HEAD(for_each_word, tc)
137*11be35a1SLionel Sambuc {
138*11be35a1SLionel Sambuc     atf_tc_set_md_var(tc, "descr", "Checks the atf_text_for_each_word"
139*11be35a1SLionel Sambuc                       "function");
140*11be35a1SLionel Sambuc }
ATF_TC_BODY(for_each_word,tc)141*11be35a1SLionel Sambuc ATF_TC_BODY(for_each_word, tc)
142*11be35a1SLionel Sambuc {
143*11be35a1SLionel Sambuc     size_t cnt;
144*11be35a1SLionel Sambuc     char acum[1024];
145*11be35a1SLionel Sambuc 
146*11be35a1SLionel Sambuc     cnt = 0;
147*11be35a1SLionel Sambuc     strcpy(acum, "");
148*11be35a1SLionel Sambuc     RE(atf_text_for_each_word("1 2 3", " ", word_count, &cnt));
149*11be35a1SLionel Sambuc     RE(atf_text_for_each_word("1 2 3", " ", word_acum, acum));
150*11be35a1SLionel Sambuc     ATF_REQUIRE(cnt == 3);
151*11be35a1SLionel Sambuc     ATF_REQUIRE(strcmp(acum, "123") == 0);
152*11be35a1SLionel Sambuc 
153*11be35a1SLionel Sambuc     cnt = 0;
154*11be35a1SLionel Sambuc     strcpy(acum, "");
155*11be35a1SLionel Sambuc     RE(atf_text_for_each_word("1 2 3", ".", word_count, &cnt));
156*11be35a1SLionel Sambuc     RE(atf_text_for_each_word("1 2 3", ".", word_acum, acum));
157*11be35a1SLionel Sambuc     ATF_REQUIRE(cnt == 1);
158*11be35a1SLionel Sambuc     ATF_REQUIRE(strcmp(acum, "1 2 3") == 0);
159*11be35a1SLionel Sambuc 
160*11be35a1SLionel Sambuc     cnt = 0;
161*11be35a1SLionel Sambuc     strcpy(acum, "");
162*11be35a1SLionel Sambuc     RE(atf_text_for_each_word("1 2 3 4 5", " ", word_count, &cnt));
163*11be35a1SLionel Sambuc     RE(atf_text_for_each_word("1 2 3 4 5", " ", word_acum, acum));
164*11be35a1SLionel Sambuc     ATF_REQUIRE(cnt == 5);
165*11be35a1SLionel Sambuc     ATF_REQUIRE(strcmp(acum, "12345") == 0);
166*11be35a1SLionel Sambuc 
167*11be35a1SLionel Sambuc     cnt = 0;
168*11be35a1SLionel Sambuc     strcpy(acum, "");
169*11be35a1SLionel Sambuc     RE(atf_text_for_each_word("1 2.3.4 5", " .", word_count, &cnt));
170*11be35a1SLionel Sambuc     RE(atf_text_for_each_word("1 2.3.4 5", " .", word_acum, acum));
171*11be35a1SLionel Sambuc     ATF_REQUIRE(cnt == 5);
172*11be35a1SLionel Sambuc     ATF_REQUIRE(strcmp(acum, "12345") == 0);
173*11be35a1SLionel Sambuc 
174*11be35a1SLionel Sambuc     {
175*11be35a1SLionel Sambuc         struct fail_at fa;
176*11be35a1SLionel Sambuc         fa.failpos = 3;
177*11be35a1SLionel Sambuc         fa.curpos = 0;
178*11be35a1SLionel Sambuc         atf_error_t err = atf_text_for_each_word("a b c d e", " ",
179*11be35a1SLionel Sambuc                                                  word_fail_at, &fa);
180*11be35a1SLionel Sambuc         ATF_REQUIRE(atf_is_error(err));
181*11be35a1SLionel Sambuc         ATF_REQUIRE(atf_error_is(err, "no_memory"));
182*11be35a1SLionel Sambuc         ATF_REQUIRE(fa.curpos == 3);
183*11be35a1SLionel Sambuc         atf_error_free(err);
184*11be35a1SLionel Sambuc     }
185*11be35a1SLionel Sambuc }
186*11be35a1SLionel Sambuc 
187*11be35a1SLionel Sambuc ATF_TC(format);
ATF_TC_HEAD(format,tc)188*11be35a1SLionel Sambuc ATF_TC_HEAD(format, tc)
189*11be35a1SLionel Sambuc {
190*11be35a1SLionel Sambuc     atf_tc_set_md_var(tc, "descr", "Checks the construction of free-form "
191*11be35a1SLionel Sambuc                       "strings using a variable parameters list");
192*11be35a1SLionel Sambuc }
ATF_TC_BODY(format,tc)193*11be35a1SLionel Sambuc ATF_TC_BODY(format, tc)
194*11be35a1SLionel Sambuc {
195*11be35a1SLionel Sambuc     char *str;
196*11be35a1SLionel Sambuc     atf_error_t err;
197*11be35a1SLionel Sambuc 
198*11be35a1SLionel Sambuc     err = atf_text_format(&str, "%s %s %d", "Test", "string", 1);
199*11be35a1SLionel Sambuc     ATF_REQUIRE(!atf_is_error(err));
200*11be35a1SLionel Sambuc     ATF_REQUIRE(strcmp(str, "Test string 1") == 0);
201*11be35a1SLionel Sambuc     free(str);
202*11be35a1SLionel Sambuc }
203*11be35a1SLionel Sambuc 
204*11be35a1SLionel Sambuc static
205*11be35a1SLionel Sambuc void
format_ap(char ** dest,const char * fmt,...)206*11be35a1SLionel Sambuc format_ap(char **dest, const char *fmt, ...)
207*11be35a1SLionel Sambuc {
208*11be35a1SLionel Sambuc     va_list ap;
209*11be35a1SLionel Sambuc     atf_error_t err;
210*11be35a1SLionel Sambuc 
211*11be35a1SLionel Sambuc     va_start(ap, fmt);
212*11be35a1SLionel Sambuc     err = atf_text_format_ap(dest, fmt, ap);
213*11be35a1SLionel Sambuc     va_end(ap);
214*11be35a1SLionel Sambuc 
215*11be35a1SLionel Sambuc     ATF_REQUIRE(!atf_is_error(err));
216*11be35a1SLionel Sambuc }
217*11be35a1SLionel Sambuc 
218*11be35a1SLionel Sambuc ATF_TC(format_ap);
ATF_TC_HEAD(format_ap,tc)219*11be35a1SLionel Sambuc ATF_TC_HEAD(format_ap, tc)
220*11be35a1SLionel Sambuc {
221*11be35a1SLionel Sambuc     atf_tc_set_md_var(tc, "descr", "Checks the construction of free-form "
222*11be35a1SLionel Sambuc                       "strings using a va_list argument");
223*11be35a1SLionel Sambuc }
ATF_TC_BODY(format_ap,tc)224*11be35a1SLionel Sambuc ATF_TC_BODY(format_ap, tc)
225*11be35a1SLionel Sambuc {
226*11be35a1SLionel Sambuc     char *str;
227*11be35a1SLionel Sambuc 
228*11be35a1SLionel Sambuc     format_ap(&str, "%s %s %d", "Test", "string", 1);
229*11be35a1SLionel Sambuc     ATF_REQUIRE(strcmp(str, "Test string 1") == 0);
230*11be35a1SLionel Sambuc     free(str);
231*11be35a1SLionel Sambuc }
232*11be35a1SLionel Sambuc 
233*11be35a1SLionel Sambuc ATF_TC(split);
ATF_TC_HEAD(split,tc)234*11be35a1SLionel Sambuc ATF_TC_HEAD(split, tc)
235*11be35a1SLionel Sambuc {
236*11be35a1SLionel Sambuc     atf_tc_set_md_var(tc, "descr", "Checks the split function");
237*11be35a1SLionel Sambuc }
ATF_TC_BODY(split,tc)238*11be35a1SLionel Sambuc ATF_TC_BODY(split, tc)
239*11be35a1SLionel Sambuc {
240*11be35a1SLionel Sambuc     {
241*11be35a1SLionel Sambuc         const char *words[] = { NULL };
242*11be35a1SLionel Sambuc         check_split("", " ", words);
243*11be35a1SLionel Sambuc     }
244*11be35a1SLionel Sambuc 
245*11be35a1SLionel Sambuc     {
246*11be35a1SLionel Sambuc         const char *words[] = { NULL };
247*11be35a1SLionel Sambuc         check_split(" ", " ", words);
248*11be35a1SLionel Sambuc     }
249*11be35a1SLionel Sambuc 
250*11be35a1SLionel Sambuc     {
251*11be35a1SLionel Sambuc         const char *words[] = { NULL };
252*11be35a1SLionel Sambuc         check_split("    ", " ", words);
253*11be35a1SLionel Sambuc     }
254*11be35a1SLionel Sambuc 
255*11be35a1SLionel Sambuc     {
256*11be35a1SLionel Sambuc         const char *words[] = { "a", "b", NULL };
257*11be35a1SLionel Sambuc         check_split("a b", " ", words);
258*11be35a1SLionel Sambuc     }
259*11be35a1SLionel Sambuc 
260*11be35a1SLionel Sambuc     {
261*11be35a1SLionel Sambuc         const char *words[] = { "a", "b", "c", "d", NULL };
262*11be35a1SLionel Sambuc         check_split("a b c d", " ", words);
263*11be35a1SLionel Sambuc     }
264*11be35a1SLionel Sambuc 
265*11be35a1SLionel Sambuc     {
266*11be35a1SLionel Sambuc         const char *words[] = { "foo", "bar", NULL };
267*11be35a1SLionel Sambuc         check_split("foo bar", " ", words);
268*11be35a1SLionel Sambuc     }
269*11be35a1SLionel Sambuc 
270*11be35a1SLionel Sambuc     {
271*11be35a1SLionel Sambuc         const char *words[] = { "foo", "bar", "baz", "foobar", NULL };
272*11be35a1SLionel Sambuc         check_split("foo bar baz foobar", " ", words);
273*11be35a1SLionel Sambuc     }
274*11be35a1SLionel Sambuc 
275*11be35a1SLionel Sambuc     {
276*11be35a1SLionel Sambuc         const char *words[] = { "foo", "bar", NULL };
277*11be35a1SLionel Sambuc         check_split(" foo bar", " ", words);
278*11be35a1SLionel Sambuc     }
279*11be35a1SLionel Sambuc 
280*11be35a1SLionel Sambuc     {
281*11be35a1SLionel Sambuc         const char *words[] = { "foo", "bar", NULL };
282*11be35a1SLionel Sambuc         check_split("foo  bar", " ", words);
283*11be35a1SLionel Sambuc     }
284*11be35a1SLionel Sambuc 
285*11be35a1SLionel Sambuc     {
286*11be35a1SLionel Sambuc         const char *words[] = { "foo", "bar", NULL };
287*11be35a1SLionel Sambuc         check_split("foo bar ", " ", words);
288*11be35a1SLionel Sambuc     }
289*11be35a1SLionel Sambuc 
290*11be35a1SLionel Sambuc     {
291*11be35a1SLionel Sambuc         const char *words[] = { "foo", "bar", NULL };
292*11be35a1SLionel Sambuc         check_split("  foo  bar  ", " ", words);
293*11be35a1SLionel Sambuc     }
294*11be35a1SLionel Sambuc }
295*11be35a1SLionel Sambuc 
296*11be35a1SLionel Sambuc ATF_TC(split_delims);
ATF_TC_HEAD(split_delims,tc)297*11be35a1SLionel Sambuc ATF_TC_HEAD(split_delims, tc)
298*11be35a1SLionel Sambuc {
299*11be35a1SLionel Sambuc     atf_tc_set_md_var(tc, "descr", "Checks the split function using "
300*11be35a1SLionel Sambuc                       "different delimiters");
301*11be35a1SLionel Sambuc }
ATF_TC_BODY(split_delims,tc)302*11be35a1SLionel Sambuc ATF_TC_BODY(split_delims, tc)
303*11be35a1SLionel Sambuc {
304*11be35a1SLionel Sambuc 
305*11be35a1SLionel Sambuc     {
306*11be35a1SLionel Sambuc         const char *words[] = { NULL };
307*11be35a1SLionel Sambuc         check_split("", "/", words);
308*11be35a1SLionel Sambuc     }
309*11be35a1SLionel Sambuc 
310*11be35a1SLionel Sambuc     {
311*11be35a1SLionel Sambuc         const char *words[] = { " ", NULL };
312*11be35a1SLionel Sambuc         check_split(" ", "/", words);
313*11be35a1SLionel Sambuc     }
314*11be35a1SLionel Sambuc 
315*11be35a1SLionel Sambuc     {
316*11be35a1SLionel Sambuc         const char *words[] = { "    ", NULL };
317*11be35a1SLionel Sambuc         check_split("    ", "/", words);
318*11be35a1SLionel Sambuc     }
319*11be35a1SLionel Sambuc 
320*11be35a1SLionel Sambuc     {
321*11be35a1SLionel Sambuc         const char *words[] = { "a", "b", NULL };
322*11be35a1SLionel Sambuc         check_split("a/b", "/", words);
323*11be35a1SLionel Sambuc     }
324*11be35a1SLionel Sambuc 
325*11be35a1SLionel Sambuc     {
326*11be35a1SLionel Sambuc         const char *words[] = { "a", "bcd", "ef", NULL };
327*11be35a1SLionel Sambuc         check_split("aLONGDELIMbcdLONGDELIMef", "LONGDELIM", words);
328*11be35a1SLionel Sambuc     }
329*11be35a1SLionel Sambuc }
330*11be35a1SLionel Sambuc 
331*11be35a1SLionel Sambuc ATF_TC(to_bool);
ATF_TC_HEAD(to_bool,tc)332*11be35a1SLionel Sambuc ATF_TC_HEAD(to_bool, tc)
333*11be35a1SLionel Sambuc {
334*11be35a1SLionel Sambuc     atf_tc_set_md_var(tc, "descr", "Checks the atf_text_to_bool function");
335*11be35a1SLionel Sambuc }
ATF_TC_BODY(to_bool,tc)336*11be35a1SLionel Sambuc ATF_TC_BODY(to_bool, tc)
337*11be35a1SLionel Sambuc {
338*11be35a1SLionel Sambuc     bool b;
339*11be35a1SLionel Sambuc 
340*11be35a1SLionel Sambuc     RE(atf_text_to_bool("true", &b)); ATF_REQUIRE(b);
341*11be35a1SLionel Sambuc     RE(atf_text_to_bool("TRUE", &b)); ATF_REQUIRE(b);
342*11be35a1SLionel Sambuc     RE(atf_text_to_bool("yes", &b)); ATF_REQUIRE(b);
343*11be35a1SLionel Sambuc     RE(atf_text_to_bool("YES", &b)); ATF_REQUIRE(b);
344*11be35a1SLionel Sambuc 
345*11be35a1SLionel Sambuc     RE(atf_text_to_bool("false", &b)); ATF_REQUIRE(!b);
346*11be35a1SLionel Sambuc     RE(atf_text_to_bool("FALSE", &b)); ATF_REQUIRE(!b);
347*11be35a1SLionel Sambuc     RE(atf_text_to_bool("no", &b)); ATF_REQUIRE(!b);
348*11be35a1SLionel Sambuc     RE(atf_text_to_bool("NO", &b)); ATF_REQUIRE(!b);
349*11be35a1SLionel Sambuc 
350*11be35a1SLionel Sambuc     b = false;
351*11be35a1SLionel Sambuc     REQUIRE_ERROR(atf_text_to_bool("", &b));
352*11be35a1SLionel Sambuc     ATF_REQUIRE(!b);
353*11be35a1SLionel Sambuc     b = true;
354*11be35a1SLionel Sambuc     REQUIRE_ERROR(atf_text_to_bool("", &b));
355*11be35a1SLionel Sambuc     ATF_REQUIRE(b);
356*11be35a1SLionel Sambuc 
357*11be35a1SLionel Sambuc     b = false;
358*11be35a1SLionel Sambuc     REQUIRE_ERROR(atf_text_to_bool("tru", &b));
359*11be35a1SLionel Sambuc     ATF_REQUIRE(!b);
360*11be35a1SLionel Sambuc     b = true;
361*11be35a1SLionel Sambuc     REQUIRE_ERROR(atf_text_to_bool("tru", &b));
362*11be35a1SLionel Sambuc     ATF_REQUIRE(b);
363*11be35a1SLionel Sambuc 
364*11be35a1SLionel Sambuc     b = false;
365*11be35a1SLionel Sambuc     REQUIRE_ERROR(atf_text_to_bool("true2", &b));
366*11be35a1SLionel Sambuc     ATF_REQUIRE(!b);
367*11be35a1SLionel Sambuc     b = true;
368*11be35a1SLionel Sambuc     REQUIRE_ERROR(atf_text_to_bool("true2", &b));
369*11be35a1SLionel Sambuc     ATF_REQUIRE(b);
370*11be35a1SLionel Sambuc 
371*11be35a1SLionel Sambuc     b = false;
372*11be35a1SLionel Sambuc     REQUIRE_ERROR(atf_text_to_bool("fals", &b));
373*11be35a1SLionel Sambuc     ATF_REQUIRE(!b);
374*11be35a1SLionel Sambuc     b = true;
375*11be35a1SLionel Sambuc     REQUIRE_ERROR(atf_text_to_bool("fals", &b));
376*11be35a1SLionel Sambuc     ATF_REQUIRE(b);
377*11be35a1SLionel Sambuc 
378*11be35a1SLionel Sambuc     b = false;
379*11be35a1SLionel Sambuc     REQUIRE_ERROR(atf_text_to_bool("false2", &b));
380*11be35a1SLionel Sambuc     ATF_REQUIRE(!b);
381*11be35a1SLionel Sambuc     b = true;
382*11be35a1SLionel Sambuc     REQUIRE_ERROR(atf_text_to_bool("false2", &b));
383*11be35a1SLionel Sambuc     ATF_REQUIRE(b);
384*11be35a1SLionel Sambuc }
385*11be35a1SLionel Sambuc 
386*11be35a1SLionel Sambuc ATF_TC(to_long);
ATF_TC_HEAD(to_long,tc)387*11be35a1SLionel Sambuc ATF_TC_HEAD(to_long, tc)
388*11be35a1SLionel Sambuc {
389*11be35a1SLionel Sambuc     atf_tc_set_md_var(tc, "descr", "Checks the atf_text_to_long function");
390*11be35a1SLionel Sambuc }
ATF_TC_BODY(to_long,tc)391*11be35a1SLionel Sambuc ATF_TC_BODY(to_long, tc)
392*11be35a1SLionel Sambuc {
393*11be35a1SLionel Sambuc     long l;
394*11be35a1SLionel Sambuc 
395*11be35a1SLionel Sambuc     RE(atf_text_to_long("0", &l)); ATF_REQUIRE_EQ(l, 0);
396*11be35a1SLionel Sambuc     RE(atf_text_to_long("-5", &l)); ATF_REQUIRE_EQ(l, -5);
397*11be35a1SLionel Sambuc     RE(atf_text_to_long("5", &l)); ATF_REQUIRE_EQ(l, 5);
398*11be35a1SLionel Sambuc     RE(atf_text_to_long("123456789", &l)); ATF_REQUIRE_EQ(l, 123456789);
399*11be35a1SLionel Sambuc 
400*11be35a1SLionel Sambuc     l = 1212;
401*11be35a1SLionel Sambuc     REQUIRE_ERROR(atf_text_to_long("", &l));
402*11be35a1SLionel Sambuc     ATF_REQUIRE_EQ(l, 1212);
403*11be35a1SLionel Sambuc     REQUIRE_ERROR(atf_text_to_long("foo", &l));
404*11be35a1SLionel Sambuc     ATF_REQUIRE_EQ(l, 1212);
405*11be35a1SLionel Sambuc     REQUIRE_ERROR(atf_text_to_long("1234x", &l));
406*11be35a1SLionel Sambuc     ATF_REQUIRE_EQ(l, 1212);
407*11be35a1SLionel Sambuc }
408*11be35a1SLionel Sambuc 
409*11be35a1SLionel Sambuc /* ---------------------------------------------------------------------
410*11be35a1SLionel Sambuc  * Main.
411*11be35a1SLionel Sambuc  * --------------------------------------------------------------------- */
412*11be35a1SLionel Sambuc 
ATF_TP_ADD_TCS(tp)413*11be35a1SLionel Sambuc ATF_TP_ADD_TCS(tp)
414*11be35a1SLionel Sambuc {
415*11be35a1SLionel Sambuc     ATF_TP_ADD_TC(tp, for_each_word);
416*11be35a1SLionel Sambuc     ATF_TP_ADD_TC(tp, format);
417*11be35a1SLionel Sambuc     ATF_TP_ADD_TC(tp, format_ap);
418*11be35a1SLionel Sambuc     ATF_TP_ADD_TC(tp, split);
419*11be35a1SLionel Sambuc     ATF_TP_ADD_TC(tp, split_delims);
420*11be35a1SLionel Sambuc     ATF_TP_ADD_TC(tp, to_bool);
421*11be35a1SLionel Sambuc     ATF_TP_ADD_TC(tp, to_long);
422*11be35a1SLionel Sambuc 
423*11be35a1SLionel Sambuc     return atf_no_error();
424*11be35a1SLionel Sambuc }
425