blob: b79012dc5a1f233c9ce9e93a3874d99282823e59 [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/*
Davide Pesavento47ce2ee2023-05-09 01:33:33 -04003 * Copyright (c) 2013-2023 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/stream-sink.hpp"
Yingdi Yu3168c302015-07-04 16:45:40 -070023
Davide Pesavento7e780642018-11-24 15:51:34 -050024#include "tests/boost-test.hpp"
Yingdi Yu3168c302015-07-04 16:45:40 -070025
Davide Pesavento47ce2ee2023-05-09 01:33:33 -040026namespace ndn::tests {
27
28using namespace ndn::security::transform;
Yingdi Yu3168c302015-07-04 16:45:40 -070029
30BOOST_AUTO_TEST_SUITE(Security)
31BOOST_AUTO_TEST_SUITE(Transform)
32BOOST_AUTO_TEST_SUITE(TestStreamSink)
33
34BOOST_AUTO_TEST_CASE(Basic)
35{
Davide Pesavento765abc92021-12-27 00:44:04 -050036 const uint8_t in[] = {
Yingdi Yu3168c302015-07-04 16:45:40 -070037 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
Davide Pesavento765abc92021-12-27 00:44:04 -050038 0x20, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
Yingdi Yu3168c302015-07-04 16:45:40 -070039 };
40 std::ostringstream os;
41 StreamSink sink(os);
Davide Pesavento765abc92021-12-27 00:44:04 -050042 BOOST_CHECK_EQUAL(sink.write({in, 4}), 4);
43 BOOST_CHECK_EQUAL(sink.write({in + 4, 4}), 4);
44 BOOST_CHECK_EQUAL(sink.write({in + 8, 4}), 4);
45 BOOST_CHECK_EQUAL(sink.write({in + 12, 4}), 4);
Yingdi Yu3168c302015-07-04 16:45:40 -070046 sink.end();
Davide Pesavento765abc92021-12-27 00:44:04 -050047
Yingdi Yu3168c302015-07-04 16:45:40 -070048 std::string out = os.str();
49 BOOST_CHECK_EQUAL_COLLECTIONS(in, in + sizeof(in), out.begin(), out.end());
Davide Pesavento47ce2ee2023-05-09 01:33:33 -040050 BOOST_CHECK_THROW(sink.write({in + 8, 8}), Error);
Yingdi Yu3168c302015-07-04 16:45:40 -070051}
52
53BOOST_AUTO_TEST_SUITE_END() // TestStreamSink
54BOOST_AUTO_TEST_SUITE_END() // Transform
55BOOST_AUTO_TEST_SUITE_END() // Security
56
Davide Pesavento47ce2ee2023-05-09 01:33:33 -040057} // namespace ndn::tests