2 // Automated Testing Framework (atf)
4 // Copyright (c) 2007 The NetBSD Foundation, Inc.
5 // All rights reserved.
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
10 // 1. Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 // 2. Redistributions in binary form must reproduce the above copyright
13 // notice, this list of conditions and the following disclaimer in the
14 // documentation and/or other materials provided with the distribution.
16 // THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17 // CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 // IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 // GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 // IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 // IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include <sys/types.h>
43 #include "detail/test_helpers.hpp"
44 #include "detail/text.hpp"
46 // ------------------------------------------------------------------------
47 // Tests for the "atf_tp_writer" class.
48 // ------------------------------------------------------------------------
52 print_indented(const std::string
& str
)
54 std::vector
< std::string
> ws
= atf::text::split(str
, "\n");
55 for (std::vector
< std::string
>::const_iterator iter
= ws
.begin();
56 iter
!= ws
.end(); iter
++)
57 std::cout
<< ">>" << *iter
<< "<<\n";
60 // XXX Should this string handling and verbosity level be part of the
61 // ATF_REQUIRE_EQ macro? It may be hard to predict sometimes that a
62 // string can have newlines in it, and so the error message generated
63 // at the moment will be bogus if there are some.
66 check_equal(const atf::tests::tc
& tc
, const std::string
& str
,
67 const std::string
& exp
)
70 std::cout
<< "String equality check failed.\n"
71 "Adding >> and << to delimit the string boundaries below.\n";
72 std::cout
<< "GOT:\n";
74 std::cout
<< "EXPECTED:\n";
76 tc
.fail("Constructed string differs from the expected one");
80 ATF_TEST_CASE(atf_tp_writer
);
81 ATF_TEST_CASE_HEAD(atf_tp_writer
)
83 set_md_var("descr", "Verifies the application/X-atf-tp writer");
85 ATF_TEST_CASE_BODY(atf_tp_writer
)
87 std::ostringstream expss
;
88 std::ostringstream ss
;
95 check_equal(*this, ss.str(), expss.str())
100 atf::tests::detail::atf_tp_writer
w(ss
);
101 expss
<< "Content-Type: application/X-atf-tp; version=\"1\"\n\n";
108 atf::tests::detail::atf_tp_writer
w(ss
);
109 expss
<< "Content-Type: application/X-atf-tp; version=\"1\"\n\n";
113 expss
<< "ident: test1\n";
123 atf::tests::detail::atf_tp_writer
w(ss
);
124 expss
<< "Content-Type: application/X-atf-tp; version=\"1\"\n\n";
128 expss
<< "ident: test1\n";
135 expss
<< "\nident: test2\n";
145 atf::tests::detail::atf_tp_writer
w(ss
);
146 expss
<< "Content-Type: application/X-atf-tp; version=\"1\"\n\n";
150 expss
<< "ident: test1\n";
153 w
.tc_meta_data("descr", "the description");
154 expss
<< "descr: the description\n";
161 expss
<< "\nident: test2\n";
164 w
.tc_meta_data("descr", "second test case");
165 expss
<< "descr: second test case\n";
168 w
.tc_meta_data("require.progs", "/bin/cp");
169 expss
<< "require.progs: /bin/cp\n";
172 w
.tc_meta_data("X-custom", "foo bar baz");
173 expss
<< "X-custom: foo bar baz\n";
184 // ------------------------------------------------------------------------
185 // Tests cases for the header file.
186 // ------------------------------------------------------------------------
188 HEADER_TC(include
, "atf-c++/tests.hpp");
190 // ------------------------------------------------------------------------
192 // ------------------------------------------------------------------------
194 ATF_INIT_TEST_CASES(tcs
)
196 // Add tests for the "atf_tp_writer" class.
197 ATF_ADD_TEST_CASE(tcs
, atf_tp_writer
);
199 // Add the test cases for the header file.
200 ATF_ADD_TEST_CASE(tcs
, include
);