a747113422afaa29ce72d2c5ba7f0b7ea9ec2054Evan Hunt// Copyright (c) 2007 The NetBSD Foundation, Inc.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// All rights reserved.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt//
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// Redistribution and use in source and binary forms, with or without
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// modification, are permitted provided that the following conditions
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// are met:
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// 1. Redistributions of source code must retain the above copyright
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// notice, this list of conditions and the following disclaimer.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// 2. Redistributions in binary form must reproduce the above copyright
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// notice, this list of conditions and the following disclaimer in the
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// documentation and/or other materials provided with the distribution.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt//
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews#include "atf-c++/tests.hpp"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntextern "C" {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#include <sys/types.h>
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#include <sys/stat.h>
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#include <fcntl.h>
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#include <unistd.h>
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#include <fstream>
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews#include <iostream>
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#include <sstream>
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews#include <atf-c++.hpp>
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
4a53e3c2b83c476a93148eaee0272649beb221caMark Andrews#include "atf-c++/detail/text.hpp"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// ------------------------------------------------------------------------
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// Tests for the "atf_tp_writer" class.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// ------------------------------------------------------------------------
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstatic
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntvoid
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntprint_indented(const std::string& str)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt std::vector< std::string > ws = atf::text::split(str, "\n");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt for (std::vector< std::string >::const_iterator iter = ws.begin();
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt iter != ws.end(); iter++)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt std::cout << ">>" << *iter << "<<\n";
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// XXX Should this string handling and verbosity level be part of the
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// ATF_REQUIRE_EQ macro? It may be hard to predict sometimes that a
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// string can have newlines in it, and so the error message generated
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// at the moment will be bogus if there are some.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntstatic
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntvoid
ef421f66f47224a42073deaf087378c5d0c9952eEvan Huntcheck_equal(const atf::tests::tc& tc, const std::string& str,
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt const std::string& exp)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt if (str != exp) {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt std::cout << "String equality check failed.\n"
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt "Adding >> and << to delimit the string boundaries below.\n";
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt std::cout << "GOT:\n";
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt print_indented(str);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt std::cout << "EXPECTED:\n";
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt print_indented(exp);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt tc.fail("Constructed string differs from the expected one");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt }
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TEST_CASE(atf_tp_writer);
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TEST_CASE_HEAD(atf_tp_writer)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt set_md_var("descr", "Verifies the application/X-atf-tp writer");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_TEST_CASE_BODY(atf_tp_writer)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt std::ostringstream expss;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt std::ostringstream ss;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#define RESET \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt expss.str(""); \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ss.str("")
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#define CHECK \
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt check_equal(*this, ss.str(), expss.str())
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RESET;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf::tests::detail::atf_tp_writer w(ss);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt expss << "Content-Type: application/X-atf-tp; version=\"1\"\n\n";
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt CHECK;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt }
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RESET;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf::tests::detail::atf_tp_writer w(ss);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt expss << "Content-Type: application/X-atf-tp; version=\"1\"\n\n";
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt CHECK;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt w.start_tc("test1");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt expss << "ident: test1\n";
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt CHECK;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt w.end_tc();
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt CHECK;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt }
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RESET;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf::tests::detail::atf_tp_writer w(ss);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt expss << "Content-Type: application/X-atf-tp; version=\"1\"\n\n";
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt CHECK;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt w.start_tc("test1");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt expss << "ident: test1\n";
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt CHECK;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt w.end_tc();
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt CHECK;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt w.start_tc("test2");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt expss << "\nident: test2\n";
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt CHECK;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt w.end_tc();
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt CHECK;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt }
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt {
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt RESET;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt atf::tests::detail::atf_tp_writer w(ss);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt expss << "Content-Type: application/X-atf-tp; version=\"1\"\n\n";
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt CHECK;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt w.start_tc("test1");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt expss << "ident: test1\n";
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt CHECK;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt w.tc_meta_data("descr", "the description");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt expss << "descr: the description\n";
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt CHECK;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt w.end_tc();
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt CHECK;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt w.start_tc("test2");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt expss << "\nident: test2\n";
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt CHECK;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt w.tc_meta_data("descr", "second test case");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt expss << "descr: second test case\n";
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt CHECK;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt w.tc_meta_data("require.progs", "/bin/cp");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt expss << "require.progs: /bin/cp\n";
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt CHECK;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt w.tc_meta_data("X-custom", "foo bar baz");
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt expss << "X-custom: foo bar baz\n";
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt CHECK;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt w.end_tc();
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt CHECK;
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt }
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#undef CHECK
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt#undef RESET
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// ------------------------------------------------------------------------
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// Main.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt// ------------------------------------------------------------------------
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt
ef421f66f47224a42073deaf087378c5d0c9952eEvan HuntATF_INIT_TEST_CASES(tcs)
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt{
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt // Add tests for the "atf_tp_writer" class.
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt ATF_ADD_TEST_CASE(tcs, atf_tp_writer);
ef421f66f47224a42073deaf087378c5d0c9952eEvan Hunt}