// Copyright (c) 2008 The NetBSD Foundation, Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
//
// THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
// CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
// IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "atf-c++/macros.hpp"
extern "C" {
#include <fcntl.h>
#include <unistd.h>
}
#include <cerrno>
#include <cstdlib>
#include <iostream>
#include <stdexcept>
#include "atf-c++/detail/process.hpp"
#include "atf-c++/detail/sanity.hpp"
#include "atf-c++/detail/test_helpers.hpp"
#include "atf-c++/utils.hpp"
// ------------------------------------------------------------------------
// Auxiliary functions.
// ------------------------------------------------------------------------
static
void
{
}
// ------------------------------------------------------------------------
// Auxiliary test cases.
// ------------------------------------------------------------------------
{
}
{
create_ctl_file("before");
ATF_PASS();
create_ctl_file("after");
}
{
}
{
create_ctl_file("before");
ATF_FAIL("Failed on purpose");
create_ctl_file("after");
}
{
}
{
create_ctl_file("before");
ATF_SKIP("Skipped on purpose");
create_ctl_file("after");
}
{
}
{
create_ctl_file("before");
create_ctl_file("after");
}
{
}
{
create_ctl_file("before");
create_ctl_file("after");
}
{
}
{
create_ctl_file("before");
create_ctl_file("after");
}
{
}
{
create_ctl_file("before");
create_ctl_file("after");
}
{
}
{
create_ctl_file("before");
create_ctl_file("after");
}
{
}
{
create_ctl_file("before");
create_ctl_file("after");
}
{
}
{
create_ctl_file("before");
create_ctl_file("after");
}
static int
{
return -1;
}
static int
errno_ok_stub(void)
{
return 0;
}
{
}
{
create_ctl_file("before");
else
create_ctl_file("after");
}
{
}
{
create_ctl_file("before");
else
create_ctl_file("after");
}
// ------------------------------------------------------------------------
// Test cases for the macros.
// ------------------------------------------------------------------------
{
}
{
}
{
}
{
}
{
}
{
"result"));
}
{
}
{
struct test {
const char *cond;
bool ok;
} *t, tests[] = {
{ "false", false },
{ "true", true },
{ NULL, false }
};
if (t->ok) {
} else {
"^failed: .*condition not met", "result"));
}
if (t->ok)
}
}
{
}
{
struct test {
const char *v1;
const char *v2;
bool ok;
} *t, tests[] = {
{ "1", "1", true },
{ "1", "2", false },
{ "2", "1", false },
{ "2", "2", true },
};
<< "\n";
if (t->ok) {
} else {
}
if (t->ok)
}
}
{
}
{
struct test {
const char *value;
bool ok;
} *t, tests[] = {
{ "foo", true },
{ "bar", true },
{ "baz", true },
{ "xxx", false },
{ "fooa", false },
{ "foo ", false },
{ NULL, false }
};
if (t->ok) {
} else {
}
if (t->ok)
}
}
{
}
{
struct test {
const char *regexp;
const char *string;
bool ok;
} *t, tests[] = {
{ "foo.*bar", "this is a foo, bar, baz", true },
{ "bar.*baz", "this is a baz, bar, foo", false },
};
<< "\n";
if (t->ok) {
} else {
}
if (t->ok)
}
}
{
}
{
struct test {
const char *value;
bool ok;
} *t, tests[] = {
{ "foo", false },
{ "bar", false },
{ "baz", false },
{ "xxx", true },
{ "fooa", true },
{ "foo ", true },
{ NULL, false }
};
if (t->ok) {
} else {
}
if (t->ok)
}
}
{
}
{
struct test {
const char *what;
bool ok;
const char *msg;
} *t, tests[] = {
{ "throw_int", false, "unexpected error" },
{ "throw_rt", true, NULL },
{ "no_throw_rt", false, "did not throw" },
};
if (t->ok) {
} else {
<< "'\n";
}
if (t->ok)
}
}
{
}
{
struct test {
const char *what;
bool ok;
const char *msg;
} *t, tests[] = {
{ "throw_int", false, "unexpected error" },
{ "throw_rt_match", true, NULL },
{ "throw_rt_no_match", false,
"threw.*runtime_error\\(baz foo bar a\\).*"
"does not match 'foo\\.\\*baz'" },
{ "no_throw_rt", false, "did not throw" },
};
if (t->ok) {
} else {
<< "'\n";
}
if (t->ok)
}
}
{
}
{
struct test {
const char *what;
bool ok;
const char *msg;
} *t, tests[] = {
{ "no_error", false,
"Expected true value in errno_ok_stub\\(\\) == -1" },
{ "errno_ok", true, NULL },
{ "errno_fail", false,
"Expected errno 3, got 4, in errno_fail_stub\\(4\\) == -1" },
};
if (t->ok) {
} else {
}
}
}
{
}
{
struct test {
const char *what;
bool ok;
const char *msg;
} *t, tests[] = {
{ "no_error", false,
"Expected true value in errno_ok_stub\\(\\) == -1" },
{ "errno_ok", true, NULL },
{ "errno_fail", false,
"Expected errno 3, got 4, in errno_fail_stub\\(4\\) == -1" },
};
if (t->ok) {
} else {
}
if (t->ok)
}
}
// ------------------------------------------------------------------------
// Tests cases for the header file.
// ------------------------------------------------------------------------
"Tests that the macros provided by the atf-c++/macros.hpp file "
"do not cause syntax errors when used",
"Build of macros_hpp_test.cpp failed; some macros in "
"atf-c++/macros.hpp are broken");
{
set_md_var("descr",
"Tests that defining an unused test case raises a warning (and "
"thus an error)");
}
{
const char* validate_compiler =
"class test_class { public: int dummy; };\n"
"#define define_unused static test_class unused\n"
"define_unused;\n";
if (build_check_cxx_o("compiler_test.cpp"))
expect_fail("Compiler does not raise a warning on an unused "
"static global variable declared by a macro");
if (build_check_cxx_o_srcdir(*this, "unused_test.cpp"))
ATF_FAIL("Build of unused_test.cpp passed; unused test cases are "
"not properly detected");
}
// ------------------------------------------------------------------------
// Main.
// ------------------------------------------------------------------------
{
// Add the test cases for the macros.
// Add the test cases for the header file.
}