1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright (C) 2012-2024 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include <config.h>

#include <dns/master_loader_callbacks.h>
#include <dns/rrset.h>
#include <dns/name.h>
#include <dns/rrttl.h>
#include <dns/rrclass.h>

#include <exceptions/exceptions.h>

#include <gtest/gtest.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <functional><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.

namespace {

using std::string;
using namespace isc::dns;
namespace ph = std::placeholders;

class MasterLoaderCallbacksTest : public ::testing::Test {
protected:
    MasterLoaderCallbacksTest() :
        last_was_error_(false), // Not needed, but then cppcheck complains
        issue_called_(false),
        rrset_(new RRset(Name("example.org"), RRClass::IN(), RRType::A(),
                         RRTTL(3600))),
        error_(std::bind(&MasterLoaderCallbacksTest::checkCallback, this,
                         true, ph::_1, ph::_2, ph::_3)),
        warning_(std::bind(&MasterLoaderCallbacksTest::checkCallback, this,
                           false, ph::_1, ph::_2, ph::_3)),
        callbacks_(error_, warning_)
    {}

    void checkCallback(bool error, const string& source, size_t line,
                       const string& reason)
    {
        issue_called_ = true;
        last_was_error_ = error;
        EXPECT_EQ("source", source);
        EXPECT_EQ(1, line);
        EXPECT_EQ("reason", reason);
    }
    bool last_was_error_;
    bool issue_called_;
    const RRsetPtr rrset_;
    const MasterLoaderCallbacks::IssueCallback error_, warning_;
    MasterLoaderCallbacks callbacks_;
};

// Check the constructor rejects empty callbacks, but accepts non-empty ones
TEST_F(MasterLoaderCallbacksTest, constructor) {<--- syntax error
    EXPECT_THROW(MasterLoaderCallbacks(MasterLoaderCallbacks::IssueCallback(),
                                       warning_), isc::InvalidParameter);
    EXPECT_THROW(MasterLoaderCallbacks(error_,
                                       MasterLoaderCallbacks::IssueCallback()),
                 isc::InvalidParameter);
    EXPECT_NO_THROW(MasterLoaderCallbacks(error_, warning_));
}

// Call the issue callbacks
TEST_F(MasterLoaderCallbacksTest, issueCall) {
    callbacks_.error("source", 1, "reason");
    EXPECT_TRUE(last_was_error_);
    EXPECT_TRUE(issue_called_);

    issue_called_ = false;

    callbacks_.warning("source", 1, "reason");
    EXPECT_FALSE(last_was_error_);
    EXPECT_TRUE(issue_called_);
}

}