From: Tomek Mrugalski Date: Wed, 28 Dec 2016 13:41:05 +0000 (+0100) Subject: [5021] SimpleParser unit-tests now use bison parser. X-Git-Tag: trac5101_base~1^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a904a3e14c822cf528d5e1cd36b3ac1113aa9f9e;p=thirdparty%2Fkea.git [5021] SimpleParser unit-tests now use bison parser. --- diff --git a/src/bin/dhcp4/parser_context.cc b/src/bin/dhcp4/parser_context.cc index 250f4dbc8f..12e4831293 100644 --- a/src/bin/dhcp4/parser_context.cc +++ b/src/bin/dhcp4/parser_context.cc @@ -24,14 +24,14 @@ Parser4Context::~Parser4Context() { } -isc::data::ConstElementPtr +isc::data::ElementPtr Parser4Context::parseString(const std::string& str, ParserType parser_type) { scanStringBegin(str, parser_type); return (parseCommon()); } -isc::data::ConstElementPtr +isc::data::ElementPtr Parser4Context::parseFile(const std::string& filename, ParserType parser_type) { FILE* f = fopen(filename.c_str(), "r"); if (!f) { @@ -41,7 +41,7 @@ Parser4Context::parseFile(const std::string& filename, ParserType parser_type) { return (parseCommon()); } -isc::data::ConstElementPtr +isc::data::ElementPtr Parser4Context::parseCommon() { isc::dhcp::Dhcp4Parser parser(*this); // Uncomment this to get detailed parser logs. diff --git a/src/bin/dhcp4/parser_context.h b/src/bin/dhcp4/parser_context.h index 4c8c7d1631..5f37dda521 100644 --- a/src/bin/dhcp4/parser_context.h +++ b/src/bin/dhcp4/parser_context.h @@ -123,8 +123,8 @@ public: /// @param str string to be parsed /// @param parser_type specifies expected content (usually DHCP4 or generic JSON) /// @return Element structure representing parsed text. - isc::data::ConstElementPtr parseString(const std::string& str, - ParserType parser_type); + isc::data::ElementPtr parseString(const std::string& str, + ParserType parser_type); /// @brief Run the parser on the file specified. /// @@ -136,8 +136,8 @@ public: /// @param filename file to be parsed /// @param parser_type specifies expected content (usually DHCP4 or generic JSON) /// @return Element structure representing parsed text. - isc::data::ConstElementPtr parseFile(const std::string& filename, - ParserType parser_type); + isc::data::ElementPtr parseFile(const std::string& filename, + ParserType parser_type); /// @brief Error handler /// @@ -312,7 +312,7 @@ public: /// @brief Common part of parseXXX /// /// @return Element structure representing parsed text. - isc::data::ConstElementPtr parseCommon(); + isc::data::ElementPtr parseCommon(); }; }; // end of isc::eval namespace diff --git a/src/bin/dhcp4/tests/dhcp4_test_utils.h b/src/bin/dhcp4/tests/dhcp4_test_utils.h index 0133fb886b..e6d14a02f5 100644 --- a/src/bin/dhcp4/tests/dhcp4_test_utils.h +++ b/src/bin/dhcp4/tests/dhcp4_test_utils.h @@ -483,7 +483,7 @@ public: /// /// @param in string to be parsed /// @return ElementPtr structure representing parsed JSON -inline isc::data::ConstElementPtr +inline isc::data::ElementPtr parseJSON(const std::string& in) { isc::dhcp::Parser4Context ctx; @@ -498,7 +498,7 @@ parseJSON(const std::string& in) /// @param in string to be parsed /// @param verbose display the exception message when it fails /// @return ElementPtr structure representing parsed JSON -inline isc::data::ConstElementPtr +inline isc::data::ElementPtr parseDHCP4(const std::string& in, bool verbose = false) { try { @@ -520,7 +520,7 @@ parseDHCP4(const std::string& in, bool verbose = false) /// @param in string to be parsed /// @param verbose display the exception message when it fails /// @return ElementPtr structure representing parsed JSON -inline isc::data::ConstElementPtr +inline isc::data::ElementPtr parseOPTION_DEF(const std::string& in, bool verbose = false) { try { diff --git a/src/bin/dhcp4/tests/simple_parser4_unittest.cc b/src/bin/dhcp4/tests/simple_parser4_unittest.cc index d95e45fb3d..d1d879b443 100644 --- a/src/bin/dhcp4/tests/simple_parser4_unittest.cc +++ b/src/bin/dhcp4/tests/simple_parser4_unittest.cc @@ -7,6 +7,7 @@ #include #include #include +#include #include using namespace isc::data; @@ -44,7 +45,7 @@ public: // This test checks if global defaults are properly set for DHCPv4. TEST_F(SimpleParser4Test, globalDefaults4) { - ElementPtr empty = Element::fromJSON("{ }"); + ElementPtr empty = parseJSON("{ }"); size_t num = 0; EXPECT_NO_THROW(num = SimpleParser4::setAllDefaults(empty)); @@ -65,12 +66,12 @@ TEST_F(SimpleParser4Test, globalDefaults4) { // This test checks if the parameters can be inherited from the global // scope to the subnet scope. TEST_F(SimpleParser4Test, inheritGlobalToSubnet4) { - ElementPtr global = Element::fromJSON("{ \"renew-timer\": 1," - " \"rebind-timer\": 2," - " \"preferred-lifetime\": 3," - " \"valid-lifetime\": 4" - "}"); - ElementPtr subnet = Element::fromJSON("{ \"renew-timer\": 100 }"); + ElementPtr global = parseJSON("{ \"renew-timer\": 1," + " \"rebind-timer\": 2," + " \"preferred-lifetime\": 3," + " \"valid-lifetime\": 4" + "}"); + ElementPtr subnet = parseJSON("{ \"renew-timer\": 100 }"); // we should inherit 3 parameters. Renew-timer should remain intact, // as it was already defined in the subnet scope. diff --git a/src/bin/dhcp6/parser_context.cc b/src/bin/dhcp6/parser_context.cc index 8f2f28195e..6293f91bee 100644 --- a/src/bin/dhcp6/parser_context.cc +++ b/src/bin/dhcp6/parser_context.cc @@ -24,14 +24,14 @@ Parser6Context::~Parser6Context() { } -isc::data::ConstElementPtr +isc::data::ElementPtr Parser6Context::parseString(const std::string& str, ParserType parser_type) { scanStringBegin(str, parser_type); return (parseCommon()); } -isc::data::ConstElementPtr +isc::data::ElementPtr Parser6Context::parseFile(const std::string& filename, ParserType parser_type) { FILE* f = fopen(filename.c_str(), "r"); if (!f) { @@ -41,7 +41,7 @@ Parser6Context::parseFile(const std::string& filename, ParserType parser_type) { return (parseCommon()); } -isc::data::ConstElementPtr +isc::data::ElementPtr Parser6Context::parseCommon() { isc::dhcp::Dhcp6Parser parser(*this); // Uncomment this to get detailed parser logs. diff --git a/src/bin/dhcp6/parser_context.h b/src/bin/dhcp6/parser_context.h index 2b840e2a58..077bb6e639 100644 --- a/src/bin/dhcp6/parser_context.h +++ b/src/bin/dhcp6/parser_context.h @@ -126,8 +126,8 @@ public: /// @param str string to be parsed /// @param parser_type specifies expected content (usually DHCP6 or generic JSON) /// @return Element structure representing parsed text. - isc::data::ConstElementPtr parseString(const std::string& str, - ParserType parser_type); + isc::data::ElementPtr parseString(const std::string& str, + ParserType parser_type); /// @brief Run the parser on the file specified. /// @@ -139,8 +139,8 @@ public: /// @param filename file to be parsed /// @param parser_type specifies expected content (usually DHCP6 or generic JSON) /// @return Element structure representing parsed text. - isc::data::ConstElementPtr parseFile(const std::string& filename, - ParserType parser_type); + isc::data::ElementPtr parseFile(const std::string& filename, + ParserType parser_type); /// @brief Error handler /// @@ -321,7 +321,7 @@ public: /// @brief Common part of parseXXX /// /// @return Element structure representing parsed text. - isc::data::ConstElementPtr parseCommon(); + isc::data::ElementPtr parseCommon(); }; }; // end of isc::eval namespace diff --git a/src/bin/dhcp6/tests/dhcp6_test_utils.h b/src/bin/dhcp6/tests/dhcp6_test_utils.h index 95f706d351..e99cff003f 100644 --- a/src/bin/dhcp6/tests/dhcp6_test_utils.h +++ b/src/bin/dhcp6/tests/dhcp6_test_utils.h @@ -643,7 +643,7 @@ public: /// /// @param in string to be parsed /// @return ElementPtr structure representing parsed JSON -inline isc::data::ConstElementPtr +inline isc::data::ElementPtr parseJSON(const std::string& in) { isc::dhcp::Parser6Context ctx; @@ -658,7 +658,7 @@ parseJSON(const std::string& in) /// @param in string to be parsed /// @param verbose display the exception message when it fails /// @return ElementPtr structure representing parsed JSON -inline isc::data::ConstElementPtr +inline isc::data::ElementPtr parseDHCP6(const std::string& in, bool verbose = false) { try { @@ -680,7 +680,7 @@ parseDHCP6(const std::string& in, bool verbose = false) /// @param in string to be parsed /// @param verbose display the exception message when it fails /// @return ElementPtr structure representing parsed JSON -inline isc::data::ConstElementPtr +inline isc::data::ElementPtr parseOPTION_DEF(const std::string& in, bool verbose = false) { try { diff --git a/src/bin/dhcp6/tests/simple_parser6_unittest.cc b/src/bin/dhcp6/tests/simple_parser6_unittest.cc index 3721a954c1..67be1be2de 100644 --- a/src/bin/dhcp6/tests/simple_parser6_unittest.cc +++ b/src/bin/dhcp6/tests/simple_parser6_unittest.cc @@ -5,13 +5,15 @@ // file, You can obtain one at http://mozilla.org/MPL/2.0/. #include -#include -#include #include +#include +#include +#include using namespace isc; using namespace isc::data; using namespace isc::dhcp; +using namespace isc::dhcp::test; namespace { @@ -44,7 +46,7 @@ public: // This test checks if global defaults are properly set for DHCPv6. TEST_F(SimpleParser6Test, globalDefaults6) { - ElementPtr empty = Element::fromJSON("{ }"); + ElementPtr empty = parseJSON("{ }"); size_t num = 0; EXPECT_NO_THROW(num = SimpleParser6::setAllDefaults(empty)); @@ -61,12 +63,12 @@ TEST_F(SimpleParser6Test, globalDefaults6) { // This test checks if the parameters can be inherited from the global // scope to the subnet scope. TEST_F(SimpleParser6Test, inheritGlobalToSubnet6) { - ElementPtr global = Element::fromJSON("{ \"renew-timer\": 1," + ElementPtr global = parseJSON("{ \"renew-timer\": 1," " \"rebind-timer\": 2," " \"preferred-lifetime\": 3," " \"valid-lifetime\": 4" "}"); - ElementPtr subnet = Element::fromJSON("{ \"renew-timer\": 100 }"); + ElementPtr subnet = parseJSON("{ \"renew-timer\": 100 }"); // we should inherit 3 parameters. Renew-timer should remain intact, // as it was already defined in the subnet scope.