Remove building with NOCRYPTO option
[minix3.git] / external / bsd / atf / dist / tools / ui_test.cpp
blobe4d9050eab9eff41f4edc28f6b2d893359f6f14a
1 //
2 // Automated Testing Framework (atf)
3 //
4 // Copyright (c) 2009 The NetBSD Foundation, Inc.
5 // All rights reserved.
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
9 // are met:
10 // 1. Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 // 2. Redistributions in binary form must reproduce the above copyright
13 // notice, this list of conditions and the following disclaimer in the
14 // documentation and/or other materials provided with the distribution.
16 // THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17 // CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 // IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 // GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 // IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 // IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include <cstring>
31 #include <iostream>
33 #include <atf-c++.hpp>
35 #include "env.hpp"
36 #include "ui.hpp"
38 // ------------------------------------------------------------------------
39 // Test cases for the free functions.
40 // ------------------------------------------------------------------------
42 struct test {
43 const char *tc;
44 const char *tag;
45 bool repeat;
46 size_t col;
47 const char *fmt;
48 const char *result;
49 } tests[] = {
51 // wo_tag
55 "wo_tag",
56 "",
57 false,
59 "12345",
60 "12345",
64 "wo_tag",
65 "",
66 false,
68 "12345 ",
69 "12345",
73 "wo_tag",
74 "",
75 false,
77 "12345 7890",
78 "12345 7890",
82 "wo_tag",
83 "",
84 false,
86 "12345 789012 45",
87 "12345 789012 45",
91 "wo_tag",
92 "",
93 false,
95 "12345 789012 456",
96 "12345 789012\n456",
100 "wo_tag",
102 false,
104 "1234567890123456",
105 "1234567890123456",
108 // TODO(jmmv): Fix the code to pass this test...
109 // {
110 // "wo_tag",
111 // "",
112 // false,
113 // 0,
114 // " 2345678901234567",
115 // "\n2345678901234567",
116 // },
119 "wo_tag",
121 false,
123 "12345 789012345 78",
124 "12345 789012345\n78",
128 // wo_tag_col
132 "wo_tag_col",
134 false,
136 "12345",
137 " 12345",
141 "wo_tag_col",
143 false,
145 "12345 7890",
146 " 12345\n"
147 " 7890",
151 "wo_tag_col",
153 false,
155 "1 3 5 7 9",
156 " 1 3 5\n"
157 " 7 9",
161 // w_tag_no_repeat
165 "w_tag_no_repeat",
166 "1234: ",
167 false,
169 "789012345",
170 "1234: 789012345",
174 "w_tag_no_repeat",
175 "1234: ",
176 false,
178 "789 1234 56789",
179 "1234: 789 1234\n"
180 " 56789",
184 "w_tag_no_repeat",
185 "1234: ",
186 false,
188 "789012345",
189 "1234: 789012345",
193 "w_tag_no_repeat",
194 "1234: ",
195 false,
197 "789012345 7890",
198 "1234: 789012345\n"
199 " 7890",
203 // w_tag_repeat
207 "w_tag_repeat",
208 "1234: ",
209 true,
211 "789012345",
212 "1234: 789012345",
216 "w_tag_repeat",
217 "1234: ",
218 true,
220 "789 1234 56789",
221 "1234: 789 1234\n"
222 "1234: 56789",
226 "w_tag_repeat",
227 "1234: ",
228 true,
230 "789012345",
231 "1234: 789012345",
235 "w_tag_no_repeat",
236 "1234: ",
237 true,
239 "789012345 7890",
240 "1234: 789012345\n"
241 "1234: 7890",
245 // w_tag_col
249 "w_tag_col",
250 "1234:",
251 false,
253 "1 3 5",
254 "1234: 1 3 5",
258 "w_tag_col",
259 "1234:",
260 false,
262 "1 3 5 7 9",
263 "1234: 1 3 5\n"
264 " 7 9",
268 "w_tag_col",
269 "1234:",
270 true,
272 "1 3 5 7 9",
273 "1234: 1 3 5\n"
274 "1234: 7 9",
278 // paragraphs
282 "paragraphs",
284 false,
286 "1 3 5\n\n",
287 "1 3 5"
291 "paragraphs",
293 false,
295 "1 3 5\n2 4 6",
296 "1 3 5\n\n2 4 6"
300 "paragraphs",
302 false,
304 "1234 6789 123456\n2 4 6",
305 "1234 6789\n123456\n\n2 4 6"
309 "paragraphs",
310 "12: ",
311 false,
313 "56789 123456\n2 4 6",
314 "12: 56789\n 123456\n\n 2 4 6"
318 "paragraphs",
319 "12: ",
320 true,
322 "56789 123456\n2 4 6",
323 "12: 56789\n12: 123456\n12: \n12: 2 4 6"
327 "paragraphs",
328 "12:",
329 false,
331 "56789 123456\n2 4 6",
332 "12: 56789\n 123456\n\n 2 4 6"
336 "paragraphs",
337 "12:",
338 true,
340 "56789 123456\n2 4 6",
341 "12: 56789\n12: 123456\n12:\n12: 2 4 6"
345 // end
349 NULL,
350 NULL,
351 false,
353 NULL,
354 NULL,
358 static
359 void
360 run_tests(const char *tc)
362 struct test *t;
364 std::cout << "Running tests for " << tc << "\n";
366 tools::env::set("COLUMNS", "15");
368 for (t = &tests[0]; t->tc != NULL; t++) {
369 if (std::strcmp(t->tc, tc) == 0) {
370 std::cout << "\n";
371 std::cout << "Testing with tag '" << t->tag << "', '"
372 << (t->repeat ? "repeat" : "no repeat") << "', col "
373 << t->col << "\n";
374 std::cout << "Input: >>>" << t->fmt << "<<<\n";
375 std::cout << "Expected output: >>>" << t->result << "<<<\n";
377 std::string result = tools::ui::format_text_with_tag(t->fmt, t->tag,
378 t->repeat, t->col);
379 std::cout << "Output : >>>" << result << "<<<\n";
380 ATF_REQUIRE_EQ(t->result, result);
385 ATF_TEST_CASE(wo_tag);
386 ATF_TEST_CASE_HEAD(wo_tag)
388 set_md_var("descr", "Checks formatting without tags");
390 ATF_TEST_CASE_BODY(wo_tag)
392 run_tests("wo_tag");
395 ATF_TEST_CASE(wo_tag_col);
396 ATF_TEST_CASE_HEAD(wo_tag_col)
398 set_md_var("descr", "Checks formatting without tags and with a non-zero "
399 "starting column");
401 ATF_TEST_CASE_BODY(wo_tag_col)
403 run_tests("wo_tag_col");
406 ATF_TEST_CASE(w_tag_no_repeat);
407 ATF_TEST_CASE_HEAD(w_tag_no_repeat)
409 set_md_var("descr", "Checks formatting with a tag");
411 ATF_TEST_CASE_BODY(w_tag_no_repeat)
413 run_tests("w_tag_no_repeat");
416 ATF_TEST_CASE(w_tag_repeat);
417 ATF_TEST_CASE_HEAD(w_tag_repeat)
419 set_md_var("descr", "Checks formatting with a tag and repeating it on "
420 "each line");
422 ATF_TEST_CASE_BODY(w_tag_repeat)
424 run_tests("w_tag_repeat");
427 ATF_TEST_CASE(w_tag_col);
428 ATF_TEST_CASE_HEAD(w_tag_col)
430 set_md_var("descr", "Checks formatting with a tag and starting at a "
431 "column greater than its length");
433 ATF_TEST_CASE_BODY(w_tag_col)
435 run_tests("w_tag_col");
438 ATF_TEST_CASE(paragraphs);
439 ATF_TEST_CASE_HEAD(paragraphs)
441 set_md_var("descr", "Checks formatting a string that contains multiple "
442 "paragraphs");
444 ATF_TEST_CASE_BODY(paragraphs)
446 run_tests("paragraphs");
449 // ------------------------------------------------------------------------
450 // Main.
451 // ------------------------------------------------------------------------
453 ATF_INIT_TEST_CASES(tcs)
455 // Add the test cases for the free functions.
456 ATF_ADD_TEST_CASE(tcs, wo_tag);
457 ATF_ADD_TEST_CASE(tcs, wo_tag_col);
458 ATF_ADD_TEST_CASE(tcs, w_tag_no_repeat);
459 ATF_ADD_TEST_CASE(tcs, w_tag_repeat);
460 ATF_ADD_TEST_CASE(tcs, w_tag_col);
461 ATF_ADD_TEST_CASE(tcs, paragraphs);