1 // Copyright (c) 2007 The NetBSD Foundation, Inc.
2 // All rights reserved.
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions
7 // 1. Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // 2. Redistributions in binary form must reproduce the above copyright
10 // notice, this list of conditions and the following disclaimer in the
11 // documentation and/or other materials provided with the distribution.
13 // THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
14 // CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
15 // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 // IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
18 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
20 // GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22 // IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
24 // IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #include "atf-c++/tests.hpp"
29 #include <sys/types.h>
40 #include <atf-c++.hpp>
42 #include "atf-c++/detail/text.hpp"
44 // ------------------------------------------------------------------------
45 // Tests for the "atf_tp_writer" class.
46 // ------------------------------------------------------------------------
50 print_indented(const std::string& str)
52 std::vector< std::string > ws = atf::text::split(str, "\n");
53 for (std::vector< std::string >::const_iterator iter = ws.begin();
54 iter != ws.end(); iter++)
55 std::cout << ">>" << *iter << "<<\n";
58 // XXX Should this string handling and verbosity level be part of the
59 // ATF_REQUIRE_EQ macro? It may be hard to predict sometimes that a
60 // string can have newlines in it, and so the error message generated
61 // at the moment will be bogus if there are some.
64 check_equal(const atf::tests::tc& tc, const std::string& str,
65 const std::string& exp)
68 std::cout << "String equality check failed.\n"
69 "Adding >> and << to delimit the string boundaries below.\n";
70 std::cout << "GOT:\n";
72 std::cout << "EXPECTED:\n";
74 tc.fail("Constructed string differs from the expected one");
78 ATF_TEST_CASE(atf_tp_writer);
79 ATF_TEST_CASE_HEAD(atf_tp_writer)
81 set_md_var("descr", "Verifies the application/X-atf-tp writer");
83 ATF_TEST_CASE_BODY(atf_tp_writer)
85 std::ostringstream expss;
86 std::ostringstream ss;
93 check_equal(*this, ss.str(), expss.str())
98 atf::tests::detail::atf_tp_writer w(ss);
99 expss << "Content-Type: application/X-atf-tp; version=\"1\"\n\n";
106 atf::tests::detail::atf_tp_writer w(ss);
107 expss << "Content-Type: application/X-atf-tp; version=\"1\"\n\n";
111 expss << "ident: test1\n";
121 atf::tests::detail::atf_tp_writer w(ss);
122 expss << "Content-Type: application/X-atf-tp; version=\"1\"\n\n";
126 expss << "ident: test1\n";
133 expss << "\nident: test2\n";
143 atf::tests::detail::atf_tp_writer w(ss);
144 expss << "Content-Type: application/X-atf-tp; version=\"1\"\n\n";
148 expss << "ident: test1\n";
151 w.tc_meta_data("descr", "the description");
152 expss << "descr: the description\n";
159 expss << "\nident: test2\n";
162 w.tc_meta_data("descr", "second test case");
163 expss << "descr: second test case\n";
166 w.tc_meta_data("require.progs", "/bin/cp");
167 expss << "require.progs: /bin/cp\n";
170 w.tc_meta_data("X-custom", "foo bar baz");
171 expss << "X-custom: foo bar baz\n";
182 // ------------------------------------------------------------------------
184 // ------------------------------------------------------------------------
186 ATF_INIT_TEST_CASES(tcs)
188 // Add tests for the "atf_tp_writer" class.
189 ATF_ADD_TEST_CASE(tcs, atf_tp_writer);