blob: ab3afc3e05b9c424a2f6a0562a5dcd94227b42ee [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
21#include <name-assignments/assignment-random.hpp>
22#include <name-assignments/assignment-param.hpp>
23#include <name-assignments/assignment-hash.hpp>
24#include "test-common.hpp"
25
26namespace ndn {
27namespace ndncert {
28namespace tests {
29
30BOOST_AUTO_TEST_SUITE(TestNameAssignment)
31BOOST_AUTO_TEST_CASE(NameAssignmentRandom)
32{
33 AssignmentRandom randomAssignment;
34 auto func = randomAssignment.getFunction("");
35 BOOST_CHECK_EQUAL(func(std::vector<std::tuple<std::string, std::string>>()).size(), 1);
36 BOOST_CHECK_EQUAL(func(std::vector<std::tuple<std::string, std::string>>()).begin()->size(), 1);
37}
38
39BOOST_AUTO_TEST_CASE(NameAssignmentParam)
40{
41 AssignmentParam paramAssignment;
42 auto func = paramAssignment.getFunction("abc:xyz");
43 std::vector<std::tuple<std::string, std::string>> requirements;
44 requirements.emplace_back("abc", "123");
45 BOOST_CHECK_EQUAL(func(requirements).size(), 0);
46 requirements.emplace_back("xyz", "789");
47 BOOST_CHECK_EQUAL(func(requirements).size(), 1);
48 BOOST_CHECK_EQUAL(*func(requirements).begin(), Name("/123/789"));
49 requirements.emplace_back("fake", "456");
50 BOOST_CHECK_EQUAL(func(requirements).size(), 1);
51 BOOST_CHECK_EQUAL(*func(requirements).begin(), Name("/123/789"));
52 requirements[1] = std::tuple<std::string, std::string>("xyz", "");
53 BOOST_CHECK_EQUAL(func(requirements).size(), 0);
54}
55
56BOOST_AUTO_TEST_CASE(NameAssignmentHash)
57{
58 AssignmentHash hashAssignment;
59 auto func = hashAssignment.getFunction("abc:xyz");
60 std::vector<std::tuple<std::string, std::string>> requirements;
61 requirements.emplace_back("abc", "123");
62 BOOST_CHECK_EQUAL(func(requirements).size(), 0);
63 requirements.emplace_back("xyz", "789");
64 BOOST_CHECK_EQUAL(func(requirements).size(), 1);
65 BOOST_CHECK_EQUAL(func(requirements).begin()->size(), 1);
66 requirements.emplace_back("fake", "456");
67 BOOST_CHECK_EQUAL(func(requirements).size(), 1);
68 BOOST_CHECK_EQUAL(func(requirements).begin()->size(), 1);
69 requirements[1] = std::tuple<std::string, std::string>("xyz", "");
70 BOOST_CHECK_EQUAL(func(requirements).size(), 1);
71 BOOST_CHECK_EQUAL(func(requirements).begin()->size(), 1);
72}
73
74BOOST_AUTO_TEST_SUITE_END()
75
76} // namespace tests
77} // namespace ndncert
78} // namespace ndn
79
80