blob: 1446bc94a06578757a5208f622055a65682fa4ec [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/*
3 * Copyright (c) 2013-2018 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-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"
26
Junxiao Shiba6baaf2016-08-20 02:59:20 +000027#include <boost/mpl/integral_c.hpp>
28#include <boost/mpl/vector.hpp>
Yingdi Yu3168c302015-07-04 16:45:40 -070029
30namespace ndn {
31namespace security {
32namespace transform {
33namespace tests {
34
35BOOST_AUTO_TEST_SUITE(Security)
36BOOST_AUTO_TEST_SUITE(Transform)
37BOOST_AUTO_TEST_SUITE(TestStreamSource)
38
39BOOST_AUTO_TEST_CASE(Basic)
40{
41 std::string input =
42 "0123456701234567012345670123456701234567012345670123456701234567"
43 "01234567012345670123456701234567 1234567012345670123456701234567"
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"
60 "0123456701234567012345670123456701234567012345670123456701234567"
61 "0123456701234567012345670123456701234567012345670123456701234567";
62
63 std::stringstream is(input);
64 std::stringstream os;
65 streamSource(is) >> streamSink(os);
66 std::string output = os.str();
67
68 BOOST_CHECK_EQUAL(input, output);
69}
70
Junxiao Shiba6baaf2016-08-20 02:59:20 +000071BOOST_AUTO_TEST_CASE(EmptyStream)
72{
73 std::stringstream is;
74 std::stringstream os;
75 streamSource(is) >> streamSink(os);
76
77 BOOST_CHECK_EQUAL(os.str(), "");
78}
79
80typedef boost::mpl::vector<
81 boost::mpl::integral_c<std::ios_base::iostate, std::ios_base::badbit>,
82 boost::mpl::integral_c<std::ios_base::iostate, std::ios_base::failbit>
83> BadBits;
84
85BOOST_AUTO_TEST_CASE_TEMPLATE(BadStream, BadBit, BadBits)
86{
87 std::stringstream is;
88 is.setstate(BadBit::value);
89 std::stringstream os;
90 BOOST_CHECK_THROW(streamSource(is) >> streamSink(os), transform::Error);
91}
92
Yingdi Yu3168c302015-07-04 16:45:40 -070093BOOST_AUTO_TEST_SUITE_END() // TestStreamSource
94BOOST_AUTO_TEST_SUITE_END() // Transform
95BOOST_AUTO_TEST_SUITE_END() // Security
96
97} // namespace tests
98} // namespace transform
99} // namespace security
100} // namespace ndn