blob: 8f1a23ebc35337e4543d4ed4a25f58bc2eb3ea6d [file] [log] [blame]
Yingdi Yu3168c302015-07-04 16:45:40 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento74daf742018-11-23 18:14:13 -05002/*
Eric Newberry6d024ba2020-06-14 16:10:34 -07003 * Copyright (c) 2013-2020 Regents of the University of California.
Yingdi Yu3168c302015-07-04 16:45:40 -07004 *
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 Pesavento7e780642018-11-24 15:51:34 -050022#include "ndn-cxx/security/transform/buffer-source.hpp"
23#include "ndn-cxx/security/transform/stream-sink.hpp"
Yingdi Yu3168c302015-07-04 16:45:40 -070024
Davide Pesavento7e780642018-11-24 15:51:34 -050025#include "tests/boost-test.hpp"
Yingdi Yu3168c302015-07-04 16:45:40 -070026
27namespace ndn {
28namespace security {
29namespace transform {
30namespace tests {
31
32BOOST_AUTO_TEST_SUITE(Security)
33BOOST_AUTO_TEST_SUITE(Transform)
34BOOST_AUTO_TEST_SUITE(TestBufferSource)
35
36BOOST_AUTO_TEST_CASE(Basic)
37{
38 uint8_t in[16] = {
39 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
40 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
41 };
42
43 std::ostringstream os1;
44 bufferSource(in, sizeof(in)) >> streamSink(os1);
45 std::string out1 = os1.str();
Eric Newberry6d024ba2020-06-14 16:10:34 -070046 BOOST_CHECK_EQUAL_COLLECTIONS(out1.begin(), out1.end(), in, in + sizeof(in));
Yingdi Yu3168c302015-07-04 16:45:40 -070047
48 std::string in2 =
49 "0123456701234567012345670123456701234567012345670123456701234567"
50 "0123456701234567012345670123456701234567012345670123456701234567"
51 "0123456701234567012345670123456701234567012345670123456701234567"
52 "0123456701234567012345670123456701234567012345670123456701234567"
53 "0123456701234567012345670123456701234567012345670123456701234567"
54 "0123456701234567012345670123456701234567012345670123456701234567"
55 "0123456701234567012345670123456701234567012345670123456701234567"
56 "0123456701234567012345670123456701234567012345670123456701234567"
57 "0123456701234567012345670123456701234567012345670123456701234567"
58 "0123456701234567012345670123456701234567012345670123456701234567"
59 "0123456701234567012345670123456701234567012345670123456701234567"
60 "0123456701234567012345670123456701234567012345670123456701234567"
61 "0123456701234567012345670123456701234567012345670123456701234567"
62 "0123456701234567012345670123456701234567012345670123456701234567"
63 "0123456701234567012345670123456701234567012345670123456701234567"
64 "0123456701234567012345670123456701234567012345670123456701234567"
65 "0123456701234567012345670123456701234567012345670123456701234567"
66 "0123456701234567012345670123456701234567012345670123456701234567"
67 "0123456701234567012345670123456701234567012345670123456701234567"
68 "0123456701234567012345670123456701234567012345670123456701234567";
69
70 std::ostringstream os2;
71 bufferSource(in2) >> streamSink(os2);
72 std::string out2 = os2.str();
Eric Newberry6d024ba2020-06-14 16:10:34 -070073 BOOST_CHECK_EQUAL_COLLECTIONS(out2.begin(), out2.end(), in2.begin(), in2.end());
Yingdi Yu3168c302015-07-04 16:45:40 -070074
75 Buffer in3(in, sizeof(in));
76 std::ostringstream os3;
77 bufferSource(in3) >> streamSink(os3);
78 std::string out3 = os3.str();
Eric Newberry6d024ba2020-06-14 16:10:34 -070079 BOOST_CHECK_EQUAL_COLLECTIONS(out3.begin(), out3.end(), in3.begin(), in3.end());
80
81 InputBuffers in4{{in, sizeof(in)}, {reinterpret_cast<const uint8_t*>(in2.data()), in2.size()}};
82 std::ostringstream os4;
83 bufferSource(in4) >> streamSink(os4);
84 std::string out4 = os4.str();
85 BOOST_CHECK_EQUAL(out4.size(), sizeof(in) + in2.size());
86 BOOST_CHECK_EQUAL_COLLECTIONS(out4.begin(), out4.begin() + in4[0].second,
87 in4[0].first, in4[0].first + in4[0].second);
88 BOOST_CHECK_EQUAL_COLLECTIONS(out4.begin() + in4[0].second, out4.end(),
89 in4[1].first, in4[1].first + in4[1].second);
Yingdi Yu3168c302015-07-04 16:45:40 -070090}
91
92BOOST_AUTO_TEST_SUITE_END() // TestBufferSource
93BOOST_AUTO_TEST_SUITE_END() // Transform
94BOOST_AUTO_TEST_SUITE_END() // Security
95
96} // namespace tests
97} // namespace transform
98} // namespace security
99} // namespace ndn