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