Kea 2.5.8
textdata.h
Go to the documentation of this file.
1// Copyright (C) 2011-2015 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 <istream>
8#include <string>
9#include <sstream>
10
11#include <gtest/gtest.h>
12
13#ifndef UTIL_UNITTESTS_TEXTDATA_H
14#define UTIL_UNITTESTS_TEXTDATA_H 1
15
24namespace isc {
25namespace util {
26namespace unittests {
27
32template <typename EXPECTED_STREAM, typename ACTUAL_STREAM>
33void
34matchTextData(EXPECTED_STREAM& expected, ACTUAL_STREAM& actual) {
35 std::string actual_line;
36 std::string expected_line;
37 while (std::getline(actual, actual_line), !actual.eof()) {
38 std::getline(expected, expected_line);
39 if (expected.eof()) {
40 FAIL() << "Redundant line in actual output: " << actual_line;
41 break;
42 }
43 if (actual.bad() || actual.fail() ||
44 expected.bad() || expected.fail()) {
45 throw std::runtime_error("Unexpected error in data streams");
46 }
47 EXPECT_EQ(expected_line, actual_line);
48 }
49 while (std::getline(expected, expected_line), !expected.eof()) {
50 ADD_FAILURE() << "Missing line in actual output: " << expected_line;
51 }
52}
53
61template <typename EXPECTED_STREAM>
62void
63matchTextData(EXPECTED_STREAM& expected, const std::string& actual_text) {
64 std::istringstream iss(actual_text);
65 matchTextData(expected, iss);
66}
67
69template <typename ACTUAL_STREAM>
70void
71matchTextData(const std::string& expected_text, ACTUAL_STREAM& actual) {
72 std::istringstream iss(expected_text);
73 matchTextData(iss, actual);
74}
75
78void
79matchTextData(const std::string& expected_text,
80 const std::string& actual_text)
81{
82 std::istringstream expected_is(expected_text);
83 std::istringstream actual_is(actual_text);
84 matchTextData(expected_is, actual_is);
85}
86
87}
88}
89}
90
91#endif // UTIL_UNITTESTS_TEXTDATA_H
void matchTextData(EXPECTED_STREAM &expected, ACTUAL_STREAM &actual)
Line-by-line text comparison.
Definition: textdata.h:34
Defines the logger used by the top-level component of kea-lfc.