update name assignment part
Change-Id: I9655448b2d2ed927e36e55ac49357afa0470e507
diff --git a/tests/unit-tests/ca-module.t.cpp b/tests/unit-tests/ca-module.t.cpp
index 9c198df..4374a86 100644
--- a/tests/unit-tests/ca-module.t.cpp
+++ b/tests/unit-tests/ca-module.t.cpp
@@ -135,7 +135,7 @@
probeResponse.parse();
Name caName;
caName.wireDecode(probeResponse.get(tlv::Name));
- BOOST_CHECK_EQUAL(caName, "/ndn/example");
+ BOOST_CHECK_EQUAL(caName.size(), 2);
});
face.receive(interest);
diff --git a/tests/unit-tests/configuration.t.cpp b/tests/unit-tests/configuration.t.cpp
index 87de3f2..223b52f 100644
--- a/tests/unit-tests/configuration.t.cpp
+++ b/tests/unit-tests/configuration.t.cpp
@@ -54,14 +54,19 @@
config.load("tests/unit-tests/config-files/config-ca-5");
BOOST_CHECK_EQUAL(config.m_redirection->at(0)->getName(),
"/ndn/site1/KEY/%11%BC%22%F4c%15%FF%17/self/%FD%00%00%01Y%C8%14%D9%A5");
-
+ BOOST_CHECK_EQUAL(config.m_heuristic.size(), 3);
std::vector<std::tuple<std::string, std::string>> params;
params.emplace_back("email", "1@1.edu");
params.emplace_back("group", "irl");
params.emplace_back("name", "ndncert");
- BOOST_CHECK_EQUAL(config.m_nameAssignmentFunc(params).size(), 3);
- BOOST_CHECK_EQUAL(config.m_nameAssignmentFunc(params)[0], Name("/irl/1@1.edu"));
- BOOST_CHECK_EQUAL(config.m_nameAssignmentFunc(params)[1], Name("/irl/ndncert"));
+ std::vector<Name> names;
+ for (auto& assignment : config.m_heuristic) {
+ auto results = assignment->assignName(params);
+ names.insert(names.end(), results.begin(), results.end());
+ }
+ BOOST_CHECK_EQUAL(names[0], Name("/irl/1@1.edu"));
+ BOOST_CHECK_EQUAL(names[1], Name("/irl/ndncert"));
+ BOOST_CHECK_EQUAL(names[2].size(), 2);
}
BOOST_AUTO_TEST_CASE(CAConfigFileWithErrors)
diff --git a/tests/unit-tests/name-assignment.t.cpp b/tests/unit-tests/name-assignment.t.cpp
index 1e7dd0e..83c492c 100644
--- a/tests/unit-tests/name-assignment.t.cpp
+++ b/tests/unit-tests/name-assignment.t.cpp
@@ -18,10 +18,9 @@
* See AUTHORS.md for complete list of ndncert authors and contributors.
*/
-#include <name-assignments/assignment-random.hpp>
-#include <name-assignments/assignment-param.hpp>
-#include <name-assignments/assignment-hash.hpp>
-#include <name-assignments/assignment-or.hpp>
+#include "name-assignments/assignment-random.hpp"
+#include "name-assignments/assignment-param.hpp"
+#include "name-assignments/assignment-hash.hpp"
#include "test-common.hpp"
namespace ndn {
@@ -31,79 +30,42 @@
BOOST_AUTO_TEST_SUITE(TestNameAssignment)
BOOST_AUTO_TEST_CASE(NameAssignmentRandom)
{
- AssignmentRandom randomAssignment;
- auto func = randomAssignment.getFunction("");
- BOOST_CHECK_EQUAL(func(std::vector<std::tuple<std::string, std::string>>()).size(), 1);
- BOOST_CHECK_EQUAL(func(std::vector<std::tuple<std::string, std::string>>()).begin()->size(), 1);
+ AssignmentRandom assignment;
+ BOOST_CHECK_EQUAL(assignment.assignName(std::vector<std::tuple<std::string, std::string>>()).size(), 1);
+ BOOST_CHECK_EQUAL(assignment.assignName(std::vector<std::tuple<std::string, std::string>>()).begin()->size(), 1);
}
BOOST_AUTO_TEST_CASE(NameAssignmentParam)
{
- AssignmentParam paramAssignment;
- auto func = paramAssignment.getFunction("/abc/xyz/");
+ AssignmentParam assignment("/abc/xyz");
std::vector<std::tuple<std::string, std::string>> requirements;
requirements.emplace_back("abc", "123");
- BOOST_CHECK_EQUAL(func(requirements).size(), 0);
+ BOOST_CHECK_EQUAL(assignment.assignName(requirements).size(), 0);
requirements.emplace_back("xyz", "789");
- BOOST_CHECK_EQUAL(func(requirements).size(), 1);
- BOOST_CHECK_EQUAL(*func(requirements).begin(), Name("/123/789"));
+ BOOST_CHECK_EQUAL(assignment.assignName(requirements).size(), 1);
+ BOOST_CHECK_EQUAL(*assignment.assignName(requirements).begin(), Name("/123/789"));
requirements.emplace_back("fake", "456");
- BOOST_CHECK_EQUAL(func(requirements).size(), 1);
- BOOST_CHECK_EQUAL(*func(requirements).begin(), Name("/123/789"));
+ BOOST_CHECK_EQUAL(assignment.assignName(requirements).size(), 1);
+ BOOST_CHECK_EQUAL(*assignment.assignName(requirements).begin(), Name("/123/789"));
requirements[1] = std::tuple<std::string, std::string>("xyz", "");
- BOOST_CHECK_EQUAL(func(requirements).size(), 0);
+ BOOST_CHECK_EQUAL(assignment.assignName(requirements).size(), 0);
}
BOOST_AUTO_TEST_CASE(NameAssignmentHash)
{
- AssignmentHash hashAssignment;
- auto func = hashAssignment.getFunction("/abc/xyz");
+ AssignmentHash assignment("/abe/xyz");
std::vector<std::tuple<std::string, std::string>> requirements;
requirements.emplace_back("abc", "123");
- BOOST_CHECK_EQUAL(func(requirements).size(), 0);
+ BOOST_CHECK_EQUAL(assignment.assignName(requirements).size(), 0);
requirements.emplace_back("xyz", "789");
- BOOST_CHECK_EQUAL(func(requirements).size(), 1);
- BOOST_CHECK_EQUAL(func(requirements).begin()->size(), 1);
+ BOOST_CHECK_EQUAL(assignment.assignName(requirements).size(), 1);
+ BOOST_CHECK_EQUAL(assignment.assignName(requirements).begin()->size(), 1);
requirements.emplace_back("fake", "456");
- BOOST_CHECK_EQUAL(func(requirements).size(), 1);
- BOOST_CHECK_EQUAL(func(requirements).begin()->size(), 1);
+ BOOST_CHECK_EQUAL(assignment.assignName(requirements).size(), 1);
+ BOOST_CHECK_EQUAL(assignment.assignName(requirements).begin()->size(), 1);
requirements[1] = std::tuple<std::string, std::string>("xyz", "");
- BOOST_CHECK_EQUAL(func(requirements).size(), 1);
- BOOST_CHECK_EQUAL(func(requirements).begin()->size(), 1);
-}
-
-BOOST_AUTO_TEST_CASE(NameAssignmentOr)
-{
- AssignmentParam paramAssignment;
- AssignmentOr orAssignment;
- std::list<NameAssignmentFunc> func2Subfuncs;
- auto func1 = orAssignment.getFunction(func2Subfuncs);
- BOOST_CHECK_EQUAL(func1(std::vector<std::tuple<std::string, std::string>>()).size(), 0);
-
- auto funcUnit = paramAssignment.getFunction("/abc/xyz/");
- func2Subfuncs.push_back(funcUnit);
- func2Subfuncs.push_back(funcUnit);
- auto func2 = orAssignment.getFunction(func2Subfuncs);
- std::list<NameAssignmentFunc> func3Subfuncs;
- func3Subfuncs.push_back(func2);
- func3Subfuncs.push_back(funcUnit);
- auto func3 = orAssignment.getFunction(func3Subfuncs);
- std::vector<std::tuple<std::string, std::string>> requirements;
- requirements.emplace_back("abc", "123");
- BOOST_CHECK_EQUAL(func3(requirements).size(), 0);
- requirements.emplace_back("xyz", "789");
- BOOST_CHECK_EQUAL(func3(requirements).size(), 3);
-}
-
-BOOST_AUTO_TEST_CASE(NameAssignmentOrOperatorString)
-{
- AssignmentOr orAssignment;
- auto func = orAssignment.getFunction(R"({"param": "/abc/xyz/", "param": "/abc/xyz"})");
- std::vector<std::tuple<std::string, std::string>> requirements;
- requirements.emplace_back("abc", "123");
- BOOST_CHECK_EQUAL(func(requirements).size(), 0);
- requirements.emplace_back("xyz", "789");
- BOOST_CHECK_EQUAL(func(requirements).size(), 2);
+ BOOST_CHECK_EQUAL(assignment.assignName(requirements).size(), 1);
+ BOOST_CHECK_EQUAL(assignment.assignName(requirements).begin()->size(), 1);
}
BOOST_AUTO_TEST_SUITE_END()
diff --git a/tests/unit-tests/ndncert-common.t.cpp b/tests/unit-tests/ndncert-common.t.cpp
deleted file mode 100644
index 40f1bb9..0000000
--- a/tests/unit-tests/ndncert-common.t.cpp
+++ /dev/null
@@ -1,40 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2017-2020, Regents of the University of California.
- *
- * This file is part of ndncert, a certificate management system based on NDN.
- *
- * ndncert is free software: you can redistribute it and/or modify it under the terms
- * of the GNU General Public License as published by the Free Software Foundation, either
- * version 3 of the License, or (at your option) any later version.
- *
- * ndncert is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
- * PARTICULAR PURPOSE. See the GNU General Public License for more details.
- *
- * You should have received copies of the GNU General Public License along with
- * ndncert, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
- *
- * See AUTHORS.md for complete list of ndncert authors and contributors.
- */
-
-#include "ndncert-common.hpp"
-#include "test-common.hpp"
-
-namespace ndn {
-namespace ndncert {
-namespace tests {
-
-BOOST_AUTO_TEST_SUITE(TestCommon)
-
-BOOST_AUTO_TEST_CASE(EncodingDecoding) {
- const uint8_t str[] = {0xbc, 0x22, 0xf3, 0xf0, 0x5c, 0xc4, 0x0d, 0xb9,
- 0x31, 0x1e, 0x41, 0x92, 0x96, 0x6f, 0xee, 0x92};
- BOOST_CHECK_EQUAL(hexlify(str, sizeof(str)), "bc22f3f05cc40db9311e4192966fee92");
-}
-
-BOOST_AUTO_TEST_SUITE_END() // TestCommon
-
-} // namespace tests
-} // namespace ndncert
-} // namespace ndn