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/bool-sink.hpp" |
Yingdi Yu | 3168c30 | 2015-07-04 16:45:40 -0700 | [diff] [blame] | 23 | |
Davide Pesavento | 7e78064 | 2018-11-24 15:51:34 -0500 | [diff] [blame] | 24 | #include "tests/boost-test.hpp" |
Yingdi Yu | 3168c30 | 2015-07-04 16:45:40 -0700 | [diff] [blame] | 25 | |
Davide Pesavento | 47ce2ee | 2023-05-09 01:33:33 -0400 | [diff] [blame] | 26 | namespace ndn::tests { |
| 27 | |
| 28 | using namespace ndn::security::transform; |
Yingdi Yu | 3168c30 | 2015-07-04 16:45:40 -0700 | [diff] [blame] | 29 | |
| 30 | BOOST_AUTO_TEST_SUITE(Security) |
| 31 | BOOST_AUTO_TEST_SUITE(Transform) |
| 32 | BOOST_AUTO_TEST_SUITE(TestBoolSink) |
| 33 | |
| 34 | BOOST_AUTO_TEST_CASE(Basic) |
| 35 | { |
Davide Pesavento | 765abc9 | 2021-12-27 00:44:04 -0500 | [diff] [blame] | 36 | const uint8_t in1[] = {0x00, 0x01}; |
Yingdi Yu | 3168c30 | 2015-07-04 16:45:40 -0700 | [diff] [blame] | 37 | bool value1 = true; |
| 38 | BoolSink sink1(value1); |
Davide Pesavento | 765abc9 | 2021-12-27 00:44:04 -0500 | [diff] [blame] | 39 | BOOST_CHECK_EQUAL(sink1.write({in1, 1}), 1); |
| 40 | BOOST_CHECK_EQUAL(sink1.write({in1 + 1, 1}), 1); |
Yingdi Yu | 3168c30 | 2015-07-04 16:45:40 -0700 | [diff] [blame] | 41 | sink1.end(); |
| 42 | BOOST_CHECK_EQUAL(value1, false); |
Davide Pesavento | 47ce2ee | 2023-05-09 01:33:33 -0400 | [diff] [blame] | 43 | BOOST_CHECK_THROW(sink1.write({in1 + 1, 1}), Error); |
Yingdi Yu | 3168c30 | 2015-07-04 16:45:40 -0700 | [diff] [blame] | 44 | |
Davide Pesavento | 765abc9 | 2021-12-27 00:44:04 -0500 | [diff] [blame] | 45 | const uint8_t in2[] = {0x01, 0x00}; |
Yingdi Yu | 3168c30 | 2015-07-04 16:45:40 -0700 | [diff] [blame] | 46 | bool value2 = false; |
| 47 | BoolSink sink2(value2); |
Davide Pesavento | 765abc9 | 2021-12-27 00:44:04 -0500 | [diff] [blame] | 48 | BOOST_CHECK_EQUAL(sink2.write({in2, 1}), 1); |
| 49 | BOOST_CHECK_EQUAL(sink2.write({in2 + 1, 1}), 1); |
Yingdi Yu | 3168c30 | 2015-07-04 16:45:40 -0700 | [diff] [blame] | 50 | sink2.end(); |
| 51 | BOOST_CHECK_EQUAL(value2, true); |
Davide Pesavento | 47ce2ee | 2023-05-09 01:33:33 -0400 | [diff] [blame] | 52 | BOOST_CHECK_THROW(sink2.write({in2 + 1, 1}), Error); |
Yingdi Yu | 3168c30 | 2015-07-04 16:45:40 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | BOOST_AUTO_TEST_SUITE_END() // TestBoolSink |
| 56 | BOOST_AUTO_TEST_SUITE_END() // Transform |
| 57 | BOOST_AUTO_TEST_SUITE_END() // Security |
| 58 | |
Davide Pesavento | 47ce2ee | 2023-05-09 01:33:33 -0400 | [diff] [blame] | 59 | } // namespace ndn::tests |