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 | 720f3ba | 2017-12-29 22:06:29 -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/step-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 | 720f3ba | 2017-12-29 22:06:29 -0500 | [diff] [blame] | 27 | #include <sstream> |
| 28 | |
Davide Pesavento | 47ce2ee | 2023-05-09 01:33:33 -0400 | [diff] [blame] | 29 | namespace ndn::tests { |
| 30 | |
| 31 | using namespace ndn::security::transform; |
Yingdi Yu | 3168c30 | 2015-07-04 16:45:40 -0700 | [diff] [blame] | 32 | |
| 33 | BOOST_AUTO_TEST_SUITE(Security) |
| 34 | BOOST_AUTO_TEST_SUITE(Transform) |
| 35 | BOOST_AUTO_TEST_SUITE(TestStepSource) |
| 36 | |
| 37 | BOOST_AUTO_TEST_CASE(Basic) |
| 38 | { |
Davide Pesavento | 720f3ba | 2017-12-29 22:06:29 -0500 | [diff] [blame] | 39 | const std::string input = |
Yingdi Yu | 3168c30 | 2015-07-04 16:45:40 -0700 | [diff] [blame] | 40 | "0123456701234567012345670123456701234567012345670123456701234567" |
| 41 | "0123456701234567012345670123456701234567012345670123456701234567" |
| 42 | "0123456701234567012345670123456701234567012345670123456701234567" |
| 43 | "0123456701234567012345670123456701234567012345670123456701234567" |
| 44 | "0123456701234567012345670123456701234567012345670123456701234567" |
| 45 | "0123456701234567012345670123456701234567012345670123456701234567" |
| 46 | "0123456701234567012345670123456701234567012345670123456701234567" |
| 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"; |
Davide Pesavento | 765abc9 | 2021-12-27 00:44:04 -0500 | [diff] [blame] | 60 | auto buf = reinterpret_cast<const uint8_t*>(input.data()); |
Yingdi Yu | 3168c30 | 2015-07-04 16:45:40 -0700 | [diff] [blame] | 61 | |
Davide Pesavento | 720f3ba | 2017-12-29 22:06:29 -0500 | [diff] [blame] | 62 | std::ostringstream os; |
Yingdi Yu | 3168c30 | 2015-07-04 16:45:40 -0700 | [diff] [blame] | 63 | StepSource ss; |
| 64 | ss >> streamSink(os); |
Davide Pesavento | 765abc9 | 2021-12-27 00:44:04 -0500 | [diff] [blame] | 65 | BOOST_CHECK_EQUAL(ss.write({buf, 320}), 320); |
| 66 | BOOST_CHECK_EQUAL(ss.write({buf + 320, 320}), 320); |
| 67 | BOOST_CHECK_EQUAL(ss.write({buf + 640, 320}), 320); |
| 68 | BOOST_CHECK_EQUAL(ss.write({buf + 960, 320}), 320); |
Yingdi Yu | 3168c30 | 2015-07-04 16:45:40 -0700 | [diff] [blame] | 69 | ss.end(); |
Davide Pesavento | 765abc9 | 2021-12-27 00:44:04 -0500 | [diff] [blame] | 70 | |
Davide Pesavento | 47ce2ee | 2023-05-09 01:33:33 -0400 | [diff] [blame] | 71 | BOOST_CHECK_THROW(ss.write({buf + 960, 320}), Error); |
Davide Pesavento | 720f3ba | 2017-12-29 22:06:29 -0500 | [diff] [blame] | 72 | BOOST_CHECK_EQUAL(os.str(), input); |
| 73 | } |
| 74 | |
| 75 | BOOST_AUTO_TEST_CASE(EmptyInput) |
| 76 | { |
| 77 | std::ostringstream os; |
| 78 | StepSource ss; |
| 79 | ss >> streamSink(os); |
| 80 | ss.end(); |
Davide Pesavento | 765abc9 | 2021-12-27 00:44:04 -0500 | [diff] [blame] | 81 | |
Davide Pesavento | 720f3ba | 2017-12-29 22:06:29 -0500 | [diff] [blame] | 82 | BOOST_CHECK_EQUAL(os.str(), ""); |
Yingdi Yu | 3168c30 | 2015-07-04 16:45:40 -0700 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | BOOST_AUTO_TEST_SUITE_END() // TestStepSource |
| 86 | BOOST_AUTO_TEST_SUITE_END() // Transform |
| 87 | BOOST_AUTO_TEST_SUITE_END() // Security |
| 88 | |
Davide Pesavento | 47ce2ee | 2023-05-09 01:33:33 -0400 | [diff] [blame] | 89 | } // namespace ndn::tests |