/// @param a first to be compared
/// @param b second to be compared
void compareJSON(ConstElementPtr a, ConstElementPtr b) {
- ASSERT_TRUE(a);
- ASSERT_TRUE(b);
- EXPECT_EQ(a->str(), b->str())
-#ifdef HAVE_CREATE_UNIFIED_DIFF
- << "\nDiff:\n" << generateDiff(prettyPrint(a), prettyPrint(b)) << "\n"
-#endif
- ;
+ expectEqWithDiff(a, b);
}
/// @brief Tests if the input string can be parsed with specific parser
/// @param a first to be compared
/// @param b second to be compared
void compareJSON(ConstElementPtr a, ConstElementPtr b) {
- ASSERT_TRUE(a);
- ASSERT_TRUE(b);
- EXPECT_EQ(a->str(), b->str())
-#ifdef HAVE_CREATE_UNIFIED_DIFF
- << "\nDiff:\n" << generateDiff(prettyPrint(a), prettyPrint(b)) << "\n"
-#endif
- ;
+ expectEqWithDiff(a, b);
}
/// @brief Tests if the input string can be parsed with specific parser
using namespace isc::dhcp;
using namespace isc::dhcp::test;
using namespace isc::hooks;
+using namespace isc::test;
using namespace std;
namespace {
}
// Verify that the staged queue control equals the expected queue control.
- EXPECT_TRUE(staged_control->equals(*exp_control))
-#ifdef HAVE_CREATE_UNIFIED_DIFF
- << "\nDiff:\n" << isc::test::generateDiff(prettyPrint(staged_control), prettyPrint(exp_control)) << "\n"
-#endif
- ;
+ expectEqWithDiff(staged_control, exp_control);
}
}
}
/// @param a first to be compared
/// @param b second to be compared
void compareJSON(ConstElementPtr a, ConstElementPtr b) {
- ASSERT_TRUE(a);
- ASSERT_TRUE(b);
- EXPECT_EQ(a->str(), b->str())
-#ifdef HAVE_CREATE_UNIFIED_DIFF
- << "\nDiff:\n" << generateDiff(prettyPrint(a), prettyPrint(b)) << "\n"
-#endif
- ;
+ expectEqWithDiff(a, b);
}
/// @brief Tests if the input string can be parsed with specific parser
using namespace isc::dhcp;
using namespace isc::dhcp::test;
using namespace isc::hooks;
+using namespace isc::test;
using namespace std;
namespace {
}
// Verify that the staged queue control equals the expected queue control.
- EXPECT_TRUE(staged_control->equals(*exp_control))
-#ifdef HAVE_CREATE_UNIFIED_DIFF
- << "\nDiff:\n" << isc::test::generateDiff(prettyPrint(staged_control), prettyPrint(exp_control)) << "\n"
-#endif
- ;
+ expectEqWithDiff(staged_control, exp_control);
}
}
}
/// @param a first to be compared
/// @param b second to be compared
void compareJSON(ConstElementPtr a, ConstElementPtr b) {
- ASSERT_TRUE(a);
- ASSERT_TRUE(b);
- EXPECT_EQ(a->str(), b->str())
-#ifdef HAVE_CREATE_UNIFIED_DIFF
- << "\nDiff:\n" << generateDiff(prettyPrint(a), prettyPrint(b)) << "\n"
-#endif
- ;
+ expectEqWithDiff(a, b);
}
/// @brief Tests if the input string can be parsed with specific parser
/// @param a first to be compared
/// @param b second to be compared
void compareJSON(ConstElementPtr a, ConstElementPtr b) {
- ASSERT_TRUE(a);
- ASSERT_TRUE(b);
- EXPECT_EQ(a->str(), b->str())
-#ifdef HAVE_CREATE_UNIFIED_DIFF
- << "\nDiff:\n" << generateDiff(prettyPrint(a), prettyPrint(b)) << "\n"
-#endif
- ;
+ expectEqWithDiff(a, b);
}
/// @brief Tests if the input string can be parsed with specific parser
#include <string>
#include <vector>
+using namespace isc::data;
+using namespace std;
+
namespace isc {
namespace test {
+void expectEqWithDiff(ConstElementPtr const& a, ConstElementPtr const& b) {
+ ASSERT_TRUE(a);
+ ASSERT_TRUE(b);
+ string const pretty_print_a(prettyPrint(a));
+ string const pretty_print_b(prettyPrint(b));
+ EXPECT_EQ(pretty_print_a, pretty_print_b)
+ << endl
+ << "Diff:" << endl
+ << generateDiff(pretty_print_a, pretty_print_b) << endl;
+}
+
+void expectEqWithDiff(ElementPtr const& a, ElementPtr const& b) {
+ ASSERT_TRUE(a);
+ ASSERT_TRUE(b);
+ string const pretty_print_a(prettyPrint(a));
+ string const pretty_print_b(prettyPrint(b));
+ EXPECT_EQ(pretty_print_a, pretty_print_b)
+ << endl
+ << "Diff:" << endl
+ << generateDiff(pretty_print_a, pretty_print_b) << endl;
+}
+
#ifdef HAVE_CREATE_UNIFIED_DIFF
-std::string generateDiff(std::string left, std::string right) {
- std::vector<std::string> left_lines;
+string generateDiff(string left, string right) {
+ vector<string> left_lines;
boost::split(left_lines, left, boost::is_any_of("\n"));
- std::vector<std::string> right_lines;
+ vector<string> right_lines;
boost::split(right_lines, right, boost::is_any_of("\n"));
using namespace testing::internal;
return (edit_distance::CreateUnifiedDiff(left_lines, right_lines));
}
#else
std::string generateDiff(std::string, std::string) {
- return ("");
+ return ("N/A: !HAVE_CREATE_UNIFIED_DIFF");
}
#endif
-}; // end of isc::test namespace
-}; // end of isc namespace
+} // namespace test
+} // namespace isc
namespace isc {
namespace test {
+/// @brief Expect two element pointers to be equal. Order of elements
+/// in a list or a map is also checked by default.
+/// @{
+void
+expectEqWithDiff(isc::data::ConstElementPtr const& left, isc::data::ConstElementPtr const& right);
+
+void
+expectEqWithDiff(isc::data::ElementPtr const& left, isc::data::ElementPtr const& right);
+/// @}
+
/// @brief Return the difference between two strings
///
/// Use the gtest >= 1.8.0 tool which builds the difference between
/// @param left left string
/// @param right right string
/// @return the unified diff between left and right
-std::string generateDiff(std::string left, std::string right);
+std::string
+generateDiff(std::string left, std::string right);
/// @brief Run a test using toElement() method with a string
///
/// @tparam Cfg the class implementing the toElement() method
/// @param expected the expected textual value
/// @param cfg an instance of the Cfg class
-template<typename Cfg>
-void runToElementTest(const std::string& expected, const Cfg& cfg) {
+template <typename Cfg>
+void
+runToElementTest(const std::string& expected, const Cfg& cfg) {
using namespace isc::data;
#ifdef HAVE_IS_BASE_OF
static_assert(std::is_base_of<CfgToElement, Cfg>::value,
std::string got = prettyPrint(unparsed);
ADD_FAILURE() << "Expected:\n" << wanted << "\n"
<< "Actual:\n" << got
-#ifdef HAVE_CREATE_UNIFIED_DIFF
<< "\nDiff:\n" << generateDiff(wanted, got)
-#endif
<< "\n";
}
}
std::string got = prettyPrint(unparsed);
ADD_FAILURE() << "Expected:\n" << wanted << "\n"
<< "Actual:\n" << got
-#ifdef HAVE_CREATE_UNIFIED_DIFF
<< "\nDiff:\n" << generateDiff(wanted, got)
-#endif
<< "\n";
}
}
-}; // end of isc::test namespace
-}; // end of isc namespace
+} // namespace test
+} // namespace isc
#endif // TEST_TO_ELEMENT_H
#include <gtest/gtest.h>
#include <testutils/io_utils.h>
+#include <testutils/test_to_element.h>
#include <testutils/user_context_utils.h>
#include <yang/tests/json_configs.h>
#include <yang/tests/sysrepo_setup.h>
using namespace std;
using namespace isc;
using namespace isc::data;
+using namespace isc::test;
using namespace isc::yang;
using namespace isc::yang::test;
using namespace sysrepo;
namespace {
-/// @brief Return the difference between two strings
-///
-/// Use the gtest >= 1.8.0 tool which builds the difference between
-/// two vectors of lines.
-///
-/// @param left left string
-/// @param right right string
-/// @return the unified diff between left and right
-#ifdef HAVE_CREATE_UNIFIED_DIFF
-string generateDiff(string left, string right) {
- vector<string> left_lines;
- boost::split(left_lines, left, boost::is_any_of("\n"));
- vector<string> right_lines;
- boost::split(right_lines, right, boost::is_any_of("\n"));
- using namespace testing::internal;
- return (edit_distance::CreateUnifiedDiff(left_lines, right_lines));
-}
-#else
-string generateDiff(string, string) {
- return ("");
-}
-#endif
-
/// @brief Test Fixture class for Yang <-> JSON configs.
class ConfigTest : public ::testing::Test {
public:
string got = prettyPrint(content);
cerr << "Expected:\n" << wanted << "\n"
<< "Actual:\n" << got
-#ifdef HAVE_CREATE_UNIFIED_DIFF
<< "\nDiff:\n" << generateDiff(wanted, got)
-#endif
<< "\n";
return (false);
}
#include <gtest/gtest.h>
+#include <testutils/test_to_element.h>
#include <yang/tests/sysrepo_setup.h>
#include <yang/translator_option_data.h>
#include <yang/yang_models.h>
using namespace std;
using namespace isc;
using namespace isc::data;
+using namespace isc::test;
using namespace isc::yang;
using namespace isc::yang::test;
using namespace sysrepo;
ASSERT_TRUE(options);
ASSERT_EQ(Element::list, options->getType());
EXPECT_EQ(1, options->size());
- EXPECT_TRUE(option->equals(*options->get(0)));
+ expectEqWithDiff(option, options->get(0));
}
// This test verifies that one option data can be properly translated
ASSERT_TRUE(options);
ASSERT_EQ(Element::list, options->getType());
EXPECT_EQ(1, options->size());
- EXPECT_TRUE(option->equals(*options->get(0)));
+ expectEqWithDiff(option, options->get(0));
}
// This test verifies that an empty option data list can be properly
EXPECT_NO_THROW_LOG(got = translator_->getOptionDataListFromAbsoluteXpath(xpath));
ASSERT_TRUE(got);
ASSERT_EQ(1, got->size());
- EXPECT_TRUE(option->equals(*got->get(0)));
+ expectEqWithDiff(option, options->get(0));
}
// This test verifies that one option data can be properly translated
EXPECT_NO_THROW_LOG(got = translator_->getOptionDataListFromAbsoluteXpath(xpath));
ASSERT_TRUE(got);
ASSERT_EQ(1, got->size());
- EXPECT_TRUE(option->equals(*got->get(0)));
+ expectEqWithDiff(option, options->get(0));
}
-// This test verifies that multiple options of smae code and space but different data can be
+// This test verifies that multiple options of same code and space but different data can be
// configured for v4.
TEST_F(TranslatorOptionDataListTestv4, optionsSameCodeAndSpace) {
string const xpath("/kea-dhcp4-server:config");
EXPECT_NO_THROW_LOG(got = translator_->getOptionDataListFromAbsoluteXpath(xpath));
ASSERT_TRUE(got);
EXPECT_EQ(2, got->size());
- EXPECT_TRUE(options->equals(*got));
+ expectEqWithDiff(options, got);
// Now with keys only.
options = Element::createList();
EXPECT_NO_THROW_LOG(got = translator_->getOptionDataListFromAbsoluteXpath(xpath));
ASSERT_TRUE(got);
EXPECT_EQ(4, got->size());
- EXPECT_TRUE(options->get(0)->equals(*got->get(2)));
- EXPECT_TRUE(options->get(1)->equals(*got->get(3)));
+ expectEqWithDiff(options->get(0), got->get(2));
+ expectEqWithDiff(options->get(1), got->get(3));
}
-// This test verifies that multiple options of smae code and space but different data can be
+// This test verifies that multiple options of same code and space but different data can be
// configured for v6.
TEST_F(TranslatorOptionDataListTestv6, optionsSameCodeAndSpace) {
string const xpath("/kea-dhcp6-server:config");
EXPECT_NO_THROW_LOG(got = translator_->getOptionDataListFromAbsoluteXpath(xpath));
ASSERT_TRUE(got);
EXPECT_EQ(2, got->size());
- EXPECT_TRUE(options->equals(*got));
+ expectEqWithDiff(options, got);
// Now with keys only.
options = Element::createList();
EXPECT_NO_THROW_LOG(got = translator_->getOptionDataListFromAbsoluteXpath(xpath));
ASSERT_TRUE(got);
EXPECT_EQ(4, got->size());
- EXPECT_TRUE(options->get(0)->equals(*got->get(2)));
- EXPECT_TRUE(options->get(1)->equals(*got->get(3)));
+ expectEqWithDiff(options->get(0), got->get(2));
+ expectEqWithDiff(options->get(1), got->get(3));
}
} // namespace