Alexander Afanasyev | e5a19b8 | 2017-01-30 22:30:46 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
Davide Pesavento | 74daf74 | 2018-11-23 18:14:13 -0500 | [diff] [blame] | 3 | * Copyright (c) 2013-2018 Regents of the University of California. |
Alexander Afanasyev | e5a19b8 | 2017-01-30 22:30:46 -0800 | [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 | |
| 22 | #include "security/v2/validator-config/name-relation.hpp" |
| 23 | |
| 24 | #include "boost-test.hpp" |
| 25 | |
| 26 | #include <boost/lexical_cast.hpp> |
| 27 | |
| 28 | namespace ndn { |
| 29 | namespace security { |
| 30 | namespace v2 { |
| 31 | namespace validator_config { |
| 32 | namespace tests { |
| 33 | |
| 34 | BOOST_AUTO_TEST_SUITE(Security) |
| 35 | BOOST_AUTO_TEST_SUITE(V2) |
| 36 | BOOST_AUTO_TEST_SUITE(ValidatorConfig) |
| 37 | BOOST_AUTO_TEST_SUITE(TestNameRelation) |
| 38 | |
| 39 | BOOST_AUTO_TEST_CASE(ToString) |
| 40 | { |
| 41 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(NameRelation::EQUAL), "equal"); |
| 42 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(NameRelation::IS_PREFIX_OF), |
| 43 | "is-prefix-of"); |
| 44 | BOOST_CHECK_EQUAL(boost::lexical_cast<std::string>(NameRelation::IS_STRICT_PREFIX_OF), |
| 45 | "is-strict-prefix-of"); |
| 46 | } |
| 47 | |
| 48 | BOOST_AUTO_TEST_CASE(FromString) |
| 49 | { |
| 50 | BOOST_CHECK_EQUAL(getNameRelationFromString("equal"), NameRelation::EQUAL); |
| 51 | BOOST_CHECK_EQUAL(getNameRelationFromString("is-prefix-of"), NameRelation::IS_PREFIX_OF); |
| 52 | BOOST_CHECK_EQUAL(getNameRelationFromString("is-strict-prefix-of"), NameRelation::IS_STRICT_PREFIX_OF); |
| 53 | BOOST_CHECK_THROW(getNameRelationFromString("unknown"), validator_config::Error); |
| 54 | } |
| 55 | |
| 56 | BOOST_AUTO_TEST_CASE(CheckRelation) |
| 57 | { |
| 58 | BOOST_CHECK(checkNameRelation(NameRelation::EQUAL, "/prefix", "/prefix")); |
| 59 | BOOST_CHECK(!checkNameRelation(NameRelation::EQUAL, "/prefix", "/prefix/other")); |
| 60 | |
| 61 | BOOST_CHECK(checkNameRelation(NameRelation::IS_PREFIX_OF, "/prefix", "/prefix")); |
| 62 | BOOST_CHECK(checkNameRelation(NameRelation::IS_PREFIX_OF, "/prefix", "/prefix/other")); |
| 63 | BOOST_CHECK(!checkNameRelation(NameRelation::IS_PREFIX_OF, "/prefix/other", "/prefix")); |
| 64 | |
| 65 | BOOST_CHECK(!checkNameRelation(NameRelation::IS_STRICT_PREFIX_OF, "/prefix", "/prefix")); |
| 66 | BOOST_CHECK(checkNameRelation(NameRelation::IS_STRICT_PREFIX_OF, "/prefix", "/prefix/other")); |
| 67 | BOOST_CHECK(!checkNameRelation(NameRelation::IS_STRICT_PREFIX_OF, "/prefix/other", "/prefix")); |
| 68 | } |
| 69 | |
| 70 | BOOST_AUTO_TEST_SUITE_END() // TestNameRelation |
| 71 | BOOST_AUTO_TEST_SUITE_END() // ValidatorConfig |
| 72 | BOOST_AUTO_TEST_SUITE_END() // V2 |
| 73 | BOOST_AUTO_TEST_SUITE_END() // Security |
| 74 | |
| 75 | } // namespace tests |
| 76 | } // namespace validator_config |
| 77 | } // namespace v2 |
| 78 | } // namespace security |
| 79 | } // namespace ndn |