blob: 8c690f5224f0e4ed1b7ec9045c19ad4715bf78cb [file] [log] [blame]
tylerliuafb27a02020-10-06 17:20:06 -07001/* -*- 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 Zhang8683ec92020-10-07 18:18:35 -070021#include "name-assignments/assignment-random.hpp"
22#include "name-assignments/assignment-param.hpp"
23#include "name-assignments/assignment-hash.hpp"
tylerliuafb27a02020-10-06 17:20:06 -070024#include "test-common.hpp"
25
26namespace ndn {
27namespace ndncert {
28namespace tests {
29
30BOOST_AUTO_TEST_SUITE(TestNameAssignment)
31BOOST_AUTO_TEST_CASE(NameAssignmentRandom)
32{
Zhiyi Zhang8683ec92020-10-07 18:18:35 -070033 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);
tylerliuafb27a02020-10-06 17:20:06 -070036}
37
38BOOST_AUTO_TEST_CASE(NameAssignmentParam)
39{
Zhiyi Zhang8683ec92020-10-07 18:18:35 -070040 AssignmentParam assignment("/abc/xyz");
Zhiyi Zhangcb8acf22020-10-07 19:35:16 -070041 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);
tylerliuafb27a02020-10-06 17:20:06 -070052}
53
54BOOST_AUTO_TEST_CASE(NameAssignmentHash)
55{
Zhiyi Zhangcb8acf22020-10-07 19:35:16 -070056 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);
tylerliubcd83482020-10-07 14:45:28 -070069}
70
tylerliuafb27a02020-10-06 17:20:06 -070071BOOST_AUTO_TEST_SUITE_END()
72
73} // namespace tests
74} // namespace ndncert
75} // namespace ndn
76
77