blob: 157b55a11a4f2b0c66414d3404f92f2edc789873 [file] [log] [blame]
Alexander Afanasyeve5a19b82017-01-30 22:30:46 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
Davide Pesavento74daf742018-11-23 18:14:13 -05003 * Copyright (c) 2013-2018 Regents of the University of California.
Alexander Afanasyeve5a19b82017-01-30 22:30:46 -08004 *
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
28namespace ndn {
29namespace security {
30namespace v2 {
31namespace validator_config {
32namespace tests {
33
34BOOST_AUTO_TEST_SUITE(Security)
35BOOST_AUTO_TEST_SUITE(V2)
36BOOST_AUTO_TEST_SUITE(ValidatorConfig)
37BOOST_AUTO_TEST_SUITE(TestNameRelation)
38
39BOOST_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
48BOOST_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
56BOOST_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
70BOOST_AUTO_TEST_SUITE_END() // TestNameRelation
71BOOST_AUTO_TEST_SUITE_END() // ValidatorConfig
72BOOST_AUTO_TEST_SUITE_END() // V2
73BOOST_AUTO_TEST_SUITE_END() // Security
74
75} // namespace tests
76} // namespace validator_config
77} // namespace v2
78} // namespace security
79} // namespace ndn