xref: /netbsd-src/external/bsd/atf/dist/tools/reader_test.cpp (revision ad23a81712ef29f8911becbb5b5ca2aee6441b2a)
1 //
2 // Automated Testing Framework (atf)
3 //
4 // Copyright (c) 2010 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.
15 //
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.
28 //
29 
30 #include <iostream>
31 #include <sstream>
32 #include <string>
33 #include <utility>
34 #include <vector>
35 
36 #include <atf-c++.hpp>
37 
38 #include "parser.hpp"
39 #include "reader.hpp"
40 #include "test_helpers.hpp"
41 #include "text.hpp"
42 
43 namespace impl = tools::atf_report;
44 
45 class tps_reader : protected impl::atf_tps_reader {
46     void
got_info(const std::string & what,const std::string & val)47     got_info(const std::string& what, const std::string& val)
48     {
49         m_calls.push_back("got_info(" + what + ", " + val + ")");
50     }
51 
52     void
got_ntps(size_t ntps)53     got_ntps(size_t ntps)
54     {
55         m_calls.push_back("got_ntps(" + tools::text::to_string(ntps) + ")");
56     }
57 
58     void
got_tp_start(const std::string & tpname,size_t ntcs)59     got_tp_start(const std::string& tpname, size_t ntcs)
60     {
61         m_calls.push_back("got_tp_start(" + tpname + ", " +
62                           tools::text::to_string(ntcs) + ")");
63     }
64 
65     void
got_tp_end(struct timeval * tv,const std::string & reason)66     got_tp_end(struct timeval* tv __attribute__((__unused__)),
67                const std::string& reason)
68     {
69         m_calls.push_back("got_tp_end(" + reason + ")");
70     }
71 
72     void
got_tc_start(const std::string & tcname)73     got_tc_start(const std::string& tcname)
74     {
75         m_calls.push_back("got_tc_start(" + tcname + ")");
76     }
77 
78     void
got_tc_end(const std::string & state,struct timeval * tv,const std::string & reason)79     got_tc_end(const std::string& state,
80                struct timeval* tv __attribute__((__unused__)),
81                const std::string& reason)
82     {
83         const std::string r = state + (reason.empty() ? "" : ", " + reason);
84         m_calls.push_back("got_tc_end(" + r + ")");
85     }
86 
87     void
got_tc_stdout_line(const std::string & line)88     got_tc_stdout_line(const std::string& line)
89     {
90         m_calls.push_back("got_tc_stdout_line(" + line + ")");
91     }
92 
93     void
got_tc_stderr_line(const std::string & line)94     got_tc_stderr_line(const std::string& line)
95     {
96         m_calls.push_back("got_tc_stderr_line(" + line + ")");
97     }
98 
99     void
got_eof(void)100     got_eof(void)
101     {
102         m_calls.push_back("got_eof()");
103     }
104 
105 public:
tps_reader(std::istream & is)106     tps_reader(std::istream& is) :
107         impl::atf_tps_reader(is)
108     {
109     }
110 
111     void
read(void)112     read(void)
113     {
114         atf_tps_reader::read();
115     }
116 
117     std::vector< std::string > m_calls;
118 };
119 
120 ATF_TEST_CASE_WITHOUT_HEAD(tps_1);
ATF_TEST_CASE_BODY(tps_1)121 ATF_TEST_CASE_BODY(tps_1)
122 {
123     const char* input =
124         "Content-Type: application/X-atf-tps; version=\"3\"\n"
125         "\n"
126         "tps-count: 0\n"
127     ;
128 
129     const char* exp_calls[] = {
130         "got_ntps(0)",
131         "got_eof()",
132         NULL
133     };
134 
135     const char* exp_errors[] = {
136         NULL
137     };
138 
139     do_parser_test< tps_reader >(input, exp_calls, exp_errors);
140 }
141 
142 ATF_TEST_CASE_WITHOUT_HEAD(tps_2);
ATF_TEST_CASE_BODY(tps_2)143 ATF_TEST_CASE_BODY(tps_2)
144 {
145     const char* input =
146         "Content-Type: application/X-atf-tps; version=\"3\"\n"
147         "\n"
148         "tps-count: 2\n"
149         "tp-start: 123.456, first-prog, 0\n"
150         "tp-end: 123.567, first-prog\n"
151         "tp-start: 123.678, second-prog, 0\n"
152         "tp-end: 123.789, second-prog, This program failed\n"
153     ;
154 
155     const char* exp_calls[] = {
156         "got_ntps(2)",
157         "got_tp_start(first-prog, 0)",
158         "got_tp_end()",
159         "got_tp_start(second-prog, 0)",
160         "got_tp_end(This program failed)",
161         "got_eof()",
162         NULL
163     };
164 
165     const char* exp_errors[] = {
166         NULL
167     };
168 
169     do_parser_test< tps_reader >(input, exp_calls, exp_errors);
170 }
171 
172 ATF_TEST_CASE_WITHOUT_HEAD(tps_3);
ATF_TEST_CASE_BODY(tps_3)173 ATF_TEST_CASE_BODY(tps_3)
174 {
175     const char* input =
176         "Content-Type: application/X-atf-tps; version=\"3\"\n"
177         "\n"
178         "tps-count: 2\n"
179         "tp-start: 123.123, first-prog, 3\n"
180         "tc-start: 123.234, first-test\n"
181         "tc-end: 123.345, first-test, passed\n"
182         "tc-start: 123.456, second-test\n"
183         "tc-end: 123.567, second-test, skipped, Testing skipped reason\n"
184         "tc-start: 123.678, third.test\n"
185         "tc-end: 123.789, third.test, failed, Testing failed reason\n"
186         "tp-end: 123.890, first-prog\n"
187         "tp-start: 124.901, second-prog, 3\n"
188         "tc-start: 124.1012, first-test\n"
189         "tc-so:first stdout line for 1st test\n"
190         "tc-se:first stderr line for 1st test\n"
191         "tc-so:second stdout line for 1st test\n"
192         "tc-se:second stderr line for 1st test\n"
193         "tc-end: 124.1123, first-test, passed\n"
194         "tc-start: 124.1234, second-test\n"
195         "tc-so:first stdout line for 2nd test\n"
196         "tc-se:first stderr line for 2nd test\n"
197         "tc-so:second stdout line for 2nd test\n"
198         "tc-se:second stderr line for 2nd test\n"
199         "tc-end: 124.1345, second-test, skipped, Testing skipped reason\n"
200         "tc-start: 124.1456, third.test\n"
201         "tc-so:first stdout line for 3rd test\n"
202         "tc-se:first stderr line for 3rd test\n"
203         "tc-so:second stdout line for 3rd test\n"
204         "tc-se:second stderr line for 3rd test\n"
205         "tc-end: 124.1567, third.test, failed, Testing failed reason\n"
206         "tp-end: 124.1678, second-prog, This program failed\n"
207     ;
208 
209     const char* exp_calls[] = {
210         "got_ntps(2)",
211         "got_tp_start(first-prog, 3)",
212         "got_tc_start(first-test)",
213         "got_tc_end(passed)",
214         "got_tc_start(second-test)",
215         "got_tc_end(skipped, Testing skipped reason)",
216         "got_tc_start(third.test)",
217         "got_tc_end(failed, Testing failed reason)",
218         "got_tp_end()",
219         "got_tp_start(second-prog, 3)",
220         "got_tc_start(first-test)",
221         "got_tc_stdout_line(first stdout line for 1st test)",
222         "got_tc_stderr_line(first stderr line for 1st test)",
223         "got_tc_stdout_line(second stdout line for 1st test)",
224         "got_tc_stderr_line(second stderr line for 1st test)",
225         "got_tc_end(passed)",
226         "got_tc_start(second-test)",
227         "got_tc_stdout_line(first stdout line for 2nd test)",
228         "got_tc_stderr_line(first stderr line for 2nd test)",
229         "got_tc_stdout_line(second stdout line for 2nd test)",
230         "got_tc_stderr_line(second stderr line for 2nd test)",
231         "got_tc_end(skipped, Testing skipped reason)",
232         "got_tc_start(third.test)",
233         "got_tc_stdout_line(first stdout line for 3rd test)",
234         "got_tc_stderr_line(first stderr line for 3rd test)",
235         "got_tc_stdout_line(second stdout line for 3rd test)",
236         "got_tc_stderr_line(second stderr line for 3rd test)",
237         "got_tc_end(failed, Testing failed reason)",
238         "got_tp_end(This program failed)",
239         "got_eof()",
240         NULL
241     };
242 
243     const char* exp_errors[] = {
244         NULL
245     };
246 
247     do_parser_test< tps_reader >(input, exp_calls, exp_errors);
248 }
249 
250 ATF_TEST_CASE_WITHOUT_HEAD(tps_4);
ATF_TEST_CASE_BODY(tps_4)251 ATF_TEST_CASE_BODY(tps_4)
252 {
253     const char* input =
254         "Content-Type: application/X-atf-tps; version=\"3\"\n"
255         "\n"
256         "info: a, foo\n"
257         "info: b, bar\n"
258         "info: c, baz\n"
259         "tps-count: 2\n"
260         "tp-start: 234.1, first-prog, 3\n"
261         "tc-start: 234.12, first-test\n"
262         "tc-end: 234.23, first-test, passed\n"
263         "tc-start: 234.34, second-test\n"
264         "tc-end: 234.45, second-test, skipped, Testing skipped reason\n"
265         "tc-start: 234.56, third-test\n"
266         "tc-end: 234.67, third-test, failed, Testing failed reason\n"
267         "tp-end: 234.78, first-prog\n"
268         "tp-start: 234.89, second-prog, 3\n"
269         "tc-start: 234.90, first-test\n"
270         "tc-so:first stdout line for 1st test\n"
271         "tc-se:first stderr line for 1st test\n"
272         "tc-so:second stdout line for 1st test\n"
273         "tc-se:second stderr line for 1st test\n"
274         "tc-end: 234.101, first-test, passed\n"
275         "tc-start: 234.112, second-test\n"
276         "tc-so:first stdout line for 2nd test\n"
277         "tc-se:first stderr line for 2nd test\n"
278         "tc-so:second stdout line for 2nd test\n"
279         "tc-se:second stderr line for 2nd test\n"
280         "tc-end: 234.123, second-test, skipped, Testing skipped reason\n"
281         "tc-start: 234.134, third-test\n"
282         "tc-so:first stdout line for 3rd test\n"
283         "tc-se:first stderr line for 3rd test\n"
284         "tc-so:second stdout line for 3rd test\n"
285         "tc-se:second stderr line for 3rd test\n"
286         "tc-end: 234.145, third-test, failed, Testing failed reason\n"
287         "tp-end: 234.156, second-prog, This program failed\n"
288         "info: d, foo\n"
289         "info: e, bar\n"
290         "info: f, baz\n"
291     ;
292 
293     const char* exp_calls[] = {
294         "got_info(a, foo)",
295         "got_info(b, bar)",
296         "got_info(c, baz)",
297         "got_ntps(2)",
298         "got_tp_start(first-prog, 3)",
299         "got_tc_start(first-test)",
300         "got_tc_end(passed)",
301         "got_tc_start(second-test)",
302         "got_tc_end(skipped, Testing skipped reason)",
303         "got_tc_start(third-test)",
304         "got_tc_end(failed, Testing failed reason)",
305         "got_tp_end()",
306         "got_tp_start(second-prog, 3)",
307         "got_tc_start(first-test)",
308         "got_tc_stdout_line(first stdout line for 1st test)",
309         "got_tc_stderr_line(first stderr line for 1st test)",
310         "got_tc_stdout_line(second stdout line for 1st test)",
311         "got_tc_stderr_line(second stderr line for 1st test)",
312         "got_tc_end(passed)",
313         "got_tc_start(second-test)",
314         "got_tc_stdout_line(first stdout line for 2nd test)",
315         "got_tc_stderr_line(first stderr line for 2nd test)",
316         "got_tc_stdout_line(second stdout line for 2nd test)",
317         "got_tc_stderr_line(second stderr line for 2nd test)",
318         "got_tc_end(skipped, Testing skipped reason)",
319         "got_tc_start(third-test)",
320         "got_tc_stdout_line(first stdout line for 3rd test)",
321         "got_tc_stderr_line(first stderr line for 3rd test)",
322         "got_tc_stdout_line(second stdout line for 3rd test)",
323         "got_tc_stderr_line(second stderr line for 3rd test)",
324         "got_tc_end(failed, Testing failed reason)",
325         "got_tp_end(This program failed)",
326         "got_info(d, foo)",
327         "got_info(e, bar)",
328         "got_info(f, baz)",
329         "got_eof()",
330         NULL
331     };
332 
333     const char* exp_errors[] = {
334         NULL
335     };
336 
337     do_parser_test< tps_reader >(input, exp_calls, exp_errors);
338 }
339 
340 ATF_TEST_CASE_WITHOUT_HEAD(tps_5);
ATF_TEST_CASE_BODY(tps_5)341 ATF_TEST_CASE_BODY(tps_5)
342 {
343     const char* input =
344         "Content-Type: application/X-atf-tps; version=\"3\"\n"
345         "\n"
346         "tps-count: 1\n"
347         "tp-start: 345.123, the-prog, 1\n"
348         "tc-start: 345.134, the-test\n"
349         "tc-so:--- a	2007-11-04 14:00:41.000000000 +0100\n"
350         "tc-so:+++ b	2007-11-04 14:00:48.000000000 +0100\n"
351         "tc-so:@@ -1,7 +1,7 @@\n"
352         "tc-so: This test is meant to simulate a diff.\n"
353         "tc-so: Blank space at beginning of context lines must be preserved.\n"
354         "tc-so: \n"
355         "tc-so:-First original line.\n"
356         "tc-so:-Second original line.\n"
357         "tc-so:+First modified line.\n"
358         "tc-so:+Second modified line.\n"
359         "tc-so: \n"
360         "tc-so: EOF\n"
361         "tc-end: 345.145, the-test, passed\n"
362         "tp-end: 345.156, the-prog\n"
363     ;
364 
365     // NO_CHECK_STYLE_BEGIN
366     const char* exp_calls[] = {
367         "got_ntps(1)",
368         "got_tp_start(the-prog, 1)",
369         "got_tc_start(the-test)",
370         "got_tc_stdout_line(--- a	2007-11-04 14:00:41.000000000 +0100)",
371         "got_tc_stdout_line(+++ b	2007-11-04 14:00:48.000000000 +0100)",
372         "got_tc_stdout_line(@@ -1,7 +1,7 @@)",
373         "got_tc_stdout_line( This test is meant to simulate a diff.)",
374         "got_tc_stdout_line( Blank space at beginning of context lines must be preserved.)",
375         "got_tc_stdout_line( )",
376         "got_tc_stdout_line(-First original line.)",
377         "got_tc_stdout_line(-Second original line.)",
378         "got_tc_stdout_line(+First modified line.)",
379         "got_tc_stdout_line(+Second modified line.)",
380         "got_tc_stdout_line( )",
381         "got_tc_stdout_line( EOF)",
382         "got_tc_end(passed)",
383         "got_tp_end()",
384         "got_eof()",
385         NULL
386     };
387     // NO_CHECK_STYLE_END
388 
389     const char* exp_errors[] = {
390         NULL
391     };
392 
393     do_parser_test< tps_reader >(input, exp_calls, exp_errors);
394 }
395 
396 ATF_TEST_CASE_WITHOUT_HEAD(tps_6);
ATF_TEST_CASE_BODY(tps_6)397 ATF_TEST_CASE_BODY(tps_6)
398 {
399     const char* input =
400         "Content-Type: application/X-atf-tps; version=\"3\"\n"
401         "\n"
402         "tps-count: 1\n"
403         "tp-start: 321.1, the-prog, 8\n"
404         "tc-start: 321.12, one\n"
405         "tc-end: 321.23, one, expected_death, The reason\n"
406         "tc-start: 321.34, two\n"
407         "tc-end: 321.45, two, expected_exit, This would be an exit\n"
408         "tc-start: 321.56, three\n"
409         "tc-end: 321.67, three, expected_failure, And this a failure\n"
410         "tc-start: 321.78, four\n"
411         "tc-end: 321.89, four, expected_signal, And this a signal\n"
412         "tc-start: 321.90, five\n"
413         "tc-end: 321.101, five, failed, Another reason\n"
414         "tc-start: 321.112, six\n"
415         "tc-end: 321.123, six, passed\n"
416         "tc-start: 321.134, seven\n"
417         "tc-end: 321.145, seven, skipped, Skipping it\n"
418         "tc-start: 321.156, eight\n"
419         "tc-end: 321.167, eight, expected_timeout, Some hang reason\n"
420         "tp-end: 321.178, the-prog\n"
421     ;
422 
423     // NO_CHECK_STYLE_BEGIN
424     const char* exp_calls[] = {
425         "got_ntps(1)",
426         "got_tp_start(the-prog, 8)",
427         "got_tc_start(one)",
428         "got_tc_end(expected_death, The reason)",
429         "got_tc_start(two)",
430         "got_tc_end(expected_exit, This would be an exit)",
431         "got_tc_start(three)",
432         "got_tc_end(expected_failure, And this a failure)",
433         "got_tc_start(four)",
434         "got_tc_end(expected_signal, And this a signal)",
435         "got_tc_start(five)",
436         "got_tc_end(failed, Another reason)",
437         "got_tc_start(six)",
438         "got_tc_end(passed)",
439         "got_tc_start(seven)",
440         "got_tc_end(skipped, Skipping it)",
441         "got_tc_start(eight)",
442         "got_tc_end(expected_timeout, Some hang reason)",
443         "got_tp_end()",
444         "got_eof()",
445         NULL
446     };
447     // NO_CHECK_STYLE_END
448 
449     const char* exp_errors[] = {
450         NULL
451     };
452 
453     do_parser_test< tps_reader >(input, exp_calls, exp_errors);
454 }
455 
456 
457 ATF_TEST_CASE_WITHOUT_HEAD(tps_50);
ATF_TEST_CASE_BODY(tps_50)458 ATF_TEST_CASE_BODY(tps_50)
459 {
460     const char* input =
461         "Content-Type: application/X-atf-tps; version=\"3\"\n"
462         "\n"
463         "foo\n"
464     ;
465 
466     const char* exp_calls[] = {
467         NULL
468     };
469 
470     const char* exp_errors[] = {
471         "3: Unexpected token `foo'; expected tps-count or info field",
472         NULL
473     };
474 
475     do_parser_test< tps_reader >(input, exp_calls, exp_errors);
476 }
477 
478 ATF_TEST_CASE_WITHOUT_HEAD(tps_51);
ATF_TEST_CASE_BODY(tps_51)479 ATF_TEST_CASE_BODY(tps_51)
480 {
481     const char* input =
482         "Content-Type: application/X-atf-tps; version=\"3\"\n"
483         "\n"
484         "tps-count\n"
485     ;
486 
487     const char* exp_calls[] = {
488         NULL
489     };
490 
491     const char* exp_errors[] = {
492         "3: Unexpected token `<<NEWLINE>>'; expected `:'",
493         NULL
494     };
495 
496     do_parser_test< tps_reader >(input, exp_calls, exp_errors);
497 }
498 
499 ATF_TEST_CASE_WITHOUT_HEAD(tps_52);
ATF_TEST_CASE_BODY(tps_52)500 ATF_TEST_CASE_BODY(tps_52)
501 {
502     const char* input =
503         "Content-Type: application/X-atf-tps; version=\"3\"\n"
504         "\n"
505         "tps-count:\n"
506     ;
507 
508     const char* exp_calls[] = {
509         NULL
510     };
511 
512     const char* exp_errors[] = {
513         "3: Unexpected token `<<NEWLINE>>'; expected number of test programs",
514         NULL
515     };
516 
517     do_parser_test< tps_reader >(input, exp_calls, exp_errors);
518 }
519 
520 ATF_TEST_CASE_WITHOUT_HEAD(tps_53);
ATF_TEST_CASE_BODY(tps_53)521 ATF_TEST_CASE_BODY(tps_53)
522 {
523     const char* input =
524         "Content-Type: application/X-atf-tps; version=\"3\"\n"
525         "\n"
526         "tps-count: 1\n"
527         "foo\n"
528     ;
529 
530     const char* exp_calls[] = {
531         "got_ntps(1)",
532         NULL
533     };
534 
535     const char* exp_errors[] = {
536         "4: Unexpected token `foo'; expected start of test program",
537         NULL
538     };
539 
540     do_parser_test< tps_reader >(input, exp_calls, exp_errors);
541 }
542 
543 ATF_TEST_CASE_WITHOUT_HEAD(tps_54);
ATF_TEST_CASE_BODY(tps_54)544 ATF_TEST_CASE_BODY(tps_54)
545 {
546     const char* input =
547         "Content-Type: application/X-atf-tps; version=\"3\"\n"
548         "\n"
549         "tps-count: 1\n"
550         "foo\n"
551         "tp-start\n"
552         "tp-start:\n"
553         "tp-start: 123\n"
554         "tp-start: 123.\n"
555         "tp-start: 123.456\n"
556         "tp-start: 123.456,\n"
557         "tp-start: 123.456, foo\n"
558         "tp-start: 123.456, foo,\n"
559         "tp-start: 123.456, foo, 0\n"
560         "bar\n"
561         "tp-start: 456.789, foo, 0\n"
562         "tp-end\n"
563         "tp-start: 777.777, foo, 0\n"
564         "tp-end:\n"
565         "tp-start: 777.777, foo, 0\n"
566         "tp-end: 777\n"
567         "tp-start: 777.777, foo, 0\n"
568         "tp-end: 777.\n"
569         "tp-start: 777.777, foo, 0\n"
570         "tp-end: 777.888\n"
571         "tp-start: 777.777, foo, 0\n"
572         "tp-end: 777.888, \n"
573         "tp-start: 777.777, foo, 0\n"
574         "tp-end: 777.888, bar\n"
575         "tp-start: 777.777, foo, 0\n"
576         "tp-end: 777.888, foo,\n"
577     ;
578 
579     const char* exp_calls[] = {
580         "got_ntps(1)",
581         NULL
582     };
583 
584     const char* exp_errors[] = {
585         "4: Unexpected token `foo'; expected start of test program",
586         "5: Unexpected token `<<NEWLINE>>'; expected `:'",
587         "6: Unexpected token `<<NEWLINE>>'; expected timestamp",
588         "7: Malformed timestamp value 123",
589         "8: Malformed timestamp value 123.",
590         "9: Unexpected token `<<NEWLINE>>'; expected `,'",
591         "10: Unexpected token `<<NEWLINE>>'; expected test program name",
592         "11: Unexpected token `<<NEWLINE>>'; expected `,'",
593         "12: Unexpected token `<<NEWLINE>>'; expected number of test programs",
594         "14: Unexpected token `bar'; expected end of test program",
595         "16: Unexpected token `<<NEWLINE>>'; expected `:'",
596         "18: Unexpected token `<<NEWLINE>>'; expected timestamp",
597         "20: Malformed timestamp value 777",
598         "22: Malformed timestamp value 777.",
599         "24: Unexpected token `<<NEWLINE>>'; expected `,'",
600 
601         "26: Unexpected token `<<NEWLINE>>'; expected test program name",
602         "28: Test program name used in terminator does not match opening",
603         "30: Empty reason for failed test program",
604         NULL
605     };
606 
607     do_parser_test< tps_reader >(input, exp_calls, exp_errors);
608 }
609 
610 ATF_TEST_CASE_WITHOUT_HEAD(tps_55);
ATF_TEST_CASE_BODY(tps_55)611 ATF_TEST_CASE_BODY(tps_55)
612 {
613     const char* input =
614         "Content-Type: application/X-atf-tps; version=\"3\"\n"
615         "\n"
616         "tps-count: 1\n"
617         "tp-start: 100.200, foo, 1\n"
618         "foo\n"
619         "tc-start\n"
620         "tc-start:\n"
621         "tc-start: 111\n"
622         "tc-start: 111.\n"
623         "tc-start: 111.222\n"
624         "tc-start: 111.222,\n"
625         "tc-start: 111.222, foo\n"
626         "bar\n"
627         "tc-start: 111.333, foo\n"
628         "tc-end\n"
629         "tc-start: 111.444, foo\n"
630         "tc-end:\n"
631         "tc-start: 111.444, foo\n"
632         "tc-end: 111\n"
633         "tc-start: 111.444, foo\n"
634         "tc-end: 111.\n"
635         "tc-start: 111.444, foo\n"
636         "tc-end: 111.555\n"
637         "tc-start: 111.444, foo\n"
638         "tc-end: 111.555, \n"
639         "tc-start: 111.444, foo\n"
640         "tc-end: 111.555, bar\n"
641         "tc-start: 111.444, foo\n"
642         "tc-end: 111.555, foo\n"
643         "tc-start: 111.444, foo\n"
644         "tc-end: 111.555, foo,\n"
645         "tp-end: 111.666, foo\n"
646     ;
647 
648     const char* exp_calls[] = {
649         "got_ntps(1)",
650         "got_tp_start(foo, 1)",
651         NULL
652     };
653 
654     // NO_CHECK_STYLE_BEGIN
655     const char* exp_errors[] = {
656         "5: Unexpected token `foo'; expected start of test case",
657         "6: Unexpected token `<<NEWLINE>>'; expected `:'",
658         "7: Unexpected token `<<NEWLINE>>'; expected timestamp",
659         "8: Malformed timestamp value 111",
660         "9: Malformed timestamp value 111.",
661         "10: Unexpected token `<<NEWLINE>>'; expected `,'",
662         "11: Unexpected token `<<NEWLINE>>'; expected test case name",
663         "13: Unexpected token `bar'; expected end of test case or test case's stdout/stderr line",
664         "15: Unexpected token `<<NEWLINE>>'; expected `:'",
665         "17: Unexpected token `<<NEWLINE>>'; expected timestamp",
666         "19: Malformed timestamp value 111",
667         "21: Malformed timestamp value 111.",
668         "23: Unexpected token `<<NEWLINE>>'; expected `,'",
669         "25: Unexpected token `<<NEWLINE>>'; expected test case name",
670         "27: Test case name used in terminator does not match opening",
671         "29: Unexpected token `<<NEWLINE>>'; expected `,'",
672         "31: Unexpected token `<<NEWLINE>>'; expected expected_{death,exit,failure,signal,timeout}, failed, passed or skipped",
673         "32: Unexpected token `tp-end'; expected start of test case",
674         NULL
675     };
676     // NO_CHECK_STYLE_END
677 
678     do_parser_test< tps_reader >(input, exp_calls, exp_errors);
679 }
680 
681 ATF_TEST_CASE_WITHOUT_HEAD(tps_56);
ATF_TEST_CASE_BODY(tps_56)682 ATF_TEST_CASE_BODY(tps_56)
683 {
684     const char* input =
685         "Content-Type: application/X-atf-tps; version=\"3\"\n"
686         "\n"
687         "tps-count: 1\n"
688         "tp-start: 111.222, foo, 1\n"
689         "tc-start: 111.333, foo\n"
690         "tc-end: 111.444, foo, passe\n"
691         "tc-start: 111.333, foo\n"
692         "tc-end: 111.444, foo, passed,\n"
693         "tc-start: 111.555, bar\n"
694         "tc-end: 111.666, bar, failed\n"
695         "tc-start: 111.555, bar\n"
696         "tc-end: 111.666, bar, failed,\n"
697         "tc-start: 111.555, baz\n"
698         "tc-end: 111.666, baz, skipped\n"
699         "tc-start: 111.555, baz\n"
700         "tc-end: 111.666, baz, skipped,\n"
701         "tp-end: 111.777, foo\n"
702     ;
703 
704     const char* exp_calls[] = {
705         "got_ntps(1)",
706         "got_tp_start(foo, 1)",
707         "got_tc_start(foo)",
708         NULL
709     };
710 
711     // NO_CHECK_STYLE_BEGIN
712     const char* exp_errors[] = {
713         "6: Unexpected token `passe'; expected expected_{death,exit,failure,signal,timeout}, failed, passed or skipped",
714         "8: Unexpected token `,'; expected new line",
715         "10: Unexpected token `<<NEWLINE>>'; expected `,'",
716         "12: Empty reason for failed test case result",
717         "14: Unexpected token `<<NEWLINE>>'; expected `,'",
718         "16: Empty reason for skipped test case result",
719         "17: Unexpected token `tp-end'; expected start of test case",
720         NULL
721     };
722     // NO_CHECK_STYLE_END
723 
724     do_parser_test< tps_reader >(input, exp_calls, exp_errors);
725 }
726 
727 ATF_TEST_CASE_WITHOUT_HEAD(tps_57);
ATF_TEST_CASE_BODY(tps_57)728 ATF_TEST_CASE_BODY(tps_57)
729 {
730     const char* input =
731         "Content-Type: application/X-atf-tps; version=\"3\"\n"
732         "\n"
733         "tps-count: 2\n"
734         "tp-start: 111.222, foo, 0\n"
735         "tp-end: 111.333, foo\n"
736     ;
737 
738     const char* exp_calls[] = {
739         "got_ntps(2)",
740         "got_tp_start(foo, 0)",
741         "got_tp_end()",
742         NULL
743     };
744 
745     const char* exp_errors[] = {
746         "6: Unexpected token `<<EOF>>'; expected start of test program",
747         NULL
748     };
749 
750     do_parser_test< tps_reader >(input, exp_calls, exp_errors);
751 }
752 
753 ATF_TEST_CASE_WITHOUT_HEAD(tps_58);
ATF_TEST_CASE_BODY(tps_58)754 ATF_TEST_CASE_BODY(tps_58)
755 {
756     const char* input =
757         "Content-Type: application/X-atf-tps; version=\"3\"\n"
758         "\n"
759         "tps-count: 1\n"
760         "tp-start: 111.222, foo, 0\n"
761         "tp-end: 111.333, foo\n"
762         "tp-start: 111.444, bar, 0\n"
763         "tp-end: 111.555, bar\n"
764     ;
765 
766     const char* exp_calls[] = {
767         "got_ntps(1)",
768         "got_tp_start(foo, 0)",
769         "got_tp_end()",
770         NULL
771     };
772 
773     const char* exp_errors[] = {
774         "6: Unexpected token `tp-start'; expected end of stream or info field",
775         NULL
776     };
777 
778     do_parser_test< tps_reader >(input, exp_calls, exp_errors);
779 }
780 
781 ATF_TEST_CASE_WITHOUT_HEAD(tps_59);
ATF_TEST_CASE_BODY(tps_59)782 ATF_TEST_CASE_BODY(tps_59)
783 {
784     const char* input =
785         "Content-Type: application/X-atf-tps; version=\"3\"\n"
786         "\n"
787         "info\n"
788     ;
789 
790     const char* exp_calls[] = {
791         NULL
792     };
793 
794     const char* exp_errors[] = {
795         "3: Unexpected token `<<NEWLINE>>'; expected `:'",
796         NULL
797     };
798 
799     do_parser_test< tps_reader >(input, exp_calls, exp_errors);
800 }
801 
802 ATF_TEST_CASE_WITHOUT_HEAD(tps_60);
ATF_TEST_CASE_BODY(tps_60)803 ATF_TEST_CASE_BODY(tps_60)
804 {
805     const char* input =
806         "Content-Type: application/X-atf-tps; version=\"3\"\n"
807         "\n"
808         "info:\n"
809     ;
810 
811     const char* exp_calls[] = {
812         NULL
813     };
814 
815     const char* exp_errors[] = {
816         "3: Unexpected token `<<NEWLINE>>'; expected info property name",
817         NULL
818     };
819 
820     do_parser_test< tps_reader >(input, exp_calls, exp_errors);
821 }
822 
823 ATF_TEST_CASE_WITHOUT_HEAD(tps_61);
ATF_TEST_CASE_BODY(tps_61)824 ATF_TEST_CASE_BODY(tps_61)
825 {
826     const char* input =
827         "Content-Type: application/X-atf-tps; version=\"3\"\n"
828         "\n"
829         "info: a\n"
830     ;
831 
832     const char* exp_calls[] = {
833         NULL
834     };
835 
836     const char* exp_errors[] = {
837         "3: Unexpected token `<<NEWLINE>>'; expected `,'",
838         NULL
839     };
840 
841     do_parser_test< tps_reader >(input, exp_calls, exp_errors);
842 }
843 
844 ATF_TEST_CASE_WITHOUT_HEAD(tps_62);
ATF_TEST_CASE_BODY(tps_62)845 ATF_TEST_CASE_BODY(tps_62)
846 {
847     const char* input =
848         "Content-Type: application/X-atf-tps; version=\"3\"\n"
849         "\n"
850         "info: a,\n"
851     ;
852 
853     const char* exp_calls[] = {
854         "got_info(a, )",
855         NULL
856     };
857 
858     const char* exp_errors[] = {
859         "4: Unexpected token `<<EOF>>'; expected tps-count or info field",
860         NULL
861     };
862 
863     do_parser_test< tps_reader >(input, exp_calls, exp_errors);
864 }
865 
866 ATF_TEST_CASE_WITHOUT_HEAD(tps_63);
ATF_TEST_CASE_BODY(tps_63)867 ATF_TEST_CASE_BODY(tps_63)
868 {
869     const char* input =
870         "Content-Type: application/X-atf-tps; version=\"3\"\n"
871         "\n"
872         "info: a, b\n"
873     ;
874 
875     const char* exp_calls[] = {
876         "got_info(a, b)",
877         NULL
878     };
879 
880     const char* exp_errors[] = {
881         "4: Unexpected token `<<EOF>>'; expected tps-count or info field",
882         NULL
883     };
884 
885     do_parser_test< tps_reader >(input, exp_calls, exp_errors);
886 }
887 
888 ATF_TEST_CASE_WITHOUT_HEAD(tps_64);
ATF_TEST_CASE_BODY(tps_64)889 ATF_TEST_CASE_BODY(tps_64)
890 {
891     const char* input =
892         "Content-Type: application/X-atf-tps; version=\"3\"\n"
893         "\n"
894         "info: a, b\n"
895         "info: a.b.c.def, g\n"
896         "tps-count\n"
897     ;
898 
899     const char* exp_calls[] = {
900         "got_info(a, b)",
901         "got_info(a.b.c.def, g)",
902         NULL
903     };
904 
905     const char* exp_errors[] = {
906         "5: Unexpected token `<<NEWLINE>>'; expected `:'",
907         NULL
908     };
909 
910     do_parser_test< tps_reader >(input, exp_calls, exp_errors);
911 }
912 
913 ATF_TEST_CASE_WITHOUT_HEAD(tps_65);
ATF_TEST_CASE_BODY(tps_65)914 ATF_TEST_CASE_BODY(tps_65)
915 {
916     const char* input =
917         "Content-Type: application/X-atf-tps; version=\"3\"\n"
918         "\n"
919         "info: a, b\n"
920         "tps-count:\n"
921     ;
922 
923     const char* exp_calls[] = {
924         "got_info(a, b)",
925         NULL
926     };
927 
928     const char* exp_errors[] = {
929         "4: Unexpected token `<<NEWLINE>>'; expected number of test programs",
930         NULL
931     };
932 
933     do_parser_test< tps_reader >(input, exp_calls, exp_errors);
934 }
935 
936 ATF_TEST_CASE_WITHOUT_HEAD(tps_66);
ATF_TEST_CASE_BODY(tps_66)937 ATF_TEST_CASE_BODY(tps_66)
938 {
939     const char* input =
940         "Content-Type: application/X-atf-tps; version=\"3\"\n"
941         "\n"
942         "info: a, b\n"
943         "tps-count: 0\n"
944         "info\n"
945     ;
946 
947     const char* exp_calls[] = {
948         "got_info(a, b)",
949         "got_ntps(0)",
950         NULL
951     };
952 
953     const char* exp_errors[] = {
954         "5: Unexpected token `<<NEWLINE>>'; expected `:'",
955         NULL
956     };
957 
958     do_parser_test< tps_reader >(input, exp_calls, exp_errors);
959 }
960 
ATF_INIT_TEST_CASES(tcs)961 ATF_INIT_TEST_CASES(tcs)
962 {
963     ATF_ADD_TEST_CASE(tcs, tps_1);
964     ATF_ADD_TEST_CASE(tcs, tps_2);
965     ATF_ADD_TEST_CASE(tcs, tps_3);
966     ATF_ADD_TEST_CASE(tcs, tps_4);
967     ATF_ADD_TEST_CASE(tcs, tps_5);
968     ATF_ADD_TEST_CASE(tcs, tps_6);
969     ATF_ADD_TEST_CASE(tcs, tps_50);
970     ATF_ADD_TEST_CASE(tcs, tps_51);
971     ATF_ADD_TEST_CASE(tcs, tps_52);
972     ATF_ADD_TEST_CASE(tcs, tps_53);
973     ATF_ADD_TEST_CASE(tcs, tps_54);
974     ATF_ADD_TEST_CASE(tcs, tps_55);
975     ATF_ADD_TEST_CASE(tcs, tps_56);
976     ATF_ADD_TEST_CASE(tcs, tps_57);
977     ATF_ADD_TEST_CASE(tcs, tps_58);
978     ATF_ADD_TEST_CASE(tcs, tps_59);
979     ATF_ADD_TEST_CASE(tcs, tps_60);
980     ATF_ADD_TEST_CASE(tcs, tps_61);
981     ATF_ADD_TEST_CASE(tcs, tps_62);
982     ATF_ADD_TEST_CASE(tcs, tps_63);
983     ATF_ADD_TEST_CASE(tcs, tps_64);
984     ATF_ADD_TEST_CASE(tcs, tps_65);
985     ATF_ADD_TEST_CASE(tcs, tps_66);
986 }
987 
988