Davide Pesavento | 25d4f1c | 2020-04-29 23:31:04 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
Davide Pesavento | 541a822 | 2022-03-01 15:08:42 -0500 | [diff] [blame] | 3 | * Copyright (c) 2013-2022 Regents of the University of California. |
Davide Pesavento | 25d4f1c | 2020-04-29 23:31:04 -0400 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 6 | * |
| 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
| 20 | */ |
| 21 | |
| 22 | #include "ndn-cxx/util/ostream-joiner.hpp" |
| 23 | |
| 24 | #include "tests/boost-test.hpp" |
| 25 | |
| 26 | #include <numeric> |
Davide Pesavento | 25d4f1c | 2020-04-29 23:31:04 -0400 | [diff] [blame] | 27 | #include <boost/test/tools/output_test_stream.hpp> |
Davide Pesavento | 25d4f1c | 2020-04-29 23:31:04 -0400 | [diff] [blame] | 28 | |
| 29 | namespace ndn { |
| 30 | namespace tests { |
| 31 | |
| 32 | BOOST_AUTO_TEST_SUITE(Util) |
| 33 | BOOST_AUTO_TEST_SUITE(TestOstreamJoiner) |
| 34 | |
| 35 | BOOST_AUTO_TEST_CASE(Basic) |
| 36 | { |
| 37 | boost::test_tools::output_test_stream os; |
| 38 | |
| 39 | auto joiner1 = ostream_joiner<char>(os, ' '); |
| 40 | auto joiner2 = make_ostream_joiner(os, ' '); |
| 41 | static_assert(std::is_same<decltype(joiner1), decltype(joiner2)>::value, ""); |
| 42 | |
| 43 | std::vector<int> v(5); |
| 44 | std::iota(v.begin(), v.end(), 1); |
| 45 | std::copy(v.begin(), v.end(), joiner2); |
| 46 | BOOST_CHECK(os.is_equal("1 2 3 4 5")); |
| 47 | |
| 48 | auto joiner3 = make_ostream_joiner(os, "..."); |
| 49 | std::copy(v.begin(), v.end(), joiner3); |
| 50 | BOOST_CHECK(os.is_equal("1...2...3...4...5")); |
| 51 | |
| 52 | joiner3 = "one"; |
| 53 | BOOST_CHECK(os.is_equal("one")); |
| 54 | joiner3 = "two"; |
| 55 | BOOST_CHECK(os.is_equal("...two")); |
| 56 | ++joiner3 = "three"; |
| 57 | BOOST_CHECK(os.is_equal("...three")); |
| 58 | joiner3++ = "four"; |
| 59 | BOOST_CHECK(os.is_equal("...four")); |
| 60 | |
| 61 | std::copy(v.begin(), v.end(), make_ostream_joiner(os, "")); |
| 62 | BOOST_CHECK(os.is_equal("12345")); |
| 63 | |
| 64 | std::string delimiter("_"); |
| 65 | std::copy(v.begin(), v.end(), make_ostream_joiner(os, delimiter)); |
| 66 | BOOST_CHECK(os.is_equal("1_2_3_4_5")); |
| 67 | } |
| 68 | |
| 69 | BOOST_AUTO_TEST_SUITE_END() // TestOstreamJoiner |
| 70 | BOOST_AUTO_TEST_SUITE_END() // Util |
| 71 | |
| 72 | } // namespace tests |
| 73 | } // namespace ndn |