From: Tomek Mrugalski Date: Mon, 22 Oct 2018 20:48:40 +0000 (+0200) Subject: [#65,!88] Some unit-tests written for AdaptorConfig X-Git-Tag: 65-libyang-config-translator_base~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8b8ba201f8aa0593b6ef1a8bb3b6d6d079f4c772;p=thirdparty%2Fkea.git [#65,!88] Some unit-tests written for AdaptorConfig --- diff --git a/src/lib/yang/tests/Makefile.am b/src/lib/yang/tests/Makefile.am index a6764116e2..cd822beeb9 100644 --- a/src/lib/yang/tests/Makefile.am +++ b/src/lib/yang/tests/Makefile.am @@ -18,6 +18,7 @@ TESTS = if HAVE_GTEST TESTS += run_unittests run_unittests_SOURCES = adaptor_unittests.cc +run_unittests_SOURCES += adaptor_config_unittests.cc run_unittests_SOURCES += adaptor_option_unittests.cc run_unittests_SOURCES += adaptor_pool_unittests.cc run_unittests_SOURCES += adaptor_host_unittests.cc diff --git a/src/lib/yang/tests/adaptor_config_unittests.cc b/src/lib/yang/tests/adaptor_config_unittests.cc new file mode 100644 index 0000000000..6a86b0ad33 --- /dev/null +++ b/src/lib/yang/tests/adaptor_config_unittests.cc @@ -0,0 +1,136 @@ +// Copyright (C) 2018 Internet Systems Consortium, Inc. ("ISC") +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include + +#include + +#include +#include + +#include + +using namespace std; +using namespace isc; +using namespace isc::data; +using namespace isc::test; +using namespace isc::yang; + +namespace { + + +/// @brief Fixture class that helps testing AdaptorConfig +class AdaptorConfigTest : public ::testing::Test { +public: + +/// @brief Load an example JSON config +/// +/// @param fname name of the file (expected to be a valid JSON config) +/// @param v6 - false=v4, true=v6 +/// @param result - JSON converted by a AdaptorConfig::preprocess[4/6] +void testFile(const std::string& fname, bool v6, ElementPtr& result) { + ElementPtr json; + ElementPtr reference_json; + + string decommented = decommentJSONfile(fname); + + cout << "Parsing file " << fname << " (" << decommented << ")" << endl; + + EXPECT_NO_THROW(json = Element::fromJSONFile(decommented, true)); + reference_json = moveComments(json); + + // remove the temporary file + EXPECT_NO_THROW(::remove(decommented.c_str())); + + string before = json->str(); + if (v6) { + ASSERT_NO_THROW(AdaptorConfig::preProcess6(json)); + } else { + ASSERT_NO_THROW(AdaptorConfig::preProcess4(json)); + } + string after = json->str(); + + EXPECT_FALSE(before.empty()); + EXPECT_FALSE(after.empty()); + + result = json; +} + +}; + + +TEST_F(AdaptorConfigTest, loadExamples4) { + vector configs = { "advanced.json" , + "backends.json", + "cassandra.json", + "classify.json", + "classify2.json", + "comments.json", + "dhcpv4-over-dhcpv6.json", + "hooks.json", + "leases-expiration.json", + "multiple-options.json", + "mysql-reservations.json", + "pgsql-reservations.json", + "reservations.json", + "several-subnets.json", + "shared-network.json", + "single-subnet.json", + "with-ddns.json" }; + + ElementPtr x; + + for (int i = 0; i configs = { "advanced.json", + "backends.json", + "cassandra.json", + "classify.json", + "classify2.json", + "comments.json", + "dhcpv4-over-dhcpv6.json", + "duid.json", + "hooks.json", + "iPXE.json", + "leases-expiration.json", + "multiple-options.json", + "mysql-reservations.json", + "pgsql-reservations.json", + "reservations.json", + "several-subnets.json", + "shared-network.json", + "simple.json", + "softwire46.json", + "stateless.json", + "with-ddns.json" }; + ElementPtr x; + + for (int i = 0; i