1*0a6a1f1dSLionel Sambuc //
2*0a6a1f1dSLionel Sambuc // Automated Testing Framework (atf)
3*0a6a1f1dSLionel Sambuc //
4*0a6a1f1dSLionel Sambuc // Copyright (c) 2010 The NetBSD Foundation, Inc.
5*0a6a1f1dSLionel Sambuc // All rights reserved.
6*0a6a1f1dSLionel Sambuc //
7*0a6a1f1dSLionel Sambuc // Redistribution and use in source and binary forms, with or without
8*0a6a1f1dSLionel Sambuc // modification, are permitted provided that the following conditions
9*0a6a1f1dSLionel Sambuc // are met:
10*0a6a1f1dSLionel Sambuc // 1. Redistributions of source code must retain the above copyright
11*0a6a1f1dSLionel Sambuc //    notice, this list of conditions and the following disclaimer.
12*0a6a1f1dSLionel Sambuc // 2. Redistributions in binary form must reproduce the above copyright
13*0a6a1f1dSLionel Sambuc //    notice, this list of conditions and the following disclaimer in the
14*0a6a1f1dSLionel Sambuc //    documentation and/or other materials provided with the distribution.
15*0a6a1f1dSLionel Sambuc //
16*0a6a1f1dSLionel Sambuc // THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17*0a6a1f1dSLionel Sambuc // CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18*0a6a1f1dSLionel Sambuc // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19*0a6a1f1dSLionel Sambuc // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20*0a6a1f1dSLionel Sambuc // IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21*0a6a1f1dSLionel Sambuc // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22*0a6a1f1dSLionel Sambuc // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23*0a6a1f1dSLionel Sambuc // GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24*0a6a1f1dSLionel Sambuc // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25*0a6a1f1dSLionel Sambuc // IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26*0a6a1f1dSLionel Sambuc // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27*0a6a1f1dSLionel Sambuc // IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*0a6a1f1dSLionel Sambuc //
29*0a6a1f1dSLionel Sambuc 
30*0a6a1f1dSLionel Sambuc #include <fstream>
31*0a6a1f1dSLionel Sambuc #include <iostream>
32*0a6a1f1dSLionel Sambuc 
33*0a6a1f1dSLionel Sambuc #include <atf-c++.hpp>
34*0a6a1f1dSLionel Sambuc 
35*0a6a1f1dSLionel Sambuc #include "parser.hpp"
36*0a6a1f1dSLionel Sambuc #include "test-program.hpp"
37*0a6a1f1dSLionel Sambuc #include "test_helpers.hpp"
38*0a6a1f1dSLionel Sambuc #include "text.hpp"
39*0a6a1f1dSLionel Sambuc 
40*0a6a1f1dSLionel Sambuc namespace impl = tools::test_program;
41*0a6a1f1dSLionel Sambuc namespace detail = tools::test_program::detail;
42*0a6a1f1dSLionel Sambuc 
43*0a6a1f1dSLionel Sambuc // -------------------------------------------------------------------------
44*0a6a1f1dSLionel Sambuc // Auxiliary functions.
45*0a6a1f1dSLionel Sambuc // -------------------------------------------------------------------------
46*0a6a1f1dSLionel Sambuc 
47*0a6a1f1dSLionel Sambuc namespace {
48*0a6a1f1dSLionel Sambuc 
49*0a6a1f1dSLionel Sambuc typedef std::map< std::string, std::string > vars_map;
50*0a6a1f1dSLionel Sambuc 
51*0a6a1f1dSLionel Sambuc static
52*0a6a1f1dSLionel Sambuc tools::fs::path
get_helper(const atf::tests::tc & tc,const char * name)53*0a6a1f1dSLionel Sambuc get_helper(const atf::tests::tc& tc, const char* name)
54*0a6a1f1dSLionel Sambuc {
55*0a6a1f1dSLionel Sambuc     return tools::fs::path(tc.get_config_var("srcdir")) / name;
56*0a6a1f1dSLionel Sambuc }
57*0a6a1f1dSLionel Sambuc 
58*0a6a1f1dSLionel Sambuc static
59*0a6a1f1dSLionel Sambuc void
check_property(const vars_map & props,const char * name,const char * value)60*0a6a1f1dSLionel Sambuc check_property(const vars_map& props, const char* name, const char* value)
61*0a6a1f1dSLionel Sambuc {
62*0a6a1f1dSLionel Sambuc     const vars_map::const_iterator iter = props.find(name);
63*0a6a1f1dSLionel Sambuc     ATF_REQUIRE(iter != props.end());
64*0a6a1f1dSLionel Sambuc     ATF_REQUIRE_EQ(value, (*iter).second);
65*0a6a1f1dSLionel Sambuc }
66*0a6a1f1dSLionel Sambuc 
67*0a6a1f1dSLionel Sambuc static void
check_result(const char * exp_state,const int exp_value,const char * exp_reason,const impl::test_case_result & tcr)68*0a6a1f1dSLionel Sambuc check_result(const char* exp_state, const int exp_value, const char* exp_reason,
69*0a6a1f1dSLionel Sambuc              const impl::test_case_result& tcr)
70*0a6a1f1dSLionel Sambuc {
71*0a6a1f1dSLionel Sambuc     ATF_REQUIRE_EQ(exp_state, tcr.state());
72*0a6a1f1dSLionel Sambuc     ATF_REQUIRE_EQ(exp_value, tcr.value());
73*0a6a1f1dSLionel Sambuc     ATF_REQUIRE_EQ(exp_reason, tcr.reason());
74*0a6a1f1dSLionel Sambuc }
75*0a6a1f1dSLionel Sambuc 
76*0a6a1f1dSLionel Sambuc static
77*0a6a1f1dSLionel Sambuc void
write_test_case_result(const char * results_path,const std::string & contents)78*0a6a1f1dSLionel Sambuc write_test_case_result(const char *results_path, const std::string& contents)
79*0a6a1f1dSLionel Sambuc {
80*0a6a1f1dSLionel Sambuc     std::ofstream results_file(results_path);
81*0a6a1f1dSLionel Sambuc     ATF_REQUIRE(results_file);
82*0a6a1f1dSLionel Sambuc 
83*0a6a1f1dSLionel Sambuc     results_file << contents;
84*0a6a1f1dSLionel Sambuc }
85*0a6a1f1dSLionel Sambuc 
86*0a6a1f1dSLionel Sambuc static
87*0a6a1f1dSLionel Sambuc void
print_indented(const std::string & str)88*0a6a1f1dSLionel Sambuc print_indented(const std::string& str)
89*0a6a1f1dSLionel Sambuc {
90*0a6a1f1dSLionel Sambuc     std::vector< std::string > ws = tools::text::split(str, "\n");
91*0a6a1f1dSLionel Sambuc     for (std::vector< std::string >::const_iterator iter = ws.begin();
92*0a6a1f1dSLionel Sambuc          iter != ws.end(); iter++)
93*0a6a1f1dSLionel Sambuc         std::cout << ">>" << *iter << "<<\n";
94*0a6a1f1dSLionel Sambuc }
95*0a6a1f1dSLionel Sambuc 
96*0a6a1f1dSLionel Sambuc // XXX Should this string handling and verbosity level be part of the
97*0a6a1f1dSLionel Sambuc // ATF_REQUIRE_EQ macro?  It may be hard to predict sometimes that a
98*0a6a1f1dSLionel Sambuc // string can have newlines in it, and so the error message generated
99*0a6a1f1dSLionel Sambuc // at the moment will be bogus if there are some.
100*0a6a1f1dSLionel Sambuc static
101*0a6a1f1dSLionel Sambuc void
check_match(const atf::tests::tc & tc,const std::string & str,const std::string & exp)102*0a6a1f1dSLionel Sambuc check_match(const atf::tests::tc& tc, const std::string& str,
103*0a6a1f1dSLionel Sambuc             const std::string& exp)
104*0a6a1f1dSLionel Sambuc {
105*0a6a1f1dSLionel Sambuc     if (!tools::text::match(str, exp)) {
106*0a6a1f1dSLionel Sambuc         std::cout << "String match check failed.\n"
107*0a6a1f1dSLionel Sambuc                   << "Adding >> and << to delimit the string boundaries "
108*0a6a1f1dSLionel Sambuc                      "below.\n";
109*0a6a1f1dSLionel Sambuc         std::cout << "GOT:\n";
110*0a6a1f1dSLionel Sambuc         print_indented(str);
111*0a6a1f1dSLionel Sambuc         std::cout << "EXPECTED:\n";
112*0a6a1f1dSLionel Sambuc         print_indented(exp);
113*0a6a1f1dSLionel Sambuc         tc.fail("Constructed string differs from the expected one");
114*0a6a1f1dSLionel Sambuc     }
115*0a6a1f1dSLionel Sambuc }
116*0a6a1f1dSLionel Sambuc 
117*0a6a1f1dSLionel Sambuc }  // anonymous namespace
118*0a6a1f1dSLionel Sambuc 
119*0a6a1f1dSLionel Sambuc // -------------------------------------------------------------------------
120*0a6a1f1dSLionel Sambuc // Tests for the "tp" reader.
121*0a6a1f1dSLionel Sambuc // -------------------------------------------------------------------------
122*0a6a1f1dSLionel Sambuc 
123*0a6a1f1dSLionel Sambuc class tp_reader : protected detail::atf_tp_reader {
124*0a6a1f1dSLionel Sambuc     void
got_tc(const std::string & ident,const std::map<std::string,std::string> & md)125*0a6a1f1dSLionel Sambuc     got_tc(const std::string& ident,
126*0a6a1f1dSLionel Sambuc            const std::map< std::string, std::string >& md)
127*0a6a1f1dSLionel Sambuc     {
128*0a6a1f1dSLionel Sambuc         std::string call = "got_tc(" + ident + ", {";
129*0a6a1f1dSLionel Sambuc         for (std::map< std::string, std::string >::const_iterator iter =
130*0a6a1f1dSLionel Sambuc              md.begin(); iter != md.end(); iter++) {
131*0a6a1f1dSLionel Sambuc             if (iter != md.begin())
132*0a6a1f1dSLionel Sambuc                 call += ", ";
133*0a6a1f1dSLionel Sambuc             call += (*iter).first + '=' + (*iter).second;
134*0a6a1f1dSLionel Sambuc         }
135*0a6a1f1dSLionel Sambuc         call += "})";
136*0a6a1f1dSLionel Sambuc         m_calls.push_back(call);
137*0a6a1f1dSLionel Sambuc     }
138*0a6a1f1dSLionel Sambuc 
139*0a6a1f1dSLionel Sambuc     void
got_eof(void)140*0a6a1f1dSLionel Sambuc     got_eof(void)
141*0a6a1f1dSLionel Sambuc     {
142*0a6a1f1dSLionel Sambuc         m_calls.push_back("got_eof()");
143*0a6a1f1dSLionel Sambuc     }
144*0a6a1f1dSLionel Sambuc 
145*0a6a1f1dSLionel Sambuc public:
tp_reader(std::istream & is)146*0a6a1f1dSLionel Sambuc     tp_reader(std::istream& is) :
147*0a6a1f1dSLionel Sambuc         detail::atf_tp_reader(is)
148*0a6a1f1dSLionel Sambuc     {
149*0a6a1f1dSLionel Sambuc     }
150*0a6a1f1dSLionel Sambuc 
151*0a6a1f1dSLionel Sambuc     void
read(void)152*0a6a1f1dSLionel Sambuc     read(void)
153*0a6a1f1dSLionel Sambuc     {
154*0a6a1f1dSLionel Sambuc         atf_tp_reader::read();
155*0a6a1f1dSLionel Sambuc     }
156*0a6a1f1dSLionel Sambuc 
157*0a6a1f1dSLionel Sambuc     std::vector< std::string > m_calls;
158*0a6a1f1dSLionel Sambuc };
159*0a6a1f1dSLionel Sambuc 
160*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(tp_1);
ATF_TEST_CASE_BODY(tp_1)161*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(tp_1)
162*0a6a1f1dSLionel Sambuc {
163*0a6a1f1dSLionel Sambuc     const char* input =
164*0a6a1f1dSLionel Sambuc         "Content-Type: application/X-atf-tp; version=\"1\"\n"
165*0a6a1f1dSLionel Sambuc         "\n"
166*0a6a1f1dSLionel Sambuc         "ident: test_case_1\n"
167*0a6a1f1dSLionel Sambuc         "\n"
168*0a6a1f1dSLionel Sambuc         "ident: test_case_2\n"
169*0a6a1f1dSLionel Sambuc         "\n"
170*0a6a1f1dSLionel Sambuc         "ident: test_case_3\n"
171*0a6a1f1dSLionel Sambuc     ;
172*0a6a1f1dSLionel Sambuc 
173*0a6a1f1dSLionel Sambuc     const char* exp_calls[] = {
174*0a6a1f1dSLionel Sambuc         "got_tc(test_case_1, {ident=test_case_1})",
175*0a6a1f1dSLionel Sambuc         "got_tc(test_case_2, {ident=test_case_2})",
176*0a6a1f1dSLionel Sambuc         "got_tc(test_case_3, {ident=test_case_3})",
177*0a6a1f1dSLionel Sambuc         "got_eof()",
178*0a6a1f1dSLionel Sambuc         NULL
179*0a6a1f1dSLionel Sambuc     };
180*0a6a1f1dSLionel Sambuc 
181*0a6a1f1dSLionel Sambuc     const char* exp_errors[] = {
182*0a6a1f1dSLionel Sambuc         NULL
183*0a6a1f1dSLionel Sambuc     };
184*0a6a1f1dSLionel Sambuc 
185*0a6a1f1dSLionel Sambuc     do_parser_test< tp_reader >(input, exp_calls, exp_errors);
186*0a6a1f1dSLionel Sambuc }
187*0a6a1f1dSLionel Sambuc 
188*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(tp_2);
ATF_TEST_CASE_BODY(tp_2)189*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(tp_2)
190*0a6a1f1dSLionel Sambuc {
191*0a6a1f1dSLionel Sambuc     const char* input =
192*0a6a1f1dSLionel Sambuc         "Content-Type: application/X-atf-tp; version=\"1\"\n"
193*0a6a1f1dSLionel Sambuc         "\n"
194*0a6a1f1dSLionel Sambuc         "ident: test_case_1\n"
195*0a6a1f1dSLionel Sambuc         "descr: This is the description\n"
196*0a6a1f1dSLionel Sambuc         "timeout: 300\n"
197*0a6a1f1dSLionel Sambuc         "\n"
198*0a6a1f1dSLionel Sambuc         "ident: test_case_2\n"
199*0a6a1f1dSLionel Sambuc         "\n"
200*0a6a1f1dSLionel Sambuc         "ident: test_case_3\n"
201*0a6a1f1dSLionel Sambuc         "X-prop1: A custom property\n"
202*0a6a1f1dSLionel Sambuc         "descr: Third test case\n"
203*0a6a1f1dSLionel Sambuc     ;
204*0a6a1f1dSLionel Sambuc 
205*0a6a1f1dSLionel Sambuc     // NO_CHECK_STYLE_BEGIN
206*0a6a1f1dSLionel Sambuc     const char* exp_calls[] = {
207*0a6a1f1dSLionel Sambuc         "got_tc(test_case_1, {descr=This is the description, ident=test_case_1, timeout=300})",
208*0a6a1f1dSLionel Sambuc         "got_tc(test_case_2, {ident=test_case_2})",
209*0a6a1f1dSLionel Sambuc         "got_tc(test_case_3, {X-prop1=A custom property, descr=Third test case, ident=test_case_3})",
210*0a6a1f1dSLionel Sambuc         "got_eof()",
211*0a6a1f1dSLionel Sambuc         NULL
212*0a6a1f1dSLionel Sambuc     };
213*0a6a1f1dSLionel Sambuc     // NO_CHECK_STYLE_END
214*0a6a1f1dSLionel Sambuc 
215*0a6a1f1dSLionel Sambuc     const char* exp_errors[] = {
216*0a6a1f1dSLionel Sambuc         NULL
217*0a6a1f1dSLionel Sambuc     };
218*0a6a1f1dSLionel Sambuc 
219*0a6a1f1dSLionel Sambuc     do_parser_test< tp_reader >(input, exp_calls, exp_errors);
220*0a6a1f1dSLionel Sambuc }
221*0a6a1f1dSLionel Sambuc 
222*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(tp_3);
ATF_TEST_CASE_BODY(tp_3)223*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(tp_3)
224*0a6a1f1dSLionel Sambuc {
225*0a6a1f1dSLionel Sambuc     const char* input =
226*0a6a1f1dSLionel Sambuc         "Content-Type: application/X-atf-tp; version=\"1\"\n"
227*0a6a1f1dSLionel Sambuc         "\n"
228*0a6a1f1dSLionel Sambuc         "ident: single_test\n"
229*0a6a1f1dSLionel Sambuc         "descr: Some description\n"
230*0a6a1f1dSLionel Sambuc         "timeout: 300\n"
231*0a6a1f1dSLionel Sambuc         "require.arch: thearch\n"
232*0a6a1f1dSLionel Sambuc         "require.config: foo-bar\n"
233*0a6a1f1dSLionel Sambuc         "require.files: /a/1 /b/2\n"
234*0a6a1f1dSLionel Sambuc         "require.machine: themachine\n"
235*0a6a1f1dSLionel Sambuc         "require.progs: /bin/cp mv\n"
236*0a6a1f1dSLionel Sambuc         "require.user: root\n"
237*0a6a1f1dSLionel Sambuc     ;
238*0a6a1f1dSLionel Sambuc 
239*0a6a1f1dSLionel Sambuc     // NO_CHECK_STYLE_BEGIN
240*0a6a1f1dSLionel Sambuc     const char* exp_calls[] = {
241*0a6a1f1dSLionel Sambuc         "got_tc(single_test, {descr=Some description, ident=single_test, require.arch=thearch, require.config=foo-bar, require.files=/a/1 /b/2, require.machine=themachine, require.progs=/bin/cp mv, require.user=root, timeout=300})",
242*0a6a1f1dSLionel Sambuc         "got_eof()",
243*0a6a1f1dSLionel Sambuc         NULL
244*0a6a1f1dSLionel Sambuc     };
245*0a6a1f1dSLionel Sambuc     // NO_CHECK_STYLE_END
246*0a6a1f1dSLionel Sambuc 
247*0a6a1f1dSLionel Sambuc     const char* exp_errors[] = {
248*0a6a1f1dSLionel Sambuc         NULL
249*0a6a1f1dSLionel Sambuc     };
250*0a6a1f1dSLionel Sambuc 
251*0a6a1f1dSLionel Sambuc     do_parser_test< tp_reader >(input, exp_calls, exp_errors);
252*0a6a1f1dSLionel Sambuc }
253*0a6a1f1dSLionel Sambuc 
254*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(tp_4);
ATF_TEST_CASE_BODY(tp_4)255*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(tp_4)
256*0a6a1f1dSLionel Sambuc {
257*0a6a1f1dSLionel Sambuc     const char* input =
258*0a6a1f1dSLionel Sambuc         "Content-Type: application/X-atf-tp; version=\"1\"\n"
259*0a6a1f1dSLionel Sambuc         "\n"
260*0a6a1f1dSLionel Sambuc         "ident:   single_test    \n"
261*0a6a1f1dSLionel Sambuc         "descr:      Some description	\n"
262*0a6a1f1dSLionel Sambuc     ;
263*0a6a1f1dSLionel Sambuc 
264*0a6a1f1dSLionel Sambuc     const char* exp_calls[] = {
265*0a6a1f1dSLionel Sambuc         "got_tc(single_test, {descr=Some description, ident=single_test})",
266*0a6a1f1dSLionel Sambuc         "got_eof()",
267*0a6a1f1dSLionel Sambuc         NULL
268*0a6a1f1dSLionel Sambuc     };
269*0a6a1f1dSLionel Sambuc 
270*0a6a1f1dSLionel Sambuc     const char* exp_errors[] = {
271*0a6a1f1dSLionel Sambuc         NULL
272*0a6a1f1dSLionel Sambuc     };
273*0a6a1f1dSLionel Sambuc 
274*0a6a1f1dSLionel Sambuc     do_parser_test< tp_reader >(input, exp_calls, exp_errors);
275*0a6a1f1dSLionel Sambuc }
276*0a6a1f1dSLionel Sambuc 
277*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(tp_50);
ATF_TEST_CASE_BODY(tp_50)278*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(tp_50)
279*0a6a1f1dSLionel Sambuc {
280*0a6a1f1dSLionel Sambuc     const char* input =
281*0a6a1f1dSLionel Sambuc         "Content-Type: application/X-atf-tp; version=\"1\"\n"
282*0a6a1f1dSLionel Sambuc         "\n"
283*0a6a1f1dSLionel Sambuc     ;
284*0a6a1f1dSLionel Sambuc 
285*0a6a1f1dSLionel Sambuc     const char* exp_calls[] = {
286*0a6a1f1dSLionel Sambuc         NULL
287*0a6a1f1dSLionel Sambuc     };
288*0a6a1f1dSLionel Sambuc 
289*0a6a1f1dSLionel Sambuc     const char* exp_errors[] = {
290*0a6a1f1dSLionel Sambuc         "3: Unexpected token `<<EOF>>'; expected property name",
291*0a6a1f1dSLionel Sambuc         NULL
292*0a6a1f1dSLionel Sambuc     };
293*0a6a1f1dSLionel Sambuc 
294*0a6a1f1dSLionel Sambuc     do_parser_test< tp_reader >(input, exp_calls, exp_errors);
295*0a6a1f1dSLionel Sambuc }
296*0a6a1f1dSLionel Sambuc 
297*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(tp_51);
ATF_TEST_CASE_BODY(tp_51)298*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(tp_51)
299*0a6a1f1dSLionel Sambuc {
300*0a6a1f1dSLionel Sambuc     const char* input =
301*0a6a1f1dSLionel Sambuc         "Content-Type: application/X-atf-tp; version=\"1\"\n"
302*0a6a1f1dSLionel Sambuc         "\n"
303*0a6a1f1dSLionel Sambuc         "\n"
304*0a6a1f1dSLionel Sambuc         "\n"
305*0a6a1f1dSLionel Sambuc         "\n"
306*0a6a1f1dSLionel Sambuc     ;
307*0a6a1f1dSLionel Sambuc 
308*0a6a1f1dSLionel Sambuc     const char* exp_calls[] = {
309*0a6a1f1dSLionel Sambuc         NULL
310*0a6a1f1dSLionel Sambuc     };
311*0a6a1f1dSLionel Sambuc 
312*0a6a1f1dSLionel Sambuc     const char* exp_errors[] = {
313*0a6a1f1dSLionel Sambuc         "3: Unexpected token `<<NEWLINE>>'; expected property name",
314*0a6a1f1dSLionel Sambuc         NULL
315*0a6a1f1dSLionel Sambuc     };
316*0a6a1f1dSLionel Sambuc 
317*0a6a1f1dSLionel Sambuc     do_parser_test< tp_reader >(input, exp_calls, exp_errors);
318*0a6a1f1dSLionel Sambuc }
319*0a6a1f1dSLionel Sambuc 
320*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(tp_52);
ATF_TEST_CASE_BODY(tp_52)321*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(tp_52)
322*0a6a1f1dSLionel Sambuc {
323*0a6a1f1dSLionel Sambuc     const char* input =
324*0a6a1f1dSLionel Sambuc         "Content-Type: application/X-atf-tp; version=\"1\"\n"
325*0a6a1f1dSLionel Sambuc         "\n"
326*0a6a1f1dSLionel Sambuc         "ident: test1\n"
327*0a6a1f1dSLionel Sambuc         "ident: test2\n"
328*0a6a1f1dSLionel Sambuc     ;
329*0a6a1f1dSLionel Sambuc 
330*0a6a1f1dSLionel Sambuc     const char* exp_calls[] = {
331*0a6a1f1dSLionel Sambuc         "got_tc(test1, {ident=test1})",
332*0a6a1f1dSLionel Sambuc         "got_eof()",
333*0a6a1f1dSLionel Sambuc         NULL
334*0a6a1f1dSLionel Sambuc     };
335*0a6a1f1dSLionel Sambuc 
336*0a6a1f1dSLionel Sambuc     const char* exp_errors[] = {
337*0a6a1f1dSLionel Sambuc         NULL
338*0a6a1f1dSLionel Sambuc     };
339*0a6a1f1dSLionel Sambuc 
340*0a6a1f1dSLionel Sambuc     do_parser_test< tp_reader >(input, exp_calls, exp_errors);
341*0a6a1f1dSLionel Sambuc }
342*0a6a1f1dSLionel Sambuc 
343*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(tp_53);
ATF_TEST_CASE_BODY(tp_53)344*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(tp_53)
345*0a6a1f1dSLionel Sambuc {
346*0a6a1f1dSLionel Sambuc     const char* input =
347*0a6a1f1dSLionel Sambuc         "Content-Type: application/X-atf-tp; version=\"1\"\n"
348*0a6a1f1dSLionel Sambuc         "\n"
349*0a6a1f1dSLionel Sambuc         "descr: Out of order\n"
350*0a6a1f1dSLionel Sambuc         "ident: test1\n"
351*0a6a1f1dSLionel Sambuc     ;
352*0a6a1f1dSLionel Sambuc 
353*0a6a1f1dSLionel Sambuc     const char* exp_calls[] = {
354*0a6a1f1dSLionel Sambuc         NULL
355*0a6a1f1dSLionel Sambuc     };
356*0a6a1f1dSLionel Sambuc 
357*0a6a1f1dSLionel Sambuc     const char* exp_errors[] = {
358*0a6a1f1dSLionel Sambuc         "3: First property of a test case must be 'ident'",
359*0a6a1f1dSLionel Sambuc         NULL
360*0a6a1f1dSLionel Sambuc     };
361*0a6a1f1dSLionel Sambuc 
362*0a6a1f1dSLionel Sambuc     do_parser_test< tp_reader >(input, exp_calls, exp_errors);
363*0a6a1f1dSLionel Sambuc }
364*0a6a1f1dSLionel Sambuc 
365*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(tp_54);
ATF_TEST_CASE_BODY(tp_54)366*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(tp_54)
367*0a6a1f1dSLionel Sambuc {
368*0a6a1f1dSLionel Sambuc     const char* input =
369*0a6a1f1dSLionel Sambuc         "Content-Type: application/X-atf-tp; version=\"1\"\n"
370*0a6a1f1dSLionel Sambuc         "\n"
371*0a6a1f1dSLionel Sambuc         "ident:\n"
372*0a6a1f1dSLionel Sambuc     ;
373*0a6a1f1dSLionel Sambuc 
374*0a6a1f1dSLionel Sambuc     const char* exp_calls[] = {
375*0a6a1f1dSLionel Sambuc         NULL
376*0a6a1f1dSLionel Sambuc     };
377*0a6a1f1dSLionel Sambuc 
378*0a6a1f1dSLionel Sambuc     const char* exp_errors[] = {
379*0a6a1f1dSLionel Sambuc         "3: The value for 'ident' cannot be empty",
380*0a6a1f1dSLionel Sambuc         NULL
381*0a6a1f1dSLionel Sambuc     };
382*0a6a1f1dSLionel Sambuc 
383*0a6a1f1dSLionel Sambuc     do_parser_test< tp_reader >(input, exp_calls, exp_errors);
384*0a6a1f1dSLionel Sambuc }
385*0a6a1f1dSLionel Sambuc 
386*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(tp_55);
ATF_TEST_CASE_BODY(tp_55)387*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(tp_55)
388*0a6a1f1dSLionel Sambuc {
389*0a6a1f1dSLionel Sambuc     const char* input =
390*0a6a1f1dSLionel Sambuc         "Content-Type: application/X-atf-tp; version=\"1\"\n"
391*0a6a1f1dSLionel Sambuc         "\n"
392*0a6a1f1dSLionel Sambuc         "ident: +*,\n"
393*0a6a1f1dSLionel Sambuc     ;
394*0a6a1f1dSLionel Sambuc 
395*0a6a1f1dSLionel Sambuc     const char* exp_calls[] = {
396*0a6a1f1dSLionel Sambuc         NULL
397*0a6a1f1dSLionel Sambuc     };
398*0a6a1f1dSLionel Sambuc 
399*0a6a1f1dSLionel Sambuc     const char* exp_errors[] = {
400*0a6a1f1dSLionel Sambuc         "3: The identifier must match ^[_A-Za-z0-9]+$; was '+*,'",
401*0a6a1f1dSLionel Sambuc         NULL
402*0a6a1f1dSLionel Sambuc     };
403*0a6a1f1dSLionel Sambuc 
404*0a6a1f1dSLionel Sambuc     do_parser_test< tp_reader >(input, exp_calls, exp_errors);
405*0a6a1f1dSLionel Sambuc }
406*0a6a1f1dSLionel Sambuc 
407*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(tp_56);
ATF_TEST_CASE_BODY(tp_56)408*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(tp_56)
409*0a6a1f1dSLionel Sambuc {
410*0a6a1f1dSLionel Sambuc     const char* input =
411*0a6a1f1dSLionel Sambuc         "Content-Type: application/X-atf-tp; version=\"1\"\n"
412*0a6a1f1dSLionel Sambuc         "\n"
413*0a6a1f1dSLionel Sambuc         "ident: test\n"
414*0a6a1f1dSLionel Sambuc         "timeout: hello\n"
415*0a6a1f1dSLionel Sambuc     ;
416*0a6a1f1dSLionel Sambuc 
417*0a6a1f1dSLionel Sambuc     const char* exp_calls[] = {
418*0a6a1f1dSLionel Sambuc         NULL
419*0a6a1f1dSLionel Sambuc     };
420*0a6a1f1dSLionel Sambuc 
421*0a6a1f1dSLionel Sambuc     const char* exp_errors[] = {
422*0a6a1f1dSLionel Sambuc         "4: The timeout property requires an integer value",
423*0a6a1f1dSLionel Sambuc         NULL
424*0a6a1f1dSLionel Sambuc     };
425*0a6a1f1dSLionel Sambuc 
426*0a6a1f1dSLionel Sambuc     do_parser_test< tp_reader >(input, exp_calls, exp_errors);
427*0a6a1f1dSLionel Sambuc }
428*0a6a1f1dSLionel Sambuc 
429*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(tp_57);
ATF_TEST_CASE_BODY(tp_57)430*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(tp_57)
431*0a6a1f1dSLionel Sambuc {
432*0a6a1f1dSLionel Sambuc     const char* input =
433*0a6a1f1dSLionel Sambuc         "Content-Type: application/X-atf-tp; version=\"1\"\n"
434*0a6a1f1dSLionel Sambuc         "\n"
435*0a6a1f1dSLionel Sambuc         "ident: test\n"
436*0a6a1f1dSLionel Sambuc         "unknown: property\n"
437*0a6a1f1dSLionel Sambuc     ;
438*0a6a1f1dSLionel Sambuc 
439*0a6a1f1dSLionel Sambuc     const char* exp_calls[] = {
440*0a6a1f1dSLionel Sambuc         NULL
441*0a6a1f1dSLionel Sambuc     };
442*0a6a1f1dSLionel Sambuc 
443*0a6a1f1dSLionel Sambuc     const char* exp_errors[] = {
444*0a6a1f1dSLionel Sambuc         "4: Unknown property 'unknown'",
445*0a6a1f1dSLionel Sambuc         NULL
446*0a6a1f1dSLionel Sambuc     };
447*0a6a1f1dSLionel Sambuc 
448*0a6a1f1dSLionel Sambuc     do_parser_test< tp_reader >(input, exp_calls, exp_errors);
449*0a6a1f1dSLionel Sambuc }
450*0a6a1f1dSLionel Sambuc 
451*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(tp_58);
ATF_TEST_CASE_BODY(tp_58)452*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(tp_58)
453*0a6a1f1dSLionel Sambuc {
454*0a6a1f1dSLionel Sambuc     const char* input =
455*0a6a1f1dSLionel Sambuc         "Content-Type: application/X-atf-tp; version=\"1\"\n"
456*0a6a1f1dSLionel Sambuc         "\n"
457*0a6a1f1dSLionel Sambuc         "ident: test\n"
458*0a6a1f1dSLionel Sambuc         "X-foo:\n"
459*0a6a1f1dSLionel Sambuc     ;
460*0a6a1f1dSLionel Sambuc 
461*0a6a1f1dSLionel Sambuc     const char* exp_calls[] = {
462*0a6a1f1dSLionel Sambuc         NULL
463*0a6a1f1dSLionel Sambuc     };
464*0a6a1f1dSLionel Sambuc 
465*0a6a1f1dSLionel Sambuc     const char* exp_errors[] = {
466*0a6a1f1dSLionel Sambuc         "4: The value for 'X-foo' cannot be empty",
467*0a6a1f1dSLionel Sambuc         NULL
468*0a6a1f1dSLionel Sambuc     };
469*0a6a1f1dSLionel Sambuc 
470*0a6a1f1dSLionel Sambuc     do_parser_test< tp_reader >(input, exp_calls, exp_errors);
471*0a6a1f1dSLionel Sambuc }
472*0a6a1f1dSLionel Sambuc 
473*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(tp_59);
ATF_TEST_CASE_BODY(tp_59)474*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(tp_59)
475*0a6a1f1dSLionel Sambuc {
476*0a6a1f1dSLionel Sambuc     const char* input =
477*0a6a1f1dSLionel Sambuc         "Content-Type: application/X-atf-tp; version=\"1\"\n"
478*0a6a1f1dSLionel Sambuc         "\n"
479*0a6a1f1dSLionel Sambuc         "\n"
480*0a6a1f1dSLionel Sambuc         "ident: test\n"
481*0a6a1f1dSLionel Sambuc         "timeout: 300\n"
482*0a6a1f1dSLionel Sambuc     ;
483*0a6a1f1dSLionel Sambuc 
484*0a6a1f1dSLionel Sambuc     const char* exp_calls[] = {
485*0a6a1f1dSLionel Sambuc         NULL
486*0a6a1f1dSLionel Sambuc     };
487*0a6a1f1dSLionel Sambuc 
488*0a6a1f1dSLionel Sambuc     const char* exp_errors[] = {
489*0a6a1f1dSLionel Sambuc         "3: Unexpected token `<<NEWLINE>>'; expected property name",
490*0a6a1f1dSLionel Sambuc         NULL
491*0a6a1f1dSLionel Sambuc     };
492*0a6a1f1dSLionel Sambuc 
493*0a6a1f1dSLionel Sambuc     do_parser_test< tp_reader >(input, exp_calls, exp_errors);
494*0a6a1f1dSLionel Sambuc }
495*0a6a1f1dSLionel Sambuc 
496*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(tp_60);
ATF_TEST_CASE_BODY(tp_60)497*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(tp_60)
498*0a6a1f1dSLionel Sambuc {
499*0a6a1f1dSLionel Sambuc     const char* input =
500*0a6a1f1dSLionel Sambuc         "Content-Type: application/X-atf-tp; version=\"1\"\n"
501*0a6a1f1dSLionel Sambuc         "\n"
502*0a6a1f1dSLionel Sambuc         "ident: test\n"
503*0a6a1f1dSLionel Sambuc         "require.memory: 12345D\n"
504*0a6a1f1dSLionel Sambuc     ;
505*0a6a1f1dSLionel Sambuc 
506*0a6a1f1dSLionel Sambuc     const char* exp_calls[] = {
507*0a6a1f1dSLionel Sambuc         NULL
508*0a6a1f1dSLionel Sambuc     };
509*0a6a1f1dSLionel Sambuc 
510*0a6a1f1dSLionel Sambuc     const char* exp_errors[] = {
511*0a6a1f1dSLionel Sambuc         "4: The require.memory property requires an integer value representing"
512*0a6a1f1dSLionel Sambuc         " an amount of bytes",
513*0a6a1f1dSLionel Sambuc         NULL
514*0a6a1f1dSLionel Sambuc     };
515*0a6a1f1dSLionel Sambuc 
516*0a6a1f1dSLionel Sambuc     do_parser_test< tp_reader >(input, exp_calls, exp_errors);
517*0a6a1f1dSLionel Sambuc }
518*0a6a1f1dSLionel Sambuc 
519*0a6a1f1dSLionel Sambuc // -------------------------------------------------------------------------
520*0a6a1f1dSLionel Sambuc // Tests for the "tps" writer.
521*0a6a1f1dSLionel Sambuc // -------------------------------------------------------------------------
522*0a6a1f1dSLionel Sambuc 
523*0a6a1f1dSLionel Sambuc ATF_TEST_CASE(atf_tps_writer);
ATF_TEST_CASE_HEAD(atf_tps_writer)524*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_HEAD(atf_tps_writer)
525*0a6a1f1dSLionel Sambuc {
526*0a6a1f1dSLionel Sambuc     set_md_var("descr", "Verifies the application/X-atf-tps writer");
527*0a6a1f1dSLionel Sambuc }
ATF_TEST_CASE_BODY(atf_tps_writer)528*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(atf_tps_writer)
529*0a6a1f1dSLionel Sambuc {
530*0a6a1f1dSLionel Sambuc     std::ostringstream expss;
531*0a6a1f1dSLionel Sambuc     std::ostringstream ss;
532*0a6a1f1dSLionel Sambuc     const char *ts_regex = "[0-9]+\\.[0-9]{1,6}, ";
533*0a6a1f1dSLionel Sambuc 
534*0a6a1f1dSLionel Sambuc #define RESET \
535*0a6a1f1dSLionel Sambuc     expss.str(""); \
536*0a6a1f1dSLionel Sambuc     ss.str("")
537*0a6a1f1dSLionel Sambuc 
538*0a6a1f1dSLionel Sambuc #define CHECK \
539*0a6a1f1dSLionel Sambuc     check_match(*this, ss.str(), expss.str())
540*0a6a1f1dSLionel Sambuc 
541*0a6a1f1dSLionel Sambuc     {
542*0a6a1f1dSLionel Sambuc         RESET;
543*0a6a1f1dSLionel Sambuc 
544*0a6a1f1dSLionel Sambuc         impl::atf_tps_writer w(ss);
545*0a6a1f1dSLionel Sambuc         expss << "Content-Type: application/X-atf-tps; version=\"3\"\n\n";
546*0a6a1f1dSLionel Sambuc         CHECK;
547*0a6a1f1dSLionel Sambuc     }
548*0a6a1f1dSLionel Sambuc 
549*0a6a1f1dSLionel Sambuc     {
550*0a6a1f1dSLionel Sambuc         RESET;
551*0a6a1f1dSLionel Sambuc 
552*0a6a1f1dSLionel Sambuc         impl::atf_tps_writer w(ss);
553*0a6a1f1dSLionel Sambuc         expss << "Content-Type: application/X-atf-tps; version=\"3\"\n\n";
554*0a6a1f1dSLionel Sambuc         CHECK;
555*0a6a1f1dSLionel Sambuc 
556*0a6a1f1dSLionel Sambuc         w.info("foo", "bar");
557*0a6a1f1dSLionel Sambuc         expss << "info: foo, bar\n";
558*0a6a1f1dSLionel Sambuc         CHECK;
559*0a6a1f1dSLionel Sambuc 
560*0a6a1f1dSLionel Sambuc         w.info("baz", "second info");
561*0a6a1f1dSLionel Sambuc         expss << "info: baz, second info\n";
562*0a6a1f1dSLionel Sambuc         CHECK;
563*0a6a1f1dSLionel Sambuc     }
564*0a6a1f1dSLionel Sambuc 
565*0a6a1f1dSLionel Sambuc     {
566*0a6a1f1dSLionel Sambuc         RESET;
567*0a6a1f1dSLionel Sambuc 
568*0a6a1f1dSLionel Sambuc         impl::atf_tps_writer w(ss);
569*0a6a1f1dSLionel Sambuc         expss << "Content-Type: application/X-atf-tps; version=\"3\"\n\n";
570*0a6a1f1dSLionel Sambuc         CHECK;
571*0a6a1f1dSLionel Sambuc 
572*0a6a1f1dSLionel Sambuc         w.ntps(0);
573*0a6a1f1dSLionel Sambuc         expss << "tps-count: 0\n";
574*0a6a1f1dSLionel Sambuc         CHECK;
575*0a6a1f1dSLionel Sambuc     }
576*0a6a1f1dSLionel Sambuc 
577*0a6a1f1dSLionel Sambuc     {
578*0a6a1f1dSLionel Sambuc         RESET;
579*0a6a1f1dSLionel Sambuc 
580*0a6a1f1dSLionel Sambuc         impl::atf_tps_writer w(ss);
581*0a6a1f1dSLionel Sambuc         expss << "Content-Type: application/X-atf-tps; version=\"3\"\n\n";
582*0a6a1f1dSLionel Sambuc         CHECK;
583*0a6a1f1dSLionel Sambuc 
584*0a6a1f1dSLionel Sambuc         w.ntps(123);
585*0a6a1f1dSLionel Sambuc         expss << "tps-count: 123\n";
586*0a6a1f1dSLionel Sambuc         CHECK;
587*0a6a1f1dSLionel Sambuc     }
588*0a6a1f1dSLionel Sambuc 
589*0a6a1f1dSLionel Sambuc     {
590*0a6a1f1dSLionel Sambuc         RESET;
591*0a6a1f1dSLionel Sambuc 
592*0a6a1f1dSLionel Sambuc         impl::atf_tps_writer w(ss);
593*0a6a1f1dSLionel Sambuc         expss << "Content-Type: application/X-atf-tps; version=\"3\"\n\n";
594*0a6a1f1dSLionel Sambuc         CHECK;
595*0a6a1f1dSLionel Sambuc 
596*0a6a1f1dSLionel Sambuc         w.ntps(2);
597*0a6a1f1dSLionel Sambuc         expss << "tps-count: 2\n";
598*0a6a1f1dSLionel Sambuc         CHECK;
599*0a6a1f1dSLionel Sambuc 
600*0a6a1f1dSLionel Sambuc         w.start_tp("foo", 0);
601*0a6a1f1dSLionel Sambuc         expss << "tp-start: " << ts_regex << "foo, 0\n";
602*0a6a1f1dSLionel Sambuc         CHECK;
603*0a6a1f1dSLionel Sambuc 
604*0a6a1f1dSLionel Sambuc         w.end_tp("");
605*0a6a1f1dSLionel Sambuc         expss << "tp-end: " << ts_regex << "foo\n";
606*0a6a1f1dSLionel Sambuc         CHECK;
607*0a6a1f1dSLionel Sambuc 
608*0a6a1f1dSLionel Sambuc         w.start_tp("bar", 0);
609*0a6a1f1dSLionel Sambuc         expss << "tp-start: " << ts_regex << "bar, 0\n";
610*0a6a1f1dSLionel Sambuc         CHECK;
611*0a6a1f1dSLionel Sambuc 
612*0a6a1f1dSLionel Sambuc         w.end_tp("failed program");
613*0a6a1f1dSLionel Sambuc         expss << "tp-end: " << ts_regex << "bar, failed program\n";
614*0a6a1f1dSLionel Sambuc         CHECK;
615*0a6a1f1dSLionel Sambuc     }
616*0a6a1f1dSLionel Sambuc 
617*0a6a1f1dSLionel Sambuc     {
618*0a6a1f1dSLionel Sambuc         RESET;
619*0a6a1f1dSLionel Sambuc 
620*0a6a1f1dSLionel Sambuc         impl::atf_tps_writer w(ss);
621*0a6a1f1dSLionel Sambuc         expss << "Content-Type: application/X-atf-tps; version=\"3\"\n\n";
622*0a6a1f1dSLionel Sambuc         CHECK;
623*0a6a1f1dSLionel Sambuc 
624*0a6a1f1dSLionel Sambuc         w.ntps(1);
625*0a6a1f1dSLionel Sambuc         expss << "tps-count: 1\n";
626*0a6a1f1dSLionel Sambuc         CHECK;
627*0a6a1f1dSLionel Sambuc 
628*0a6a1f1dSLionel Sambuc         w.start_tp("foo", 1);
629*0a6a1f1dSLionel Sambuc         expss << "tp-start: " << ts_regex << "foo, 1\n";
630*0a6a1f1dSLionel Sambuc         CHECK;
631*0a6a1f1dSLionel Sambuc 
632*0a6a1f1dSLionel Sambuc         w.start_tc("brokentc");
633*0a6a1f1dSLionel Sambuc         expss << "tc-start: " << ts_regex << "brokentc\n";
634*0a6a1f1dSLionel Sambuc         CHECK;
635*0a6a1f1dSLionel Sambuc 
636*0a6a1f1dSLionel Sambuc         w.end_tp("aborted");
637*0a6a1f1dSLionel Sambuc         expss << "tp-end: " << ts_regex << "foo, aborted\n";
638*0a6a1f1dSLionel Sambuc         CHECK;
639*0a6a1f1dSLionel Sambuc     }
640*0a6a1f1dSLionel Sambuc 
641*0a6a1f1dSLionel Sambuc     {
642*0a6a1f1dSLionel Sambuc         RESET;
643*0a6a1f1dSLionel Sambuc 
644*0a6a1f1dSLionel Sambuc         impl::atf_tps_writer w(ss);
645*0a6a1f1dSLionel Sambuc         expss << "Content-Type: application/X-atf-tps; version=\"3\"\n\n";
646*0a6a1f1dSLionel Sambuc         CHECK;
647*0a6a1f1dSLionel Sambuc 
648*0a6a1f1dSLionel Sambuc         w.ntps(1);
649*0a6a1f1dSLionel Sambuc         expss << "tps-count: 1\n";
650*0a6a1f1dSLionel Sambuc         CHECK;
651*0a6a1f1dSLionel Sambuc 
652*0a6a1f1dSLionel Sambuc         w.start_tp("thetp", 3);
653*0a6a1f1dSLionel Sambuc         expss << "tp-start: " << ts_regex << "thetp, 3\n";
654*0a6a1f1dSLionel Sambuc         CHECK;
655*0a6a1f1dSLionel Sambuc 
656*0a6a1f1dSLionel Sambuc         w.start_tc("passtc");
657*0a6a1f1dSLionel Sambuc         expss << "tc-start: " << ts_regex << "passtc\n";
658*0a6a1f1dSLionel Sambuc         CHECK;
659*0a6a1f1dSLionel Sambuc 
660*0a6a1f1dSLionel Sambuc         w.end_tc("passed", "");
661*0a6a1f1dSLionel Sambuc         expss << "tc-end: " << ts_regex << "passtc, passed\n";
662*0a6a1f1dSLionel Sambuc         CHECK;
663*0a6a1f1dSLionel Sambuc 
664*0a6a1f1dSLionel Sambuc         w.start_tc("failtc");
665*0a6a1f1dSLionel Sambuc         expss << "tc-start: " << ts_regex << "failtc\n";
666*0a6a1f1dSLionel Sambuc         CHECK;
667*0a6a1f1dSLionel Sambuc 
668*0a6a1f1dSLionel Sambuc         w.end_tc("failed", "The reason");
669*0a6a1f1dSLionel Sambuc         expss << "tc-end: " << ts_regex << "failtc, failed, The reason\n";
670*0a6a1f1dSLionel Sambuc         CHECK;
671*0a6a1f1dSLionel Sambuc 
672*0a6a1f1dSLionel Sambuc         w.start_tc("skiptc");
673*0a6a1f1dSLionel Sambuc         expss << "tc-start: " << ts_regex << "skiptc\n";
674*0a6a1f1dSLionel Sambuc         CHECK;
675*0a6a1f1dSLionel Sambuc 
676*0a6a1f1dSLionel Sambuc         w.end_tc("skipped", "The reason");
677*0a6a1f1dSLionel Sambuc         expss << "tc-end: " << ts_regex << "skiptc, skipped, The reason\n";
678*0a6a1f1dSLionel Sambuc         CHECK;
679*0a6a1f1dSLionel Sambuc 
680*0a6a1f1dSLionel Sambuc         w.end_tp("");
681*0a6a1f1dSLionel Sambuc         expss << "tp-end: " << ts_regex << "thetp\n";
682*0a6a1f1dSLionel Sambuc         CHECK;
683*0a6a1f1dSLionel Sambuc     }
684*0a6a1f1dSLionel Sambuc 
685*0a6a1f1dSLionel Sambuc     {
686*0a6a1f1dSLionel Sambuc         RESET;
687*0a6a1f1dSLionel Sambuc 
688*0a6a1f1dSLionel Sambuc         impl::atf_tps_writer w(ss);
689*0a6a1f1dSLionel Sambuc         expss << "Content-Type: application/X-atf-tps; version=\"3\"\n\n";
690*0a6a1f1dSLionel Sambuc         CHECK;
691*0a6a1f1dSLionel Sambuc 
692*0a6a1f1dSLionel Sambuc         w.ntps(1);
693*0a6a1f1dSLionel Sambuc         expss << "tps-count: 1\n";
694*0a6a1f1dSLionel Sambuc         CHECK;
695*0a6a1f1dSLionel Sambuc 
696*0a6a1f1dSLionel Sambuc         w.start_tp("thetp", 1);
697*0a6a1f1dSLionel Sambuc         expss << "tp-start: " << ts_regex << "thetp, 1\n";
698*0a6a1f1dSLionel Sambuc         CHECK;
699*0a6a1f1dSLionel Sambuc 
700*0a6a1f1dSLionel Sambuc         w.start_tc("thetc");
701*0a6a1f1dSLionel Sambuc         expss << "tc-start: " << ts_regex << "thetc\n";
702*0a6a1f1dSLionel Sambuc         CHECK;
703*0a6a1f1dSLionel Sambuc 
704*0a6a1f1dSLionel Sambuc         w.stdout_tc("a line");
705*0a6a1f1dSLionel Sambuc         expss << "tc-so:a line\n";
706*0a6a1f1dSLionel Sambuc         CHECK;
707*0a6a1f1dSLionel Sambuc 
708*0a6a1f1dSLionel Sambuc         w.stdout_tc("another line");
709*0a6a1f1dSLionel Sambuc         expss << "tc-so:another line\n";
710*0a6a1f1dSLionel Sambuc         CHECK;
711*0a6a1f1dSLionel Sambuc 
712*0a6a1f1dSLionel Sambuc         w.stderr_tc("an error message");
713*0a6a1f1dSLionel Sambuc         expss << "tc-se:an error message\n";
714*0a6a1f1dSLionel Sambuc         CHECK;
715*0a6a1f1dSLionel Sambuc 
716*0a6a1f1dSLionel Sambuc         w.end_tc("passed", "");
717*0a6a1f1dSLionel Sambuc         expss << "tc-end: " << ts_regex << "thetc, passed\n";
718*0a6a1f1dSLionel Sambuc         CHECK;
719*0a6a1f1dSLionel Sambuc 
720*0a6a1f1dSLionel Sambuc         w.end_tp("");
721*0a6a1f1dSLionel Sambuc         expss << "tp-end: " << ts_regex << "thetp\n";
722*0a6a1f1dSLionel Sambuc         CHECK;
723*0a6a1f1dSLionel Sambuc     }
724*0a6a1f1dSLionel Sambuc 
725*0a6a1f1dSLionel Sambuc     {
726*0a6a1f1dSLionel Sambuc         RESET;
727*0a6a1f1dSLionel Sambuc 
728*0a6a1f1dSLionel Sambuc         impl::atf_tps_writer w(ss);
729*0a6a1f1dSLionel Sambuc         expss << "Content-Type: application/X-atf-tps; version=\"3\"\n\n";
730*0a6a1f1dSLionel Sambuc         CHECK;
731*0a6a1f1dSLionel Sambuc 
732*0a6a1f1dSLionel Sambuc         w.ntps(1);
733*0a6a1f1dSLionel Sambuc         expss << "tps-count: 1\n";
734*0a6a1f1dSLionel Sambuc         CHECK;
735*0a6a1f1dSLionel Sambuc 
736*0a6a1f1dSLionel Sambuc         w.start_tp("thetp", 0);
737*0a6a1f1dSLionel Sambuc         expss << "tp-start: " << ts_regex << "thetp, 0\n";
738*0a6a1f1dSLionel Sambuc         CHECK;
739*0a6a1f1dSLionel Sambuc 
740*0a6a1f1dSLionel Sambuc         w.end_tp("");
741*0a6a1f1dSLionel Sambuc         expss << "tp-end: " << ts_regex << "thetp\n";
742*0a6a1f1dSLionel Sambuc         CHECK;
743*0a6a1f1dSLionel Sambuc 
744*0a6a1f1dSLionel Sambuc         w.info("foo", "bar");
745*0a6a1f1dSLionel Sambuc         expss << "info: foo, bar\n";
746*0a6a1f1dSLionel Sambuc         CHECK;
747*0a6a1f1dSLionel Sambuc 
748*0a6a1f1dSLionel Sambuc         w.info("baz", "second value");
749*0a6a1f1dSLionel Sambuc         expss << "info: baz, second value\n";
750*0a6a1f1dSLionel Sambuc         CHECK;
751*0a6a1f1dSLionel Sambuc     }
752*0a6a1f1dSLionel Sambuc 
753*0a6a1f1dSLionel Sambuc #undef CHECK
754*0a6a1f1dSLionel Sambuc #undef RESET
755*0a6a1f1dSLionel Sambuc }
756*0a6a1f1dSLionel Sambuc 
757*0a6a1f1dSLionel Sambuc // -------------------------------------------------------------------------
758*0a6a1f1dSLionel Sambuc // Tests for the free functions.
759*0a6a1f1dSLionel Sambuc // -------------------------------------------------------------------------
760*0a6a1f1dSLionel Sambuc 
761*0a6a1f1dSLionel Sambuc ATF_TEST_CASE(get_metadata_bad);
ATF_TEST_CASE_HEAD(get_metadata_bad)762*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_HEAD(get_metadata_bad) {}
ATF_TEST_CASE_BODY(get_metadata_bad)763*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(get_metadata_bad) {
764*0a6a1f1dSLionel Sambuc     const tools::fs::path executable = get_helper(*this, "bad_metadata_helper");
765*0a6a1f1dSLionel Sambuc     ATF_REQUIRE_THROW(tools::parser::parse_errors,
766*0a6a1f1dSLionel Sambuc                       impl::get_metadata(executable, vars_map()));
767*0a6a1f1dSLionel Sambuc }
768*0a6a1f1dSLionel Sambuc 
769*0a6a1f1dSLionel Sambuc ATF_TEST_CASE(get_metadata_zero_tcs);
ATF_TEST_CASE_HEAD(get_metadata_zero_tcs)770*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_HEAD(get_metadata_zero_tcs) {}
ATF_TEST_CASE_BODY(get_metadata_zero_tcs)771*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(get_metadata_zero_tcs) {
772*0a6a1f1dSLionel Sambuc     const tools::fs::path executable = get_helper(*this, "zero_tcs_helper");
773*0a6a1f1dSLionel Sambuc     ATF_REQUIRE_THROW(tools::parser::parse_errors,
774*0a6a1f1dSLionel Sambuc                       impl::get_metadata(executable, vars_map()));
775*0a6a1f1dSLionel Sambuc }
776*0a6a1f1dSLionel Sambuc 
777*0a6a1f1dSLionel Sambuc ATF_TEST_CASE(get_metadata_several_tcs);
ATF_TEST_CASE_HEAD(get_metadata_several_tcs)778*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_HEAD(get_metadata_several_tcs) {}
ATF_TEST_CASE_BODY(get_metadata_several_tcs)779*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(get_metadata_several_tcs) {
780*0a6a1f1dSLionel Sambuc     const tools::fs::path executable = get_helper(*this, "several_tcs_helper");
781*0a6a1f1dSLionel Sambuc     const impl::metadata md = impl::get_metadata(executable, vars_map());
782*0a6a1f1dSLionel Sambuc     ATF_REQUIRE_EQ(3, md.test_cases.size());
783*0a6a1f1dSLionel Sambuc 
784*0a6a1f1dSLionel Sambuc     {
785*0a6a1f1dSLionel Sambuc         const impl::test_cases_map::const_iterator iter =
786*0a6a1f1dSLionel Sambuc             md.test_cases.find("first");
787*0a6a1f1dSLionel Sambuc         ATF_REQUIRE(iter != md.test_cases.end());
788*0a6a1f1dSLionel Sambuc 
789*0a6a1f1dSLionel Sambuc         ATF_REQUIRE_EQ(4, (*iter).second.size());
790*0a6a1f1dSLionel Sambuc         check_property((*iter).second, "descr", "Description 1");
791*0a6a1f1dSLionel Sambuc         check_property((*iter).second, "has.cleanup", "false");
792*0a6a1f1dSLionel Sambuc         check_property((*iter).second, "ident", "first");
793*0a6a1f1dSLionel Sambuc         check_property((*iter).second, "timeout", "300");
794*0a6a1f1dSLionel Sambuc     }
795*0a6a1f1dSLionel Sambuc 
796*0a6a1f1dSLionel Sambuc     {
797*0a6a1f1dSLionel Sambuc         const impl::test_cases_map::const_iterator iter =
798*0a6a1f1dSLionel Sambuc             md.test_cases.find("second");
799*0a6a1f1dSLionel Sambuc         ATF_REQUIRE(iter != md.test_cases.end());
800*0a6a1f1dSLionel Sambuc 
801*0a6a1f1dSLionel Sambuc         ATF_REQUIRE_EQ(5, (*iter).second.size());
802*0a6a1f1dSLionel Sambuc         check_property((*iter).second, "descr", "Description 2");
803*0a6a1f1dSLionel Sambuc         check_property((*iter).second, "has.cleanup", "true");
804*0a6a1f1dSLionel Sambuc         check_property((*iter).second, "ident", "second");
805*0a6a1f1dSLionel Sambuc         check_property((*iter).second, "timeout", "500");
806*0a6a1f1dSLionel Sambuc         check_property((*iter).second, "X-property", "Custom property");
807*0a6a1f1dSLionel Sambuc     }
808*0a6a1f1dSLionel Sambuc 
809*0a6a1f1dSLionel Sambuc     {
810*0a6a1f1dSLionel Sambuc         const impl::test_cases_map::const_iterator iter =
811*0a6a1f1dSLionel Sambuc             md.test_cases.find("third");
812*0a6a1f1dSLionel Sambuc         ATF_REQUIRE(iter != md.test_cases.end());
813*0a6a1f1dSLionel Sambuc 
814*0a6a1f1dSLionel Sambuc         ATF_REQUIRE_EQ(3, (*iter).second.size());
815*0a6a1f1dSLionel Sambuc         check_property((*iter).second, "has.cleanup", "false");
816*0a6a1f1dSLionel Sambuc         check_property((*iter).second, "ident", "third");
817*0a6a1f1dSLionel Sambuc         check_property((*iter).second, "timeout", "300");
818*0a6a1f1dSLionel Sambuc     }
819*0a6a1f1dSLionel Sambuc }
820*0a6a1f1dSLionel Sambuc 
821*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(parse_test_case_result_expected_death);
ATF_TEST_CASE_BODY(parse_test_case_result_expected_death)822*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(parse_test_case_result_expected_death) {
823*0a6a1f1dSLionel Sambuc     check_result("expected_death", -1, "foo bar",
824*0a6a1f1dSLionel Sambuc                  detail::parse_test_case_result("expected_death: foo bar"));
825*0a6a1f1dSLionel Sambuc 
826*0a6a1f1dSLionel Sambuc     ATF_REQUIRE_THROW(std::runtime_error,
827*0a6a1f1dSLionel Sambuc                     detail::parse_test_case_result("expected_death"));
828*0a6a1f1dSLionel Sambuc     ATF_REQUIRE_THROW(std::runtime_error,
829*0a6a1f1dSLionel Sambuc                     detail::parse_test_case_result("expected_death(3): foo"));
830*0a6a1f1dSLionel Sambuc }
831*0a6a1f1dSLionel Sambuc 
832*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(parse_test_case_result_expected_exit);
ATF_TEST_CASE_BODY(parse_test_case_result_expected_exit)833*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(parse_test_case_result_expected_exit) {
834*0a6a1f1dSLionel Sambuc     check_result("expected_exit", -1, "foo bar",
835*0a6a1f1dSLionel Sambuc                  detail::parse_test_case_result("expected_exit: foo bar"));
836*0a6a1f1dSLionel Sambuc     check_result("expected_exit", -1, "foo bar",
837*0a6a1f1dSLionel Sambuc                  detail::parse_test_case_result("expected_exit(): foo bar"));
838*0a6a1f1dSLionel Sambuc     check_result("expected_exit", 5, "foo bar",
839*0a6a1f1dSLionel Sambuc                  detail::parse_test_case_result("expected_exit(5): foo bar"));
840*0a6a1f1dSLionel Sambuc 
841*0a6a1f1dSLionel Sambuc     ATF_REQUIRE_THROW(std::runtime_error,
842*0a6a1f1dSLionel Sambuc                     detail::parse_test_case_result("expected_exit"));
843*0a6a1f1dSLionel Sambuc     ATF_REQUIRE_THROW(std::runtime_error,
844*0a6a1f1dSLionel Sambuc                     detail::parse_test_case_result("expected_exit("));
845*0a6a1f1dSLionel Sambuc }
846*0a6a1f1dSLionel Sambuc 
847*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(parse_test_case_result_expected_failure);
ATF_TEST_CASE_BODY(parse_test_case_result_expected_failure)848*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(parse_test_case_result_expected_failure) {
849*0a6a1f1dSLionel Sambuc     check_result("expected_failure", -1, "foo bar",
850*0a6a1f1dSLionel Sambuc                  detail::parse_test_case_result("expected_failure: foo bar"));
851*0a6a1f1dSLionel Sambuc 
852*0a6a1f1dSLionel Sambuc     ATF_REQUIRE_THROW(std::runtime_error,
853*0a6a1f1dSLionel Sambuc                     detail::parse_test_case_result("expected_failure"));
854*0a6a1f1dSLionel Sambuc     ATF_REQUIRE_THROW(std::runtime_error,
855*0a6a1f1dSLionel Sambuc                     detail::parse_test_case_result("expected_failure(3): foo"));
856*0a6a1f1dSLionel Sambuc }
857*0a6a1f1dSLionel Sambuc 
858*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(parse_test_case_result_expected_signal);
ATF_TEST_CASE_BODY(parse_test_case_result_expected_signal)859*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(parse_test_case_result_expected_signal) {
860*0a6a1f1dSLionel Sambuc     check_result("expected_signal", -1, "foo bar",
861*0a6a1f1dSLionel Sambuc                  detail::parse_test_case_result("expected_signal: foo bar"));
862*0a6a1f1dSLionel Sambuc     check_result("expected_signal", -1, "foo bar",
863*0a6a1f1dSLionel Sambuc                  detail::parse_test_case_result("expected_signal(): foo bar"));
864*0a6a1f1dSLionel Sambuc     check_result("expected_signal", 5, "foo bar",
865*0a6a1f1dSLionel Sambuc                  detail::parse_test_case_result("expected_signal(5): foo bar"));
866*0a6a1f1dSLionel Sambuc 
867*0a6a1f1dSLionel Sambuc     ATF_REQUIRE_THROW(std::runtime_error,
868*0a6a1f1dSLionel Sambuc                     detail::parse_test_case_result("expected_signal"));
869*0a6a1f1dSLionel Sambuc     ATF_REQUIRE_THROW(std::runtime_error,
870*0a6a1f1dSLionel Sambuc                     detail::parse_test_case_result("expected_signal("));
871*0a6a1f1dSLionel Sambuc }
872*0a6a1f1dSLionel Sambuc 
873*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(parse_test_case_result_expected_timeout);
ATF_TEST_CASE_BODY(parse_test_case_result_expected_timeout)874*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(parse_test_case_result_expected_timeout) {
875*0a6a1f1dSLionel Sambuc     check_result("expected_timeout", -1, "foo bar",
876*0a6a1f1dSLionel Sambuc                  detail::parse_test_case_result("expected_timeout: foo bar"));
877*0a6a1f1dSLionel Sambuc 
878*0a6a1f1dSLionel Sambuc     ATF_REQUIRE_THROW(std::runtime_error,
879*0a6a1f1dSLionel Sambuc                     detail::parse_test_case_result("expected_timeout"));
880*0a6a1f1dSLionel Sambuc     ATF_REQUIRE_THROW(std::runtime_error,
881*0a6a1f1dSLionel Sambuc                     detail::parse_test_case_result("expected_timeout(3): foo"));
882*0a6a1f1dSLionel Sambuc }
883*0a6a1f1dSLionel Sambuc 
884*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(parse_test_case_result_failed);
ATF_TEST_CASE_BODY(parse_test_case_result_failed)885*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(parse_test_case_result_failed) {
886*0a6a1f1dSLionel Sambuc     check_result("failed", -1, "foo bar",
887*0a6a1f1dSLionel Sambuc                  detail::parse_test_case_result("failed: foo bar"));
888*0a6a1f1dSLionel Sambuc 
889*0a6a1f1dSLionel Sambuc     ATF_REQUIRE_THROW(std::runtime_error,
890*0a6a1f1dSLionel Sambuc                     detail::parse_test_case_result("failed"));
891*0a6a1f1dSLionel Sambuc     ATF_REQUIRE_THROW(std::runtime_error,
892*0a6a1f1dSLionel Sambuc                     detail::parse_test_case_result("failed(3): foo"));
893*0a6a1f1dSLionel Sambuc }
894*0a6a1f1dSLionel Sambuc 
895*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(parse_test_case_result_passed);
ATF_TEST_CASE_BODY(parse_test_case_result_passed)896*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(parse_test_case_result_passed) {
897*0a6a1f1dSLionel Sambuc     check_result("passed", -1, "",
898*0a6a1f1dSLionel Sambuc                  detail::parse_test_case_result("passed"));
899*0a6a1f1dSLionel Sambuc 
900*0a6a1f1dSLionel Sambuc     ATF_REQUIRE_THROW(std::runtime_error,
901*0a6a1f1dSLionel Sambuc                     detail::parse_test_case_result("passed: foo"));
902*0a6a1f1dSLionel Sambuc     ATF_REQUIRE_THROW(std::runtime_error,
903*0a6a1f1dSLionel Sambuc                     detail::parse_test_case_result("passed(3): foo"));
904*0a6a1f1dSLionel Sambuc }
905*0a6a1f1dSLionel Sambuc 
906*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(parse_test_case_result_skipped);
ATF_TEST_CASE_BODY(parse_test_case_result_skipped)907*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(parse_test_case_result_skipped) {
908*0a6a1f1dSLionel Sambuc     check_result("skipped", -1, "foo bar",
909*0a6a1f1dSLionel Sambuc                  detail::parse_test_case_result("skipped: foo bar"));
910*0a6a1f1dSLionel Sambuc 
911*0a6a1f1dSLionel Sambuc     ATF_REQUIRE_THROW(std::runtime_error,
912*0a6a1f1dSLionel Sambuc                     detail::parse_test_case_result("skipped"));
913*0a6a1f1dSLionel Sambuc     ATF_REQUIRE_THROW(std::runtime_error,
914*0a6a1f1dSLionel Sambuc                     detail::parse_test_case_result("skipped(3): foo"));
915*0a6a1f1dSLionel Sambuc }
916*0a6a1f1dSLionel Sambuc 
917*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(parse_test_case_result_unknown);
ATF_TEST_CASE_BODY(parse_test_case_result_unknown)918*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(parse_test_case_result_unknown) {
919*0a6a1f1dSLionel Sambuc     ATF_REQUIRE_THROW(std::runtime_error,
920*0a6a1f1dSLionel Sambuc                     detail::parse_test_case_result("foo"));
921*0a6a1f1dSLionel Sambuc     ATF_REQUIRE_THROW(std::runtime_error,
922*0a6a1f1dSLionel Sambuc                     detail::parse_test_case_result("bar: foo"));
923*0a6a1f1dSLionel Sambuc     ATF_REQUIRE_THROW(std::runtime_error,
924*0a6a1f1dSLionel Sambuc                     detail::parse_test_case_result("baz: foo"));
925*0a6a1f1dSLionel Sambuc }
926*0a6a1f1dSLionel Sambuc 
927*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(read_test_case_result_failed);
ATF_TEST_CASE_BODY(read_test_case_result_failed)928*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(read_test_case_result_failed) {
929*0a6a1f1dSLionel Sambuc     write_test_case_result("resfile", "failed: foo bar\n");
930*0a6a1f1dSLionel Sambuc     const impl::test_case_result tcr = impl::read_test_case_result(
931*0a6a1f1dSLionel Sambuc         tools::fs::path("resfile"));
932*0a6a1f1dSLionel Sambuc     ATF_REQUIRE_EQ("failed", tcr.state());
933*0a6a1f1dSLionel Sambuc     ATF_REQUIRE_EQ("foo bar", tcr.reason());
934*0a6a1f1dSLionel Sambuc }
935*0a6a1f1dSLionel Sambuc 
936*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(read_test_case_result_skipped);
ATF_TEST_CASE_BODY(read_test_case_result_skipped)937*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(read_test_case_result_skipped) {
938*0a6a1f1dSLionel Sambuc     write_test_case_result("resfile", "skipped: baz bar\n");
939*0a6a1f1dSLionel Sambuc     const impl::test_case_result tcr = impl::read_test_case_result(
940*0a6a1f1dSLionel Sambuc         tools::fs::path("resfile"));
941*0a6a1f1dSLionel Sambuc     ATF_REQUIRE_EQ("skipped", tcr.state());
942*0a6a1f1dSLionel Sambuc     ATF_REQUIRE_EQ("baz bar", tcr.reason());
943*0a6a1f1dSLionel Sambuc }
944*0a6a1f1dSLionel Sambuc 
945*0a6a1f1dSLionel Sambuc 
946*0a6a1f1dSLionel Sambuc ATF_TEST_CASE(read_test_case_result_no_file);
ATF_TEST_CASE_HEAD(read_test_case_result_no_file)947*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_HEAD(read_test_case_result_no_file) {}
ATF_TEST_CASE_BODY(read_test_case_result_no_file)948*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(read_test_case_result_no_file) {
949*0a6a1f1dSLionel Sambuc     ATF_REQUIRE_THROW(std::runtime_error,
950*0a6a1f1dSLionel Sambuc                     impl::read_test_case_result(tools::fs::path("resfile")));
951*0a6a1f1dSLionel Sambuc }
952*0a6a1f1dSLionel Sambuc 
953*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(read_test_case_result_empty_file);
ATF_TEST_CASE_BODY(read_test_case_result_empty_file)954*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(read_test_case_result_empty_file) {
955*0a6a1f1dSLionel Sambuc     write_test_case_result("resfile", "");
956*0a6a1f1dSLionel Sambuc     ATF_REQUIRE_THROW(std::runtime_error,
957*0a6a1f1dSLionel Sambuc                     impl::read_test_case_result(tools::fs::path("resfile")));
958*0a6a1f1dSLionel Sambuc }
959*0a6a1f1dSLionel Sambuc 
960*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(read_test_case_result_invalid);
ATF_TEST_CASE_BODY(read_test_case_result_invalid)961*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(read_test_case_result_invalid) {
962*0a6a1f1dSLionel Sambuc     write_test_case_result("resfile", "passed: hello\n");
963*0a6a1f1dSLionel Sambuc     ATF_REQUIRE_THROW(std::runtime_error,
964*0a6a1f1dSLionel Sambuc                     impl::read_test_case_result(tools::fs::path("resfile")));
965*0a6a1f1dSLionel Sambuc }
966*0a6a1f1dSLionel Sambuc 
967*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_WITHOUT_HEAD(read_test_case_result_multiline);
ATF_TEST_CASE_BODY(read_test_case_result_multiline)968*0a6a1f1dSLionel Sambuc ATF_TEST_CASE_BODY(read_test_case_result_multiline) {
969*0a6a1f1dSLionel Sambuc     write_test_case_result("resfile", "skipped: foo\nbar\n");
970*0a6a1f1dSLionel Sambuc     const impl::test_case_result tcr = impl::read_test_case_result(
971*0a6a1f1dSLionel Sambuc         tools::fs::path("resfile"));
972*0a6a1f1dSLionel Sambuc     ATF_REQUIRE_EQ("skipped", tcr.state());
973*0a6a1f1dSLionel Sambuc     ATF_REQUIRE_EQ("foo<<NEWLINE UNEXPECTED>>bar", tcr.reason());
974*0a6a1f1dSLionel Sambuc }
975*0a6a1f1dSLionel Sambuc 
976*0a6a1f1dSLionel Sambuc // -------------------------------------------------------------------------
977*0a6a1f1dSLionel Sambuc // Main.
978*0a6a1f1dSLionel Sambuc // -------------------------------------------------------------------------
979*0a6a1f1dSLionel Sambuc 
ATF_INIT_TEST_CASES(tcs)980*0a6a1f1dSLionel Sambuc ATF_INIT_TEST_CASES(tcs)
981*0a6a1f1dSLionel Sambuc {
982*0a6a1f1dSLionel Sambuc     ATF_ADD_TEST_CASE(tcs, tp_1);
983*0a6a1f1dSLionel Sambuc     ATF_ADD_TEST_CASE(tcs, tp_2);
984*0a6a1f1dSLionel Sambuc     ATF_ADD_TEST_CASE(tcs, tp_3);
985*0a6a1f1dSLionel Sambuc     ATF_ADD_TEST_CASE(tcs, tp_4);
986*0a6a1f1dSLionel Sambuc     ATF_ADD_TEST_CASE(tcs, tp_50);
987*0a6a1f1dSLionel Sambuc     ATF_ADD_TEST_CASE(tcs, tp_51);
988*0a6a1f1dSLionel Sambuc     ATF_ADD_TEST_CASE(tcs, tp_52);
989*0a6a1f1dSLionel Sambuc     ATF_ADD_TEST_CASE(tcs, tp_53);
990*0a6a1f1dSLionel Sambuc     ATF_ADD_TEST_CASE(tcs, tp_54);
991*0a6a1f1dSLionel Sambuc     ATF_ADD_TEST_CASE(tcs, tp_55);
992*0a6a1f1dSLionel Sambuc     ATF_ADD_TEST_CASE(tcs, tp_56);
993*0a6a1f1dSLionel Sambuc     ATF_ADD_TEST_CASE(tcs, tp_57);
994*0a6a1f1dSLionel Sambuc     ATF_ADD_TEST_CASE(tcs, tp_58);
995*0a6a1f1dSLionel Sambuc     ATF_ADD_TEST_CASE(tcs, tp_59);
996*0a6a1f1dSLionel Sambuc     ATF_ADD_TEST_CASE(tcs, tp_60);
997*0a6a1f1dSLionel Sambuc 
998*0a6a1f1dSLionel Sambuc     ATF_ADD_TEST_CASE(tcs, atf_tps_writer);
999*0a6a1f1dSLionel Sambuc 
1000*0a6a1f1dSLionel Sambuc     ATF_ADD_TEST_CASE(tcs, get_metadata_bad);
1001*0a6a1f1dSLionel Sambuc     ATF_ADD_TEST_CASE(tcs, get_metadata_zero_tcs);
1002*0a6a1f1dSLionel Sambuc     ATF_ADD_TEST_CASE(tcs, get_metadata_several_tcs);
1003*0a6a1f1dSLionel Sambuc 
1004*0a6a1f1dSLionel Sambuc     ATF_ADD_TEST_CASE(tcs, parse_test_case_result_expected_death);
1005*0a6a1f1dSLionel Sambuc     ATF_ADD_TEST_CASE(tcs, parse_test_case_result_expected_exit);
1006*0a6a1f1dSLionel Sambuc     ATF_ADD_TEST_CASE(tcs, parse_test_case_result_expected_failure);
1007*0a6a1f1dSLionel Sambuc     ATF_ADD_TEST_CASE(tcs, parse_test_case_result_expected_signal);
1008*0a6a1f1dSLionel Sambuc     ATF_ADD_TEST_CASE(tcs, parse_test_case_result_expected_timeout);
1009*0a6a1f1dSLionel Sambuc     ATF_ADD_TEST_CASE(tcs, parse_test_case_result_failed);
1010*0a6a1f1dSLionel Sambuc     ATF_ADD_TEST_CASE(tcs, parse_test_case_result_passed);
1011*0a6a1f1dSLionel Sambuc     ATF_ADD_TEST_CASE(tcs, parse_test_case_result_skipped);
1012*0a6a1f1dSLionel Sambuc     ATF_ADD_TEST_CASE(tcs, parse_test_case_result_unknown);
1013*0a6a1f1dSLionel Sambuc 
1014*0a6a1f1dSLionel Sambuc     ATF_ADD_TEST_CASE(tcs, read_test_case_result_failed);
1015*0a6a1f1dSLionel Sambuc     ATF_ADD_TEST_CASE(tcs, read_test_case_result_skipped);
1016*0a6a1f1dSLionel Sambuc     ATF_ADD_TEST_CASE(tcs, read_test_case_result_no_file);
1017*0a6a1f1dSLionel Sambuc     ATF_ADD_TEST_CASE(tcs, read_test_case_result_empty_file);
1018*0a6a1f1dSLionel Sambuc     ATF_ADD_TEST_CASE(tcs, read_test_case_result_multiline);
1019*0a6a1f1dSLionel Sambuc     ATF_ADD_TEST_CASE(tcs, read_test_case_result_invalid);
1020*0a6a1f1dSLionel Sambuc 
1021*0a6a1f1dSLionel Sambuc     // TODO: Add tests for run_test_case once all the missing functionality
1022*0a6a1f1dSLionel Sambuc     // is implemented.
1023*0a6a1f1dSLionel Sambuc }
1024