Kea 3.1.0
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
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
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
32void 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
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
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
void prettyPrint(ConstElementPtr element, std::ostream &out, unsigned indent, unsigned step)
Pretty prints the data into stream.
Definition data.cc:1549
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:29
boost::shared_ptr< Element > ElementPtr
Definition data.h:28
void expectEqWithDiff(ConstElementPtr const &a, ConstElementPtr const &b)
Expect two element pointers to be equal.
void assertEqWithDiff(ConstElementPtr const &a, ConstElementPtr const &b)
std::string generateDiff(std::string, std::string)
Return the difference between two strings.
Defines the logger used by the top-level component of kea-lfc.