1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
// -*- c++ -*-
//*****************************************************************************
/** @file CStringLiteralTest.cc
*
* @author Ket Kalda, Alexander Dreyer
* @date 2011-03-15
*
* boost/test-driven unit test
*
* @par Copyright:
* (c) 2011 by The PolyBoRi Team
*
**/
//*****************************************************************************
#include <boost/test/unit_test.hpp>
#include <boost/version.hpp>
#if BOOST_VERSION < 107100
#include <boost/test/output_test_stream.hpp>
#else
#include <boost/test/tools/output_test_stream.hpp>
#endif
using boost::test_tools::output_test_stream;
# include <polybori/literals/CStringLiteral.h>
USING_NAMESPACE_PBORI
template <unsigned NUM = CLiteralCodes::first_code>
class print_lit {
public:
void operator()(std::ostream& os) const {
os << '"'<< CStringLiteral<NUM>()() <<'"' <<std::endl;
print_lit<NUM+1>()(os);
};
};
template <>
class print_lit <CLiteralCodes::last_code>{
public:
void operator()(std::ostream& os) const { };
};
struct Fliteral {
Fliteral() { BOOST_TEST_MESSAGE( "setup fixture" ); }
~Fliteral() { BOOST_TEST_MESSAGE( "teardown fixture" ); }
};
BOOST_FIXTURE_TEST_SUITE(CStringLiteralTestSuite, Fliteral )
BOOST_AUTO_TEST_CASE(test_lit) {
BOOST_TEST_MESSAGE("literals");
// Test all valid template arguments
output_test_stream output;
print_lit<>()(output);
output_test_stream output2;
output2 << '"'<< "" <<'"' <<std::endl;
output2 << '"'<< " " <<'"' <<std::endl;
output2 << '"'<< "+" <<'"' <<std::endl;
output2 << '"'<< " + " <<'"' <<std::endl;
output2 << '"'<< "*" <<'"' <<std::endl;
output2 << '"'<< "," <<'"' <<std::endl;
output2 << '"'<< ", " <<'"' <<std::endl;
output2 << '"'<< "x" <<'"' <<std::endl;
output2 << '"'<< "(" <<'"' <<std::endl;
output2 << '"'<< ")" <<'"' <<std::endl;
output2 << '"'<< "}, {" <<'"' <<std::endl;
BOOST_CHECK(output.is_equal(output2.str()));
// Test default template argument
output2.flush();
output << CStringLiteral<>()();
output2 << CStringLiteral<CLiteralCodes::first_code>()();
BOOST_CHECK(output.is_equal(output2.str()));
}
BOOST_AUTO_TEST_SUITE_END()
|