Ejemplo n.º 1
0
/*
 * This test case uses confix to wrap each xml attribute's value
 * inside double quotes.
 *
 * Notice that the generators' attribute list contains also tuples.
 * Tuples are needed to specify each confix's attributes that contain
 * more than one generator, like confix()[int_ << string] (this
 * generator needs a tuple: tuple<int, string>).
 *
 * The difference between this generator and the one in test case
 * 'bgcolor_stream_test_case' is the use of less << operators and
 * a more clean handling of double quotes.
 */
BOOST_FIXTURE_TEST_CASE(bgcolor_stream_confix_test_case, F)
{
    using repository::confix;
    using fusion::tuple;

    actual_output
        << format(
            "<svg width=" << confix('"', '"')[int_ << string]
            << " height=" << confix('"', '"')[int_ << string]
            << " version=" << confix('"', '"')[float_]
            << " xmlns=" << confix('"', '"')[string]
            << ">",
            tuple<int, std::string>(width, "px"), tuple<int, std::string>(height, "px"), version, xmlns);

    BOOST_CHECK_EQUAL(actual_output.str(), expected_output);
}
/*
 * This test case uses confix to wrap each xml attribute's value
 * inside double quotes.
 *
 * Notice that the generators' attribute list contains also tuples.
 * Tuples are needed to specify each confix's attributes that contain
 * more than one generator, like confix()[int_ << string] (this 
 * generator needs a tuple: tuple<int, string>).
 *
 * The difference between this generator and the one in test case
 * 'bgcolor_stream_test_case' is the use of less << operators and
 * a more clean handling of double quotes.
 */
BOOST_FIXTURE_TEST_CASE(bgcolor_stream_confix_test_case, F)
{
    using repository::confix;
    using fusion::tuple;

    actual_output
	<< format(
	    "<rect x=" << confix('"', '"')[int_]
	    << " y=" << confix('"', '"')[int_]
	    << " width=" << confix('"', '"')[int_ << string]
	    << " height=" << confix('"', '"')[int_ << string]
	    << " style=" << confix('"', '"')["fill: " << string]
	    << "/>",
	    x, y, tuple<int, std::string>(width, "px"), tuple<int, std::string>(height, "px"), bgcolor); 
    
    BOOST_CHECK_EQUAL(actual_output.str(), expected_output);
}
Ejemplo n.º 3
0
/*
 * This test case uses an iterator to receive the generated
 * output. The iterator comes from the std::ostringstream that's
 * been used in the previous test cases, so the output is
 * actually generated into the stream.
 *
 * Using iterators instead of streams has the advantage that
 * more advanced concepts are implemented in karma for them,
 * like rules and grammars.
 */
BOOST_FIXTURE_TEST_CASE(bgcolor_stream_iterator_test_case, F)
{
    using repository::confix;
    using fusion::tuple;

    std::ostream_iterator<char> actual_output_iterator(actual_output);

    generate(
        actual_output_iterator,
        confix("<", ">")[
            "svg width=" << confix('"', '"')[int_ << string]
            << " height=" << confix('"', '"')[int_ << string]
            << " version=" << confix('"', '"')[float_]
            << " xmlns=" << confix('"', '"')[string]],
        tuple<int, std::string>(width, "px"), tuple<int, std::string>(height, "px"), version, xmlns);

    BOOST_CHECK_EQUAL(actual_output.str(), expected_output);
}
/*
 * This test case uses an iterator to receive the generated
 * output. The iterator comes from the std::ostringstream that's
 * been used in the previous test cases, so the output is
 * actually generated into the stream.
 *
 * Using iterators instead of streams has the advantage that
 * more advanced concepts are implemented in karma for them,
 * like rules and grammars.
 */
BOOST_FIXTURE_TEST_CASE(bgcolor_stream_iterator_test_case, F)
{
    using repository::confix;
    using fusion::tuple;

    std::ostream_iterator<char> actual_output_iterator(actual_output);

    generate(
	actual_output_iterator,
	confix("<", "/>")[
	    "rect x=" << confix('"', '"')[int_]
	    << " y=" << confix('"', '"')[int_]
	    << " width=" << confix('"', '"')[int_ << string]
	    << " height=" << confix('"', '"')[int_ << string]
	    << " style=" << confix('"', '"')["fill: " << string]],
	x, y, tuple<int, std::string>(width, "px"), tuple<int, std::string>(height, "px"), bgcolor);

    BOOST_CHECK_EQUAL(actual_output.str(), expected_output);
}