tylerliu | afb27a0 | 2020-10-06 17:20:06 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2017-2020, Regents of the University of California. |
| 4 | * |
| 5 | * This file is part of ndncert, a certificate management system based on NDN. |
| 6 | * |
| 7 | * ndncert is free software: you can redistribute it and/or modify it under the terms |
| 8 | * of the GNU General Public License as published by the Free Software Foundation, either |
| 9 | * version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndncert 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 General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License along with |
| 16 | * ndncert, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 17 | * |
| 18 | * See AUTHORS.md for complete list of ndncert authors and contributors. |
| 19 | */ |
| 20 | |
Zhiyi Zhang | 8683ec9 | 2020-10-07 18:18:35 -0700 | [diff] [blame] | 21 | #include "name-assignments/assignment-random.hpp" |
| 22 | #include "name-assignments/assignment-param.hpp" |
| 23 | #include "name-assignments/assignment-hash.hpp" |
tylerliu | afb27a0 | 2020-10-06 17:20:06 -0700 | [diff] [blame] | 24 | #include "test-common.hpp" |
| 25 | |
| 26 | namespace ndn { |
| 27 | namespace ndncert { |
| 28 | namespace tests { |
| 29 | |
| 30 | BOOST_AUTO_TEST_SUITE(TestNameAssignment) |
| 31 | BOOST_AUTO_TEST_CASE(NameAssignmentRandom) |
| 32 | { |
Zhiyi Zhang | 8683ec9 | 2020-10-07 18:18:35 -0700 | [diff] [blame] | 33 | AssignmentRandom assignment; |
| 34 | BOOST_CHECK_EQUAL(assignment.assignName(std::vector<std::tuple<std::string, std::string>>()).size(), 1); |
| 35 | BOOST_CHECK_EQUAL(assignment.assignName(std::vector<std::tuple<std::string, std::string>>()).begin()->size(), 1); |
tylerliu | afb27a0 | 2020-10-06 17:20:06 -0700 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | BOOST_AUTO_TEST_CASE(NameAssignmentParam) |
| 39 | { |
Zhiyi Zhang | 8683ec9 | 2020-10-07 18:18:35 -0700 | [diff] [blame] | 40 | AssignmentParam assignment("/abc/xyz"); |
Zhiyi Zhang | cb8acf2 | 2020-10-07 19:35:16 -0700 | [diff] [blame^] | 41 | std::vector<std::tuple<std::string, std::string>> params; |
| 42 | params.emplace_back("abc", "123"); |
| 43 | BOOST_CHECK_EQUAL(assignment.assignName(params).size(), 0); |
| 44 | params.emplace_back("xyz", "789"); |
| 45 | BOOST_CHECK_EQUAL(assignment.assignName(params).size(), 1); |
| 46 | BOOST_CHECK_EQUAL(*assignment.assignName(params).begin(), Name("/123/789")); |
| 47 | params.emplace_back("fake", "456"); |
| 48 | BOOST_CHECK_EQUAL(assignment.assignName(params).size(), 1); |
| 49 | BOOST_CHECK_EQUAL(*assignment.assignName(params).begin(), Name("/123/789")); |
| 50 | params[1] = std::tuple<std::string, std::string>("xyz", ""); |
| 51 | BOOST_CHECK_EQUAL(assignment.assignName(params).size(), 0); |
tylerliu | afb27a0 | 2020-10-06 17:20:06 -0700 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | BOOST_AUTO_TEST_CASE(NameAssignmentHash) |
| 55 | { |
Zhiyi Zhang | cb8acf2 | 2020-10-07 19:35:16 -0700 | [diff] [blame^] | 56 | AssignmentHash assignment("/abc/xyz"); |
| 57 | std::vector<std::tuple<std::string, std::string>> params; |
| 58 | params.emplace_back("abc", "123"); |
| 59 | BOOST_CHECK_EQUAL(assignment.assignName(params).size(), 0); |
| 60 | params.emplace_back("xyz", "789"); |
| 61 | BOOST_CHECK_EQUAL(assignment.assignName(params).size(), 1); |
| 62 | BOOST_CHECK_EQUAL(assignment.assignName(params).begin()->size(), 2); |
| 63 | params.emplace_back("fake", "456"); |
| 64 | BOOST_CHECK_EQUAL(assignment.assignName(params).size(), 1); |
| 65 | BOOST_CHECK_EQUAL(assignment.assignName(params).begin()->size(), 2); |
| 66 | params[1] = std::tuple<std::string, std::string>("xyz", ""); |
| 67 | BOOST_CHECK_EQUAL(assignment.assignName(params).size(), 1); |
| 68 | BOOST_CHECK_EQUAL(assignment.assignName(params).begin()->size(), 2); |
tylerliu | bcd8348 | 2020-10-07 14:45:28 -0700 | [diff] [blame] | 69 | } |
| 70 | |
tylerliu | afb27a0 | 2020-10-06 17:20:06 -0700 | [diff] [blame] | 71 | BOOST_AUTO_TEST_SUITE_END() |
| 72 | |
| 73 | } // namespace tests |
| 74 | } // namespace ndncert |
| 75 | } // namespace ndn |
| 76 | |
| 77 | |