summaryrefslogtreecommitdiffstats
path: root/src/bin/dhcp4/tests/dhcp4_test_utils.h
diff options
context:
space:
mode:
authorAndrei Pavel <andrei.pavel@qualitance.com>2017-08-17 20:04:29 +0200
committerAndrei Pavel <andrei.pavel@qualitance.com>2017-08-17 20:04:29 +0200
commit529d15326887b3513413567e497118b3db2c24f3 (patch)
tree8b66b262349433802bd52e920bb4783baac57cb3 /src/bin/dhcp4/tests/dhcp4_test_utils.h
parentAdded mysql_execute_script (diff)
parent[master] Added ChangeLog 1288 for trac 5315. (diff)
downloadkea-529d15326887b3513413567e497118b3db2c24f3.tar.xz
kea-529d15326887b3513413567e497118b3db2c24f3.zip
Merge branch 'isc-master' into minor-changes
Diffstat (limited to 'src/bin/dhcp4/tests/dhcp4_test_utils.h')
-rw-r--r--src/bin/dhcp4/tests/dhcp4_test_utils.h78
1 files changed, 75 insertions, 3 deletions
diff --git a/src/bin/dhcp4/tests/dhcp4_test_utils.h b/src/bin/dhcp4/tests/dhcp4_test_utils.h
index b190c55dd0..5ea2b243a4 100644
--- a/src/bin/dhcp4/tests/dhcp4_test_utils.h
+++ b/src/bin/dhcp4/tests/dhcp4_test_utils.h
@@ -1,4 +1,4 @@
-// Copyright (C) 2013-2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2013-2017 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
@@ -21,6 +21,7 @@
#include <dhcpsrv/lease.h>
#include <dhcpsrv/lease_mgr_factory.h>
#include <dhcp4/dhcp4_srv.h>
+#include <dhcp4/parser_context.h>
#include <asiolink/io_address.h>
#include <cc/command_interpreter.h>
#include <list>
@@ -417,11 +418,11 @@ public:
void configure(const std::string& config, NakedDhcpv4Srv& srv,
const bool commit = true);
- /// @brief Pretents a packet of specified type was received.
+ /// @brief Pretends a packet of specified type was received.
///
/// Instantiates fake network interfaces, configures passed Dhcpv4Srv,
/// then creates a message of specified type and sends it to the
- /// server and then checks whether expected statstics were set
+ /// server and then checks whether expected statistics were set
/// appropriately.
///
/// @param srv the DHCPv4 server to be used
@@ -478,6 +479,77 @@ public:
NakedDhcpv4Srv srv_;
};
+/// @brief Patch the server config to add interface-config/re-detect=false
+/// @param json the server config
+inline void
+disableIfacesReDetect(isc::data::ConstElementPtr json) {
+ isc::data::ConstElementPtr ifaces_cfg = json->get("interfaces-config");
+ if (ifaces_cfg) {
+ isc::data::ElementPtr mutable_cfg =
+ boost::const_pointer_cast<isc::data::Element>(ifaces_cfg);
+ mutable_cfg->set("re-detect", isc::data::Element::create(false));
+ }
+}
+
+/// @brief Runs parser in JSON mode, useful for parser testing
+///
+/// @param in string to be parsed
+/// @return ElementPtr structure representing parsed JSON
+inline isc::data::ElementPtr
+parseJSON(const std::string& in)
+{
+ isc::dhcp::Parser4Context ctx;
+ return (ctx.parseString(in, isc::dhcp::Parser4Context::PARSER_JSON));
+}
+
+/// @brief Runs parser in Dhcp4 mode
+///
+/// This is a simplified Dhcp4 mode, so no outer { } and "Dhcp4" is
+/// needed. This format is used by most of the tests.
+///
+/// @param in string to be parsed
+/// @param verbose display the exception message when it fails
+/// @return ElementPtr structure representing parsed JSON
+inline isc::data::ElementPtr
+parseDHCP4(const std::string& in, bool verbose = false)
+{
+ try {
+ isc::dhcp::Parser4Context ctx;
+ isc::data::ElementPtr json;
+ json = ctx.parseString(in, isc::dhcp::Parser4Context::SUBPARSER_DHCP4);
+ disableIfacesReDetect(json);
+ return (json);
+ }
+ catch (const std::exception& ex) {
+ if (verbose) {
+ std::cout << "EXCEPTION: " << ex.what() << std::endl;
+ }
+ throw;
+ }
+}
+
+/// @brief Runs parser in option definition mode
+///
+/// This function parses specified text as JSON that defines option definitions.
+///
+/// @param in string to be parsed
+/// @param verbose display the exception message when it fails
+/// @return ElementPtr structure representing parsed JSON
+inline isc::data::ElementPtr
+parseOPTION_DEF(const std::string& in, bool verbose = false)
+{
+ try {
+ isc::dhcp::Parser4Context ctx;
+ return (ctx.parseString(in, isc::dhcp::Parser4Context::PARSER_OPTION_DEF));
+ }
+ catch (const std::exception& ex) {
+ if (verbose) {
+ std::cout << "EXCEPTION: " << ex.what() << std::endl;
+ }
+ throw;
+ }
+}
+
}; // end of isc::dhcp::test namespace
}; // end of isc::dhcp namespace
}; // end of isc namespace