From: Francis Dupont Date: Thu, 16 Dec 2021 21:38:03 +0000 (+0100) Subject: [#2084] Added log checking X-Git-Tag: Kea-2.1.2~181 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ab4609bddaa2871951d160bba4bd76b5fbbe47f4;p=thirdparty%2Fkea.git [#2084] Added log checking --- diff --git a/src/bin/agent/tests/parser_unittests.cc b/src/bin/agent/tests/parser_unittests.cc index 756760fa64..a896549f9f 100644 --- a/src/bin/agent/tests/parser_unittests.cc +++ b/src/bin/agent/tests/parser_unittests.cc @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -857,8 +858,23 @@ TEST(ParserTest, duplicateMapEntries) { cout << "checked " << cnt << " duplicated map entries\n"; } +/// @brief Test fixture for trailing commas. +class TrailingCommasTest : public isc::dhcp::test::LogContentTest { +public: + /// @brief Add a log entry. + /// + /// @param loc Location of the trailing comma. + void addLog(const string& loc) { + string log = "CTRL_AGENT_CONFIG_SYNTAX_WARNING Control Agent "; + log += "configuration syntax warning: " + loc; + log += ": Extraneous comma. "; + log += "A piece of configuration may have been omitted."; + addString(log); + } +}; + // Test that trailing commas are allowed. -TEST(ParserTest, trailingCommas) { +TEST_F(TrailingCommasTest, tests) { string txt(R"({ "Control-agent": { "control-sockets": { @@ -893,6 +909,18 @@ TEST(ParserTest, trailingCommas) { })"); testParser(txt, ParserContext::PARSER_AGENT, false); + addLog(":6.30"); + addLog(":10.30"); + addLog(":14.30"); + addLog(":15.8"); + addLog(":25.31"); + addLog(":26.12"); + addLog(":28.28"); + addLog(":29.8"); + addLog(":30.6"); + addLog(":31.4"); + EXPECT_TRUE(checkFile()); + // Test with many consecutive commas. boost::replace_all(txt, ",", ",,,,"); testParser(txt, ParserContext::PARSER_AGENT, false); diff --git a/src/bin/d2/tests/parser_unittest.cc b/src/bin/d2/tests/parser_unittest.cc index 2e122c4a2f..5ad96bc66d 100644 --- a/src/bin/d2/tests/parser_unittest.cc +++ b/src/bin/d2/tests/parser_unittest.cc @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -807,8 +808,23 @@ TEST(ParserTest, duplicateMapEntries) { cout << "checked " << cnt << " duplicated map entries\n"; } +/// @brief Test fixture for trailing commas. +class TrailingCommasTest : public isc::dhcp::test::LogContentTest { +public: + /// @brief Add a log entry. + /// + /// @param loc Location of the trailing comma. + void addLog(const string& loc) { + string log = "DHCP_DDNS_CONFIG_SYNTAX_WARNING DHCP-DDNS server "; + log += "configuration syntax warning: " + loc; + log += ": Extraneous comma. "; + log += "A piece of configuration may have been omitted."; + addString(log); + } +}; + // Test that trailing commas are allowed. -TEST(ParserTest, trailingCommas) { +TEST_F(TrailingCommasTest, tests) { string txt(R"({ "DhcpDdns": { "forward-ddns": {}, @@ -837,6 +853,14 @@ TEST(ParserTest, trailingCommas) { })"); testParser(txt, D2ParserContext::PARSER_DHCPDDNS, false); + addLog(":11.12"); + addLog(":13.28"); + addLog(":14.8"); + addLog(":22.45"); + addLog(":23.8"); + addLog(":25.4"); + EXPECT_TRUE(checkFile()); + // Test with many consecutive commas. boost::replace_all(txt, ",", ",,,,"); testParser(txt, D2ParserContext::PARSER_DHCPDDNS, false); diff --git a/src/bin/dhcp4/tests/parser_unittest.cc b/src/bin/dhcp4/tests/parser_unittest.cc index bbed9e3ed8..03fa55d7ec 100644 --- a/src/bin/dhcp4/tests/parser_unittest.cc +++ b/src/bin/dhcp4/tests/parser_unittest.cc @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -876,8 +877,23 @@ TEST(ParserTest, duplicateMapEntries) { cout << "checked " << cnt << " duplicated map entries\n"; } +/// @brief Test fixture for trailing commas. +class TrailingCommasTest : public isc::dhcp::test::LogContentTest { +public: + /// @brief Add a log entry. + /// + /// @param loc Location of the trailing comma. + void addLog(const string& loc) { + string log = "DHCP4_CONFIG_SYNTAX_WARNING configuration syntax "; + log += "warning: " + loc; + log += ": Extraneous comma. "; + log += "A piece of configuration may have been omitted."; + addString(log); + } +}; + // Test that trailing commas are allowed. -TEST(ParserTest, trailingCommas) { +TEST_F(TrailingCommasTest, tests) { string txt(R"({ "Dhcp4": { "control-socket": { @@ -930,6 +946,24 @@ TEST(ParserTest, trailingCommas) { })"); testParser(txt, Parser4Context::PARSER_DHCP4, false); + addLog(":5.28"); + addLog(":9.63"); + addLog(":10.8"); + addLog(":14.15"); + addLog(":15.8"); + addLog(":20.24"); + addLog(":28.31"); + addLog(":29.12"); + addLog(":31.28"); + addLog(":32.8"); + addLog(":43.37"); + addLog(":44.12"); + addLog(":46.35"); + addLog(":47.8"); + addLog(":48.6"); + addLog(":49.4"); + EXPECT_TRUE(checkFile()); + // Test with many consecutive commas. boost::replace_all(txt, ",", ",,,,"); testParser(txt, Parser4Context::PARSER_DHCP4, false); diff --git a/src/bin/dhcp6/tests/parser_unittest.cc b/src/bin/dhcp6/tests/parser_unittest.cc index d1783b27b8..927f70a5af 100644 --- a/src/bin/dhcp6/tests/parser_unittest.cc +++ b/src/bin/dhcp6/tests/parser_unittest.cc @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -866,8 +867,23 @@ TEST(ParserTest, duplicateMapEntries) { cout << "checked " << cnt << " duplicated map entries\n"; } +/// @brief Test fixture for trailing commas. +class TrailingCommasTest : public isc::dhcp::test::LogContentTest { +public: + /// @brief Add a log entry. + /// + /// @param loc Location of the trailing comma. + void addLog(const string& loc) { + string log = "DHCP6_CONFIG_SYNTAX_WARNING configuration syntax "; + log += "warning: " + loc; + log += ": Extraneous comma. "; + log += "A piece of configuration may have been omitted."; + addString(log); + } +}; + // Test that trailing commas are allowed. -TEST(ParserTest, trailingCommas) { +TEST_F(TrailingCommasTest, tests) { string txt(R"({ "Dhcp6": { "control-socket": { @@ -920,6 +936,24 @@ TEST(ParserTest, trailingCommas) { })"); testParser(txt, Parser6Context::PARSER_DHCP6, false); + addLog(":5.28"); + addLog(":9.63"); + addLog(":10.8"); + addLog(":14.15"); + addLog(":15.8"); + addLog(":20.24"); + addLog(":28.31"); + addLog(":29.12"); + addLog(":31.28"); + addLog(":32.8"); + addLog(":43.38"); + addLog(":44.12"); + addLog(":46.36"); + addLog(":47.8"); + addLog(":48.6"); + addLog(":49.4"); + EXPECT_TRUE(checkFile()); + // Test with many consecutive commas. boost::replace_all(txt, ",", ",,,,"); testParser(txt, Parser6Context::PARSER_DHCP6, false); diff --git a/src/bin/netconf/tests/parser_unittests.cc b/src/bin/netconf/tests/parser_unittests.cc index f8a372f4ea..da953a09b7 100644 --- a/src/bin/netconf/tests/parser_unittests.cc +++ b/src/bin/netconf/tests/parser_unittests.cc @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -917,8 +918,23 @@ TEST(ParserTest, duplicateMapEntries) { cout << "checked " << cnt << " duplicated map entries\n"; } +/// @brief Test fixture for trailing commas. +class TrailingCommasTest : public isc::dhcp::test::LogContentTest { +public: + /// @brief Add a log entry. + /// + /// @param loc Location of the trailing comma. + void addLog(const string& loc) { + string log = "NETCONF_CONFIG_SYNTAX_WARNING Netconf "; + log += "configuration syntax warning: " + loc; + log += ": Extraneous comma. "; + log += "A piece of configuration may have been omitted."; + addString(log); + } +}; + // Test that trailing commas are allowed. -TEST(ParserTest, trailingCommas) { +TEST_F(TrailingCommasTest, tests) { string txt(R"({ "Netconf": { "boot-update": true, @@ -951,6 +967,10 @@ TEST(ParserTest, trailingCommas) { })"); testParser(txt, ParserContext::PARSER_NETCONF, false); + addLog(":7.16"); + /// @todo + EXPECT_TRUE(checkFile()); + // Test with many consecutive commas. boost::replace_all(txt, ",", ",,,,"); testParser(txt, ParserContext::PARSER_NETCONF, false);