Remove building with NOCRYPTO option
[minix3.git] / external / bsd / atf / dist / atf-c++ / tests_test.cpp
blob5f19a4e176c08bbe1e48ee155d1d779169abffed
1 //
2 // Automated Testing Framework (atf)
3 //
4 // Copyright (c) 2007 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.
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.
30 extern "C" {
31 #include <sys/types.h>
32 #include <sys/stat.h>
34 #include <fcntl.h>
35 #include <unistd.h>
38 #include <fstream>
39 #include <sstream>
41 #include "macros.hpp"
43 #include "detail/test_helpers.hpp"
44 #include "detail/text.hpp"
46 // ------------------------------------------------------------------------
47 // Tests for the "atf_tp_writer" class.
48 // ------------------------------------------------------------------------
50 static
51 void
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.
64 static
65 void
66 check_equal(const atf::tests::tc& tc, const std::string& str,
67 const std::string& exp)
69 if (str != exp) {
70 std::cout << "String equality check failed.\n"
71 "Adding >> and << to delimit the string boundaries below.\n";
72 std::cout << "GOT:\n";
73 print_indented(str);
74 std::cout << "EXPECTED:\n";
75 print_indented(exp);
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;
90 #define RESET \
91 expss.str(""); \
92 ss.str("")
94 #define CHECK \
95 check_equal(*this, ss.str(), expss.str())
98 RESET;
100 atf::tests::detail::atf_tp_writer w(ss);
101 expss << "Content-Type: application/X-atf-tp; version=\"1\"\n\n";
102 CHECK;
106 RESET;
108 atf::tests::detail::atf_tp_writer w(ss);
109 expss << "Content-Type: application/X-atf-tp; version=\"1\"\n\n";
110 CHECK;
112 w.start_tc("test1");
113 expss << "ident: test1\n";
114 CHECK;
116 w.end_tc();
117 CHECK;
121 RESET;
123 atf::tests::detail::atf_tp_writer w(ss);
124 expss << "Content-Type: application/X-atf-tp; version=\"1\"\n\n";
125 CHECK;
127 w.start_tc("test1");
128 expss << "ident: test1\n";
129 CHECK;
131 w.end_tc();
132 CHECK;
134 w.start_tc("test2");
135 expss << "\nident: test2\n";
136 CHECK;
138 w.end_tc();
139 CHECK;
143 RESET;
145 atf::tests::detail::atf_tp_writer w(ss);
146 expss << "Content-Type: application/X-atf-tp; version=\"1\"\n\n";
147 CHECK;
149 w.start_tc("test1");
150 expss << "ident: test1\n";
151 CHECK;
153 w.tc_meta_data("descr", "the description");
154 expss << "descr: the description\n";
155 CHECK;
157 w.end_tc();
158 CHECK;
160 w.start_tc("test2");
161 expss << "\nident: test2\n";
162 CHECK;
164 w.tc_meta_data("descr", "second test case");
165 expss << "descr: second test case\n";
166 CHECK;
168 w.tc_meta_data("require.progs", "/bin/cp");
169 expss << "require.progs: /bin/cp\n";
170 CHECK;
172 w.tc_meta_data("X-custom", "foo bar baz");
173 expss << "X-custom: foo bar baz\n";
174 CHECK;
176 w.end_tc();
177 CHECK;
180 #undef CHECK
181 #undef RESET
184 // ------------------------------------------------------------------------
185 // Tests cases for the header file.
186 // ------------------------------------------------------------------------
188 HEADER_TC(include, "atf-c++/tests.hpp");
190 // ------------------------------------------------------------------------
191 // Main.
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);