Browse Source

[5021] SimpleParser unit-tests now use bison parser.

Tomek Mrugalski 8 years ago
parent
commit
a904a3e14c

+ 3 - 3
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.

+ 5 - 5
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

+ 3 - 3
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 {

+ 8 - 7
src/bin/dhcp4/tests/simple_parser4_unittest.cc

@@ -7,6 +7,7 @@
 #include <config.h>
 #include <gtest/gtest.h>
 #include <dhcp4/simple_parser4.h>
+#include <dhcp4/tests/dhcp4_test_utils.h>
 #include <cc/data.h>
 
 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.

+ 3 - 3
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.

+ 5 - 5
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

+ 3 - 3
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 {

+ 7 - 5
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 <config.h>
-#include <cc/data.h>
-#include <dhcp6/simple_parser6.h>
 #include <gtest/gtest.h>
+#include <dhcp6/simple_parser6.h>
+#include <dhcp6/tests/dhcp6_test_utils.h>
+#include <cc/data.h>
 
 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.