Yingdi Yu | 3168c30 | 2015-07-04 16:45:40 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 74daf74 | 2018-11-23 18:14:13 -0500 | [diff] [blame] | 2 | /* |
Davide Pesavento | 47ce2ee | 2023-05-09 01:33:33 -0400 | [diff] [blame] | 3 | * Copyright (c) 2013-2023 Regents of the University of California. |
Yingdi Yu | 3168c30 | 2015-07-04 16:45:40 -0700 | [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/buffer-source.hpp" |
| 23 | #include "ndn-cxx/security/transform/stream-sink.hpp" |
Yingdi Yu | 3168c30 | 2015-07-04 16:45:40 -0700 | [diff] [blame] | 24 | |
Davide Pesavento | 7e78064 | 2018-11-24 15:51:34 -0500 | [diff] [blame] | 25 | #include "tests/boost-test.hpp" |
Yingdi Yu | 3168c30 | 2015-07-04 16:45:40 -0700 | [diff] [blame] | 26 | |
Davide Pesavento | 47ce2ee | 2023-05-09 01:33:33 -0400 | [diff] [blame] | 27 | namespace ndn::tests { |
| 28 | |
| 29 | using namespace ndn::security::transform; |
Yingdi Yu | 3168c30 | 2015-07-04 16:45:40 -0700 | [diff] [blame] | 30 | |
| 31 | BOOST_AUTO_TEST_SUITE(Security) |
| 32 | BOOST_AUTO_TEST_SUITE(Transform) |
| 33 | BOOST_AUTO_TEST_SUITE(TestBufferSource) |
| 34 | |
| 35 | BOOST_AUTO_TEST_CASE(Basic) |
| 36 | { |
Davide Pesavento | 765abc9 | 2021-12-27 00:44:04 -0500 | [diff] [blame] | 37 | const uint8_t in[] = { |
Yingdi Yu | 3168c30 | 2015-07-04 16:45:40 -0700 | [diff] [blame] | 38 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 39 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f |
| 40 | }; |
Yingdi Yu | 3168c30 | 2015-07-04 16:45:40 -0700 | [diff] [blame] | 41 | std::ostringstream os1; |
Davide Pesavento | 765abc9 | 2021-12-27 00:44:04 -0500 | [diff] [blame] | 42 | bufferSource(in) >> streamSink(os1); |
Yingdi Yu | 3168c30 | 2015-07-04 16:45:40 -0700 | [diff] [blame] | 43 | std::string out1 = os1.str(); |
Eric Newberry | 6d024ba | 2020-06-14 16:10:34 -0700 | [diff] [blame] | 44 | BOOST_CHECK_EQUAL_COLLECTIONS(out1.begin(), out1.end(), in, in + sizeof(in)); |
Yingdi Yu | 3168c30 | 2015-07-04 16:45:40 -0700 | [diff] [blame] | 45 | |
Davide Pesavento | 765abc9 | 2021-12-27 00:44:04 -0500 | [diff] [blame] | 46 | const std::string in2 = |
Yingdi Yu | 3168c30 | 2015-07-04 16:45:40 -0700 | [diff] [blame] | 47 | "0123456701234567012345670123456701234567012345670123456701234567" |
| 48 | "0123456701234567012345670123456701234567012345670123456701234567" |
| 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"; |
Yingdi Yu | 3168c30 | 2015-07-04 16:45:40 -0700 | [diff] [blame] | 67 | std::ostringstream os2; |
| 68 | bufferSource(in2) >> streamSink(os2); |
| 69 | std::string out2 = os2.str(); |
Eric Newberry | 6d024ba | 2020-06-14 16:10:34 -0700 | [diff] [blame] | 70 | BOOST_CHECK_EQUAL_COLLECTIONS(out2.begin(), out2.end(), in2.begin(), in2.end()); |
Yingdi Yu | 3168c30 | 2015-07-04 16:45:40 -0700 | [diff] [blame] | 71 | |
Davide Pesavento | 765abc9 | 2021-12-27 00:44:04 -0500 | [diff] [blame] | 72 | std::vector<uint8_t> in3(in, in + sizeof(in)); |
Yingdi Yu | 3168c30 | 2015-07-04 16:45:40 -0700 | [diff] [blame] | 73 | std::ostringstream os3; |
| 74 | bufferSource(in3) >> streamSink(os3); |
| 75 | std::string out3 = os3.str(); |
Eric Newberry | 6d024ba | 2020-06-14 16:10:34 -0700 | [diff] [blame] | 76 | BOOST_CHECK_EQUAL_COLLECTIONS(out3.begin(), out3.end(), in3.begin(), in3.end()); |
| 77 | |
Davide Pesavento | 35c6379 | 2022-01-17 02:06:03 -0500 | [diff] [blame] | 78 | InputBuffers in4{{in}, {reinterpret_cast<const uint8_t*>(in2.data()), in2.size()}}; |
Eric Newberry | 6d024ba | 2020-06-14 16:10:34 -0700 | [diff] [blame] | 79 | std::ostringstream os4; |
| 80 | bufferSource(in4) >> streamSink(os4); |
| 81 | std::string out4 = os4.str(); |
| 82 | BOOST_CHECK_EQUAL(out4.size(), sizeof(in) + in2.size()); |
Davide Pesavento | 765abc9 | 2021-12-27 00:44:04 -0500 | [diff] [blame] | 83 | BOOST_CHECK_EQUAL_COLLECTIONS(out4.begin(), out4.begin() + sizeof(in), |
| 84 | in4[0].begin(), in4[0].end()); |
| 85 | BOOST_CHECK_EQUAL_COLLECTIONS(out4.begin() + sizeof(in), out4.end(), |
| 86 | in4[1].begin(), in4[1].end()); |
Yingdi Yu | 3168c30 | 2015-07-04 16:45:40 -0700 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | BOOST_AUTO_TEST_SUITE_END() // TestBufferSource |
| 90 | BOOST_AUTO_TEST_SUITE_END() // Transform |
| 91 | BOOST_AUTO_TEST_SUITE_END() // Security |
| 92 | |
Davide Pesavento | 47ce2ee | 2023-05-09 01:33:33 -0400 | [diff] [blame] | 93 | } // namespace ndn::tests |