Kea 2.5.8
test_to_element.cc
Go to the documentation of this file.
1// Copyright (C) 2017-2024 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
43#ifdef HAVE_CREATE_UNIFIED_DIFF
44string generateDiff(string left, string right) {
45 vector<string> left_lines;
46 boost::split(left_lines, left, boost::is_any_of("\n"));
47 vector<string> right_lines;
48 boost::split(right_lines, right, boost::is_any_of("\n"));
49 using namespace testing::internal;
50 return (edit_distance::CreateUnifiedDiff(left_lines, right_lines));
51}
52#else
53std::string generateDiff(std::string, std::string) {
54 return ("N/A: !HAVE_CREATE_UNIFIED_DIFF");
55}
56#endif
57
58} // namespace test
59} // namespace isc
void prettyPrint(ConstElementPtr element, std::ostream &out, unsigned indent, unsigned step)
Pretty prints the data into stream.
Definition: data.cc:1547
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.
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.