When multiple ItemAttributes::operator() invocations appear on the same expression, they are not always evaluated left-to-right, causing incorrect text output. refs #3864 Change-Id: I4c99c5bc4a76b4becf83f368c9f253c0b254fc05
106 lines
3.0 KiB
C++
106 lines
3.0 KiB
C++
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
|
/**
|
|
* Copyright (c) 2014-2017, Regents of the University of California,
|
|
* Arizona Board of Regents,
|
|
* Colorado State University,
|
|
* University Pierre & Marie Curie, Sorbonne University,
|
|
* Washington University in St. Louis,
|
|
* Beijing Institute of Technology,
|
|
* The University of Memphis.
|
|
*
|
|
* This file is part of NFD (Named Data Networking Forwarding Daemon).
|
|
* See AUTHORS.md for complete list of NFD authors and contributors.
|
|
*
|
|
* NFD is free software: you can redistribute it and/or modify it under the terms
|
|
* of the GNU General Public License as published by the Free Software Foundation,
|
|
* either version 3 of the License, or (at your option) any later version.
|
|
*
|
|
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along with
|
|
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include "nfdc/format-helpers.hpp"
|
|
|
|
#include "tests/test-common.hpp"
|
|
|
|
namespace nfd {
|
|
namespace tools {
|
|
namespace nfdc {
|
|
namespace tests {
|
|
|
|
using boost::test_tools::output_test_stream;
|
|
|
|
BOOST_AUTO_TEST_SUITE(Nfdc)
|
|
BOOST_AUTO_TEST_SUITE(TestFormatHelpers)
|
|
|
|
BOOST_AUTO_TEST_SUITE(Xml)
|
|
|
|
BOOST_AUTO_TEST_CASE(TextEscaping)
|
|
{
|
|
output_test_stream os;
|
|
os << xml::Text{"\"less than\" & 'greater than' surround XML <element> tag name"};
|
|
|
|
BOOST_CHECK(os.is_equal(""less than" & 'greater than'"
|
|
" surround XML <element> tag name"));
|
|
}
|
|
|
|
BOOST_AUTO_TEST_SUITE_END() // Xml
|
|
|
|
BOOST_AUTO_TEST_SUITE(Text)
|
|
|
|
BOOST_AUTO_TEST_CASE(Space)
|
|
{
|
|
output_test_stream os;
|
|
os << 'A' << text::Spaces{-1} << 'B' << text::Spaces{0} << 'C' << text::Spaces{5} << 'D';
|
|
|
|
BOOST_CHECK(os.is_equal("ABC D"));
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(Sep)
|
|
{
|
|
output_test_stream os;
|
|
text::Separator sep(",");
|
|
for (int i = 1; i <= 3; ++i) {
|
|
os << sep << i;
|
|
}
|
|
|
|
BOOST_CHECK(os.is_equal("1,2,3"));
|
|
}
|
|
|
|
static void
|
|
printItemAttributes(std::ostream& os, bool wantMultiLine)
|
|
{
|
|
text::ItemAttributes ia(wantMultiLine, 3);
|
|
os << ia("id") << 500
|
|
<< ia("uri") << "udp4://192.0.2.1:6363"
|
|
<< ia.end();
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(ItemAttributesSingleLine)
|
|
{
|
|
output_test_stream os;
|
|
printItemAttributes(os, false);
|
|
BOOST_CHECK(os.is_equal("id=500 uri=udp4://192.0.2.1:6363"));
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(ItemAttributesMultiLine)
|
|
{
|
|
output_test_stream os;
|
|
printItemAttributes(os, true);
|
|
BOOST_CHECK(os.is_equal(" id=500\nuri=udp4://192.0.2.1:6363\n"));
|
|
}
|
|
|
|
BOOST_AUTO_TEST_SUITE_END() // Text
|
|
|
|
BOOST_AUTO_TEST_SUITE_END() // TestFormatHelpers
|
|
BOOST_AUTO_TEST_SUITE_END() // Nfdc
|
|
|
|
} // namespace tests
|
|
} // namespace nfdc
|
|
} // namespace tools
|
|
} // namespace nfd
|