Remove building with NOCRYPTO option
[minix3.git] / external / bsd / atf / dist / tools / test_helpers.hpp
blob3ac92d0ea79e62fed9b40c8e4d9aaad1f1a8343f
1 //
2 // Automated Testing Framework (atf)
3 //
4 // Copyright (c) 2009 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 #if defined(TOOLS_TEST_HELPERS_H)
31 # error "Cannot include test_helpers.hpp more than once."
32 #else
33 # define TOOLS_TEST_HELPERS_H
34 #endif
36 #include <iostream>
37 #include <sstream>
38 #include <utility>
40 #include <atf-c++.hpp>
42 #include "parser.hpp"
43 #include "text.hpp"
45 namespace test_helpers_detail {
47 typedef std::vector< std::string > string_vector;
49 template< class Reader >
50 std::pair< string_vector, string_vector >
51 do_read(const char* input)
53 string_vector errors;
55 std::istringstream is(input);
56 Reader reader(is);
57 try {
58 reader.read();
59 } catch (const tools::parser::parse_errors& pes) {
60 for (std::vector< tools::parser::parse_error >::const_iterator iter =
61 pes.begin(); iter != pes.end(); iter++)
62 errors.push_back(*iter);
63 } catch (const tools::parser::parse_error& pe) {
64 ATF_FAIL("Raised a lonely parse error: " +
65 tools::text::to_string(pe.first) + ": " + pe.second);
68 return std::make_pair(reader.m_calls, errors);
71 void
72 check_equal(const char* expected[], const string_vector& actual)
74 const char** expected_iter = expected;
75 string_vector::const_iterator actual_iter = actual.begin();
77 bool equals = true;
78 while (equals && *expected_iter != NULL && actual_iter != actual.end()) {
79 if (*expected_iter != *actual_iter) {
80 equals = false;
81 } else {
82 expected_iter++;
83 actual_iter++;
86 if (equals && ((*expected_iter == NULL && actual_iter != actual.end()) ||
87 (*expected_iter != NULL && actual_iter == actual.end())))
88 equals = false;
90 if (!equals) {
91 std::cerr << "EXPECTED:\n";
92 for (expected_iter = expected; *expected_iter != NULL; expected_iter++)
93 std::cerr << *expected_iter << "\n";
95 std::cerr << "ACTUAL:\n";
96 for (actual_iter = actual.begin(); actual_iter != actual.end();
97 actual_iter++)
98 std::cerr << *actual_iter << "\n";
100 ATF_FAIL("Expected results differ to actual values");
104 } // namespace test_helpers_detail
106 template< class Reader >
107 void
108 do_parser_test(const char* input, const char* exp_calls[],
109 const char* exp_errors[])
111 const std::pair< test_helpers_detail::string_vector,
112 test_helpers_detail::string_vector >
113 actual = test_helpers_detail::do_read< Reader >(input);
114 test_helpers_detail::check_equal(exp_calls, actual.first);
115 test_helpers_detail::check_equal(exp_errors, actual.second);