void test_helpers_detail::check_equal(const char* expected[], const string_vector& actual) { const char** expected_iter = expected; string_vector::const_iterator actual_iter = actual.begin(); bool equals = true; while (equals && *expected_iter != NULL && actual_iter != actual.end()) { if (*expected_iter != *actual_iter) { equals = false; } else { expected_iter++; actual_iter++; } } if (equals && ((*expected_iter == NULL && actual_iter != actual.end()) || (*expected_iter != NULL && actual_iter == actual.end()))) equals = false; if (!equals) { std::cerr << "EXPECTED:\n"; for (expected_iter = expected; *expected_iter != NULL; expected_iter++) std::cerr << *expected_iter << "\n"; std::cerr << "ACTUAL:\n"; for (actual_iter = actual.begin(); actual_iter != actual.end(); actual_iter++) std::cerr << *actual_iter << "\n"; ATF_FAIL("Expected results differ to actual values"); } }
static std::string read_file(const char *path) { char buffer[1024]; const int fd = open(path, O_RDONLY); if (fd == -1) ATF_FAIL("Cannot open " + std::string(path)); const ssize_t length = read(fd, buffer, sizeof(buffer) - 1); close(fd); ATF_REQUIRE(length != -1); if (length == sizeof(buffer) - 1) ATF_FAIL("Internal buffer not long enough to read temporary file"); ((char *)buffer)[length] = '\0'; return buffer; }
static void touch(const std::string& path) { std::ofstream os(path.c_str()); if (!os) ATF_FAIL("Could not create file " + path); os.close(); }
void header_check(const char *hdrname) { std::ofstream srcfile("test.cpp"); ATF_REQUIRE(srcfile); srcfile << "#include <" << hdrname << ">\n"; srcfile.close(); const std::string failmsg = std::string("Header check failed; ") + hdrname + " is not self-contained"; if (!build_check_cxx_o("test.cpp")) ATF_FAIL(failmsg); }
void build_check_cxx_o_aux(const atf::fs::path& sfile, const char* failmsg, const bool expect_pass) { std::vector< std::string > optargs; optargs.push_back("-I" + atf::config::get("atf_includedir")); optargs.push_back("-Wall"); optargs.push_back("-Werror"); const bool result = atf::check::build_cxx_o( sfile.str(), "test.o", atf::process::argv_array(optargs)); if ((expect_pass && !result) || (!expect_pass && result)) ATF_FAIL(failmsg); }
std::pair< string_vector, string_vector > do_read(const char* input) { string_vector errors; std::istringstream is(input); Reader reader(is); try { reader.read(); } catch (const atf::parser::parse_errors& pes) { for (std::vector< atf::parser::parse_error >::const_iterator iter = pes.begin(); iter != pes.end(); iter++) errors.push_back(*iter); } catch (const atf::parser::parse_error& pe) { ATF_FAIL("Raised a lonely parse error: " + atf::text::to_string(pe.first) + ": " + pe.second); } return std::make_pair(reader.m_calls, errors); }
void* operator new(size_t size ATF_DEFS_ATTRIBUTE_UNUSED) { ATF_FAIL("New called but should have been new[]"); return new int(5); }