blob: 321a3dc0f7fdf257b6d43601ca69623b324094ef [file] [log] [blame]
Yingdi Yu3168c302015-07-04 16:45:40 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2013-2016 Regents of the University of California.
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
22#include "security/transform/step-source.hpp"
23#include "security/transform/stream-sink.hpp"
24
25#include "boost-test.hpp"
26
27namespace ndn {
28namespace security {
29namespace transform {
30namespace tests {
31
32BOOST_AUTO_TEST_SUITE(Security)
33BOOST_AUTO_TEST_SUITE(Transform)
34BOOST_AUTO_TEST_SUITE(TestStepSource)
35
36BOOST_AUTO_TEST_CASE(Basic)
37{
38 std::string input =
39 "0123456701234567012345670123456701234567012345670123456701234567"
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 const uint8_t* buf = reinterpret_cast<const uint8_t*>(input.data());
60
61 std::stringstream os;
62 StepSource ss;
63 ss >> streamSink(os);
64 BOOST_CHECK_EQUAL(ss.write(buf, 320), 320);
65 BOOST_CHECK_EQUAL(ss.write(buf + 320, 320), 320);
66 BOOST_CHECK_EQUAL(ss.write(buf + 640, 320), 320);
67 BOOST_CHECK_EQUAL(ss.write(buf + 960, 320), 320);
68 ss.end();
69 BOOST_REQUIRE_THROW(ss.write(buf + 960, 320), transform::Error);
70 std::string output = os.str();
71 BOOST_CHECK_EQUAL(input, output);
72}
73
74BOOST_AUTO_TEST_SUITE_END() // TestStepSource
75BOOST_AUTO_TEST_SUITE_END() // Transform
76BOOST_AUTO_TEST_SUITE_END() // Security
77
78} // namespace tests
79} // namespace transform
80} // namespace security
81} // namespace ndn