#include <process/config_ctl_info.h>
#include <hooks/hooks_manager.h>
#include <stats/stats_mgr.h>
+#include <testutils/log_utils.h>
#include <util/boost_time_utils.h>
#include <util/doubles.h>
"} \n"
};
-class Dhcp4ParserTest : public ::testing::Test {
+class Dhcp4ParserTest : public LogContentTest {
protected:
// Check that no hooks libraries are loaded. This is a pre-condition for
// a number of tests, so is checked in one place. As this uses an
checkResult(status, 1);
EXPECT_TRUE(errorContainsPosition(status, "<string>"));
+ // Specific check for incorrect report using default config pair
+ // as option-def is parsed first.
+ string expected = "failed to create or run parser for configuration ";
+ expected += "element option-def: option definition with code '100' ";
+ expected += "already exists in option space 'isc'";
+ EXPECT_EQ(1, countFile(expected));
+
// The new configuration should have inserted option 100, but
// once configuration failed (on the duplicate option definition)
// the original configuration in libdhcp++ should be reverted.
#include <hooks/hooks_manager.h>
#include <process/config_ctl_info.h>
#include <stats/stats_mgr.h>
+#include <testutils/log_utils.h>
#include <util/boost_time_utils.h>
#include "test_data_files_config.h"
"}"
};
-class Dhcp6ParserTest : public ::testing::Test {
+class Dhcp6ParserTest : public LogContentTest {
protected:
// Check that no hooks libraries are loaded. This is a pre-condition for
// a number of tests, so is checked in one place. As this uses an
checkResult(status, 1);
EXPECT_TRUE(errorContainsPosition(status, "<string>"));
+ // Specific check for incorrect report using default config pair
+ // as option-def is parsed first.
+ string expected = "failed to create or run parser for configuration ";
+ expected += "element option-def: option definition with code '100' ";
+ expected += "already exists in option space 'isc'";
+ EXPECT_EQ(1, countFile(expected));
+
// The new configuration should have inserted option 100, but
// once configuration failed (on the duplicate option definition)
// the original configuration in libdhcp++ should be reverted.
-// Copyright (C) 2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2016-2020 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
return (true);
}
+size_t LogContentTest::countFile(const string& exp_string) {
+ ifstream file(LOG_FILE);
+ EXPECT_TRUE(file.is_open());
+ string line;
+ size_t cnt = 0;
+
+ using namespace std;
+
+ if (verbose_) {
+ cout << "Looking for:" << exp_string << endl;
+ }
+ while (getline(file, line)) {
+ if (verbose_) {
+ cout << "Read line :" << line << endl;
+ }
+ if (line.find(exp_string) != string::npos) {
+ ++cnt;
+ }
+ }
+
+ file.close();
+
+ if (verbose_) {
+ cout << "Final count: " << cnt << endl;
+ }
+
+ return (cnt);
+}
+
void LogContentTest::remFile() {
static_cast<void>(remove(LOG_FILE));
}
// the debug statements
const char *LogContentTest::LOG_FILE = "test.log";
-}; // end of isc::dhcp::test namespace
-}; // end of isc::dhcp namespace
-}; // end of isc namespace
+} // end of isc::dhcp::test namespace
+} // end of isc::dhcp namespace
+} // end of isc namespace
-// Copyright (C) 2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2016-2020 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
/// @return true if all of the strings match
bool checkFile();
+ /// @brief check that the requested string is in the
+ /// test log file.
+ ///
+ /// @param exp_string the string to be searched
+ /// @return count of matching lines
+ size_t countFile(const string& exp_string);
+
/// @brief remove the test log file
void remFile();
bool verbose_;
};
-
-
-}; // end of isc::dhcp::test namespace
-}; // end of isc::dhcp namespace
-}; // end of isc namespace
-
+} // end of isc::dhcp::test namespace
+} // end of isc::dhcp namespace
+} // end of isc namespace
#endif // TEST_LOG_UTILS_H