Kea: test_to_element.cc Source File

| Kea 3.2.0-git

test_to_element.cc
Go to the documentation of this file.
1// Copyright (C) 2017-2025 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#include <config.h>
8
9#include <testutils/test_to_element.h>
10#include <boost/algorithm/string.hpp>
11#include <gtest/gtest.h>
12#include <string>
13#include <vector>
14
15using namespace isc::data;
16using namespace std;
17
18namespace isc {
19namespace test {
20
21 void expectEqWithDiff(ConstElementPtr const& a, ConstElementPtr const& b) {
22 ASSERT_TRUE(a);
23 ASSERT_TRUE(b);
24 string const pretty_print_a(prettyPrint(a));
25 string const pretty_print_b(prettyPrint(b));
26 EXPECT_EQ(pretty_print_a, pretty_print_b)
27 << endl
28 << "Diff:" << endl
29 << generateDiff(pretty_print_a, pretty_print_b) << endl;
30}
31
32 void expectEqWithDiff(ElementPtr const& a, ElementPtr const& b) {
33 ASSERT_TRUE(a);
34 ASSERT_TRUE(b);
35 string const pretty_print_a(prettyPrint(a));
36 string const pretty_print_b(prettyPrint(b));
37 EXPECT_EQ(pretty_print_a, pretty_print_b)
38 << endl
39 << "Diff:" << endl
40 << generateDiff(pretty_print_a, pretty_print_b) << endl;
41}
42
43 void assertEqWithDiff(ConstElementPtr const& a, ConstElementPtr const& b) {
44 ASSERT_TRUE(a);
45 ASSERT_TRUE(b);
46 string const pretty_print_a(prettyPrint(a));
47 string const pretty_print_b(prettyPrint(b));
48 ASSERT_EQ(pretty_print_a, pretty_print_b)
49 << endl
50 << "Diff:" << endl
51 << generateDiff(pretty_print_a, pretty_print_b) << endl;
52}
53
54 void assertEqWithDiff(ElementPtr const& a, ConstElementPtr const& b) {
55 ASSERT_TRUE(a);
56 ASSERT_TRUE(b);
57 string const pretty_print_a(prettyPrint(a));
58 string const pretty_print_b(prettyPrint(b));
59 ASSERT_EQ(pretty_print_a, pretty_print_b)
60 << endl
61 << "Diff:" << endl
62 << generateDiff(pretty_print_a, pretty_print_b) << endl;
63}
64
65#ifdef HAVE_CREATE_UNIFIED_DIFF
66string generateDiff(string left, string right) {
67 vector<string> left_lines;
68 boost::split(left_lines, left, boost::is_any_of("\n"));
69 vector<string> right_lines;
70 boost::split(right_lines, right, boost::is_any_of("\n"));
71 using namespace testing::internal;
72 return (edit_distance::CreateUnifiedDiff(left_lines, right_lines));
73}
74#else
75std::string generateDiff(std::string, std::string) {
76 return ("N/A: !HAVE_CREATE_UNIFIED_DIFF");
77}
78#endif
79
80} // namespace test
81} // namespace isc
isc::data
Definition base_stamped_element.cc:12
isc::data::prettyPrint
void prettyPrint(ConstElementPtr element, std::ostream &out, unsigned indent, unsigned step)
Pretty prints the data into stream.
Definition data.cc:1747
isc::data::ConstElementPtr
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:30
isc::data::ElementPtr
boost::shared_ptr< Element > ElementPtr
Definition data.h:29
isc::test
Definition env_var_wrapper.cc:14
isc::test::expectEqWithDiff
void expectEqWithDiff(ConstElementPtr const &a, ConstElementPtr const &b)
Expect two element pointers to be equal.
Definition test_to_element.cc:21
isc::test::assertEqWithDiff
void assertEqWithDiff(ConstElementPtr const &a, ConstElementPtr const &b)
Definition test_to_element.cc:43
isc::test::generateDiff
std::string generateDiff(std::string, std::string)
Return the difference between two strings.
Definition test_to_element.cc:75
isc
Defines the logger used by the top-level component of kea-lfc.
Definition check_exists_add.cc:18
test_to_element.h