Junxiao Shi | 4ce0bcf | 2016-09-03 07:09:03 +0000 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | a84f464 | 2017-08-23 16:14:51 -0400 | [diff] [blame] | 2 | /* |
Davide Pesavento | 765abc9 | 2021-12-27 00:44:04 -0500 | [diff] [blame] | 3 | * Copyright (c) 2013-2021 Regents of the University of California. |
Junxiao Shi | 4ce0bcf | 2016-09-03 07:09:03 +0000 | [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 | |
Davide Pesavento | 7e78064 | 2018-11-24 15:51:34 -0500 | [diff] [blame] | 22 | #include "ndn-cxx/security/transform/strip-space.hpp" |
Junxiao Shi | 4ce0bcf | 2016-09-03 07:09:03 +0000 | [diff] [blame] | 23 | |
Davide Pesavento | 7e78064 | 2018-11-24 15:51:34 -0500 | [diff] [blame] | 24 | #include "ndn-cxx/encoding/buffer-stream.hpp" |
| 25 | #include "ndn-cxx/security/transform/step-source.hpp" |
| 26 | #include "ndn-cxx/security/transform/stream-sink.hpp" |
| 27 | |
| 28 | #include "tests/boost-test.hpp" |
Junxiao Shi | 4ce0bcf | 2016-09-03 07:09:03 +0000 | [diff] [blame] | 29 | |
| 30 | namespace ndn { |
| 31 | namespace security { |
| 32 | namespace transform { |
| 33 | namespace tests { |
| 34 | |
| 35 | BOOST_AUTO_TEST_SUITE(Security) |
| 36 | BOOST_AUTO_TEST_SUITE(Transform) |
| 37 | BOOST_AUTO_TEST_SUITE(TestStripSpace) |
| 38 | |
| 39 | BOOST_AUTO_TEST_CASE(Basic) |
| 40 | { |
| 41 | const char* input = R"STR( |
| 42 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor |
| 43 | incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud |
| 44 | exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute |
| 45 | irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla |
| 46 | pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia |
| 47 | deserunt mollit anim id est laborum. |
| 48 | )STR"; |
Davide Pesavento | 765abc9 | 2021-12-27 00:44:04 -0500 | [diff] [blame] | 49 | const size_t inputLen = strlen(input); |
Junxiao Shi | 4ce0bcf | 2016-09-03 07:09:03 +0000 | [diff] [blame] | 50 | |
| 51 | OBufferStream os; |
| 52 | StepSource source; |
| 53 | source >> stripSpace() >> streamSink(os); |
| 54 | |
| 55 | for (size_t offset = 0; offset < inputLen; offset += 40) { |
Davide Pesavento | 765abc9 | 2021-12-27 00:44:04 -0500 | [diff] [blame] | 56 | source.write({reinterpret_cast<const uint8_t*>(input + offset), |
| 57 | std::min<size_t>(40, inputLen - offset)}); |
Junxiao Shi | 4ce0bcf | 2016-09-03 07:09:03 +0000 | [diff] [blame] | 58 | } |
| 59 | source.end(); |
| 60 | |
Davide Pesavento | 765abc9 | 2021-12-27 00:44:04 -0500 | [diff] [blame] | 61 | const std::string expected( |
Junxiao Shi | 4ce0bcf | 2016-09-03 07:09:03 +0000 | [diff] [blame] | 62 | "Loremipsumdolorsitamet,consecteturadipiscingelit,seddoeiusmodtemporincididuntutl" |
| 63 | "aboreetdoloremagnaaliqua.Utenimadminimveniam,quisnostrudexercitationullamcolabor" |
| 64 | "isnisiutaliquipexeacommodoconsequat.Duisauteiruredolorinreprehenderitinvoluptate" |
| 65 | "velitessecillumdoloreeufugiatnullapariatur.Excepteursintoccaecatcupidatatnonproi" |
| 66 | "dent,suntinculpaquiofficiadeseruntmollitanimidestlaborum."); |
| 67 | ConstBufferPtr buf = os.buf(); |
Davide Pesavento | 5d0b010 | 2017-10-07 13:43:16 -0400 | [diff] [blame] | 68 | BOOST_CHECK_EQUAL(std::string(buf->get<char>(), buf->size()), expected); |
Junxiao Shi | 4ce0bcf | 2016-09-03 07:09:03 +0000 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | BOOST_AUTO_TEST_SUITE_END() // TestStripSpace |
| 72 | BOOST_AUTO_TEST_SUITE_END() // Transform |
| 73 | BOOST_AUTO_TEST_SUITE_END() // Security |
| 74 | |
| 75 | } // namespace tests |
| 76 | } // namespace transform |
| 77 | } // namespace security |
| 78 | } // namespace ndn |