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 | 187e9f9 | 2023-03-20 22:46:22 -0400 | [diff] [blame] | 3 | * Copyright (c) 2013-2023 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 | |
Davide Pesavento | 47ce2ee | 2023-05-09 01:33:33 -0400 | [diff] [blame] | 29 | namespace ndn::tests { |
Davide Pesavento | 25d4f1c | 2020-04-29 23:31:04 -0400 | [diff] [blame] | 30 | |
| 31 | BOOST_AUTO_TEST_SUITE(Util) |
| 32 | BOOST_AUTO_TEST_SUITE(TestOstreamJoiner) |
| 33 | |
| 34 | BOOST_AUTO_TEST_CASE(Basic) |
| 35 | { |
| 36 | boost::test_tools::output_test_stream os; |
| 37 | |
| 38 | auto joiner1 = ostream_joiner<char>(os, ' '); |
| 39 | auto joiner2 = make_ostream_joiner(os, ' '); |
Davide Pesavento | fffdd62 | 2023-08-28 22:50:43 -0400 | [diff] [blame] | 40 | static_assert(std::is_same_v<decltype(joiner1), decltype(joiner2)>); |
Davide Pesavento | 25d4f1c | 2020-04-29 23:31:04 -0400 | [diff] [blame] | 41 | |
| 42 | std::vector<int> v(5); |
| 43 | std::iota(v.begin(), v.end(), 1); |
| 44 | std::copy(v.begin(), v.end(), joiner2); |
| 45 | BOOST_CHECK(os.is_equal("1 2 3 4 5")); |
| 46 | |
| 47 | auto joiner3 = make_ostream_joiner(os, "..."); |
| 48 | std::copy(v.begin(), v.end(), joiner3); |
| 49 | BOOST_CHECK(os.is_equal("1...2...3...4...5")); |
| 50 | |
| 51 | joiner3 = "one"; |
| 52 | BOOST_CHECK(os.is_equal("one")); |
| 53 | joiner3 = "two"; |
| 54 | BOOST_CHECK(os.is_equal("...two")); |
| 55 | ++joiner3 = "three"; |
| 56 | BOOST_CHECK(os.is_equal("...three")); |
| 57 | joiner3++ = "four"; |
| 58 | BOOST_CHECK(os.is_equal("...four")); |
| 59 | |
| 60 | std::copy(v.begin(), v.end(), make_ostream_joiner(os, "")); |
| 61 | BOOST_CHECK(os.is_equal("12345")); |
| 62 | |
| 63 | std::string delimiter("_"); |
| 64 | std::copy(v.begin(), v.end(), make_ostream_joiner(os, delimiter)); |
| 65 | BOOST_CHECK(os.is_equal("1_2_3_4_5")); |
| 66 | } |
| 67 | |
| 68 | BOOST_AUTO_TEST_SUITE_END() // TestOstreamJoiner |
| 69 | BOOST_AUTO_TEST_SUITE_END() // Util |
| 70 | |
Davide Pesavento | 47ce2ee | 2023-05-09 01:33:33 -0400 | [diff] [blame] | 71 | } // namespace ndn::tests |