2 // Automated Testing Framework (atf)
4 // Copyright (c) 2009 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.
33 #include "../atf-c/h_build.h"
39 #include "detail/env.hpp"
40 #include "detail/process.hpp"
41 #include "detail/test_helpers.hpp"
43 // ------------------------------------------------------------------------
44 // Auxiliary functions.
45 // ------------------------------------------------------------------------
55 print_col(const char* prefix
, const C
& c
)
57 std::cout
<< prefix
<< ":";
58 for (typename
C::const_iterator iter
= c
.begin(); iter
!= c
.end();
60 std::cout
<< " '" << *iter
<< "'";
66 print_array(const char* prefix
, const char* const* a
)
68 std::cout
<< prefix
<< ":";
69 for (; *a
!= NULL
; a
++)
70 std::cout
<< " '" << *a
<< "'";
76 verbose_set_env(const char *var
, const char *val
)
78 std::cout
<< "Setting " << var
<< " to '" << val
<< "'\n";
79 atf::env::set(var
, val
);
84 equal_argvs(const atf::process::argv_array
& aa
, const char* const* array
)
88 atf::process::argv_array::size_type i
= 0;
89 while (equal
&& (i
< aa
.size() && array
[i
] != NULL
)) {
90 if (std::strcmp(aa
[i
], array
[i
]) != 0)
96 if (equal
&& (i
< aa
.size() || array
[i
] != NULL
))
104 check_equal_argvs(const atf::process::argv_array
& aa
, const char* const* array
)
106 print_array("Expected arguments", array
);
107 print_col("Arguments returned", aa
);
109 if (!equal_argvs(aa
, array
))
110 ATF_FAIL("The constructed argv differs from the expected values");
113 // ------------------------------------------------------------------------
114 // Internal test cases.
115 // ------------------------------------------------------------------------
117 ATF_TEST_CASE(equal_argvs
);
118 ATF_TEST_CASE_HEAD(equal_argvs
)
120 set_md_var("descr", "Tests the test case internal equal_argvs function");
122 ATF_TEST_CASE_BODY(equal_argvs
)
125 const char* const array
[] = { NULL
};
126 const char* const argv
[] = { NULL
};
128 ATF_REQUIRE(equal_argvs(atf::process::argv_array(argv
), array
));
132 const char* const array
[] = { NULL
};
133 const char* const argv
[] = { "foo", NULL
};
135 ATF_REQUIRE(!equal_argvs(atf::process::argv_array(argv
), array
));
139 const char* const array
[] = { "foo", NULL
};
140 const char* const argv
[] = { NULL
};
142 ATF_REQUIRE(!equal_argvs(atf::process::argv_array(argv
), array
));
146 const char* const array
[] = { "foo", NULL
};
147 const char* const argv
[] = { "foo", NULL
};
149 ATF_REQUIRE(equal_argvs(atf::process::argv_array(argv
), array
));
153 // ------------------------------------------------------------------------
154 // Test cases for the free functions.
155 // ------------------------------------------------------------------------
158 ATF_TEST_CASE_HEAD(c_o
)
160 set_md_var("descr", "Tests the c_o function");
162 ATF_TEST_CASE_BODY(c_o
)
164 for (struct c_o_test
* test
= c_o_tests
; test
->expargv
[0] != NULL
;
166 std::cout
<< "> Test: " << test
->msg
<< "\n";
168 verbose_set_env("ATF_BUILD_CC", test
->cc
);
169 verbose_set_env("ATF_BUILD_CFLAGS", test
->cflags
);
170 verbose_set_env("ATF_BUILD_CPPFLAGS", test
->cppflags
);
171 atf::config::__reinit();
173 atf::process::argv_array argv
=
174 atf::build::c_o(test
->sfile
, test
->ofile
,
175 atf::process::argv_array(test
->optargs
));
176 check_equal_argvs(argv
, test
->expargv
);
181 ATF_TEST_CASE_HEAD(cpp
)
183 set_md_var("descr", "Tests the cpp function");
185 ATF_TEST_CASE_BODY(cpp
)
187 for (struct cpp_test
* test
= cpp_tests
; test
->expargv
[0] != NULL
;
189 std::cout
<< "> Test: " << test
->msg
<< "\n";
191 verbose_set_env("ATF_BUILD_CPP", test
->cpp
);
192 verbose_set_env("ATF_BUILD_CPPFLAGS", test
->cppflags
);
193 atf::config::__reinit();
195 atf::process::argv_array argv
=
196 atf::build::cpp(test
->sfile
, test
->ofile
,
197 atf::process::argv_array(test
->optargs
));
198 check_equal_argvs(argv
, test
->expargv
);
202 ATF_TEST_CASE(cxx_o
);
203 ATF_TEST_CASE_HEAD(cxx_o
)
205 set_md_var("descr", "Tests the cxx_o function");
207 ATF_TEST_CASE_BODY(cxx_o
)
209 for (struct cxx_o_test
* test
= cxx_o_tests
; test
->expargv
[0] != NULL
;
211 std::cout
<< "> Test: " << test
->msg
<< "\n";
213 verbose_set_env("ATF_BUILD_CXX", test
->cxx
);
214 verbose_set_env("ATF_BUILD_CXXFLAGS", test
->cxxflags
);
215 verbose_set_env("ATF_BUILD_CPPFLAGS", test
->cppflags
);
216 atf::config::__reinit();
218 atf::process::argv_array argv
=
219 atf::build::cxx_o(test
->sfile
, test
->ofile
,
220 atf::process::argv_array(test
->optargs
));
221 check_equal_argvs(argv
, test
->expargv
);
225 // ------------------------------------------------------------------------
226 // Tests cases for the header file.
227 // ------------------------------------------------------------------------
229 HEADER_TC(include
, "atf-c++/build.hpp");
231 // ------------------------------------------------------------------------
233 // ------------------------------------------------------------------------
235 ATF_INIT_TEST_CASES(tcs
)
237 // Add the internal test cases.
238 ATF_ADD_TEST_CASE(tcs
, equal_argvs
);
240 // Add the test cases for the free functions.
241 ATF_ADD_TEST_CASE(tcs
, c_o
);
242 ATF_ADD_TEST_CASE(tcs
, cpp
);
243 ATF_ADD_TEST_CASE(tcs
, cxx_o
);
245 // Add the test cases for the header file.
246 ATF_ADD_TEST_CASE(tcs
, include
);