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