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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright (C) 2019 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 <cc/server_tag.h>
#include <exceptions/exceptions.h>
#include <boost/scoped_ptr.hpp><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <gtest/gtest.h><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <string><--- Include file:  not found. Please note: Cppcheck does not need standard library headers to get proper results.

using namespace isc;
using namespace isc::data;

namespace {

// This test verifies that the constructors of the ServerTag class
// work properly.
TEST(ServerTagTest, constructors) {
    boost::scoped_ptr<ServerTag> tag;

    {
        SCOPED_TRACE("default constructor for all servers");
        ASSERT_NO_THROW(tag.reset(new ServerTag()));
        EXPECT_EQ(ServerTag::ALL, tag->get());
        EXPECT_TRUE(tag->amAll());
    }

    {
        SCOPED_TRACE("all servers");
        ASSERT_NO_THROW(tag.reset(new ServerTag(ServerTag::ALL)));
        EXPECT_EQ(ServerTag::ALL, tag->get());
        EXPECT_TRUE(tag->amAll());
    }

    {
        SCOPED_TRACE("no whitespace");
        ASSERT_NO_THROW(tag.reset(new ServerTag("xyz")));
        EXPECT_EQ("xyz", tag->get());
        EXPECT_FALSE(tag->amAll());
    }

    {
        SCOPED_TRACE("leading whitespace");
        ASSERT_NO_THROW(tag.reset(new ServerTag("  left")));
        EXPECT_EQ("left", tag->get());
        EXPECT_FALSE(tag->amAll());
    }

    {
        SCOPED_TRACE("terminating whitespace");
        ASSERT_NO_THROW(tag.reset(new ServerTag("right  ")));
        EXPECT_EQ("right", tag->get());
        EXPECT_FALSE(tag->amAll());
    }

    {
        SCOPED_TRACE("leading and terminating whitespace");
        ASSERT_NO_THROW(tag.reset(new ServerTag("  both left-right  ")));
        EXPECT_EQ("both left-right", tag->get());
        EXPECT_FALSE(tag->amAll());
    }

    {
        SCOPED_TRACE("upper to lower case");
        ASSERT_NO_THROW(tag.reset(new ServerTag("UPPER CASE TAG")));
        EXPECT_EQ("upper case tag", tag->get());
        EXPECT_FALSE(tag->amAll());
    }
}

// This test verifies that malformed server tags are rejected.
TEST(ServerTagTest, malformed) {<--- syntax error
    {
        SCOPED_TRACE("empty tag");
        EXPECT_THROW(ServerTag(""), BadValue);
    }

    {
        SCOPED_TRACE("only whitespaces");
        EXPECT_THROW(ServerTag("   "), BadValue);
    }

    {
        SCOPED_TRACE("too long tag, max is 256");
        EXPECT_THROW(ServerTag(std::string(257, 'c')), BadValue);
    }

    {
        SCOPED_TRACE("use reserved keyword any as a tag");
        EXPECT_THROW(ServerTag("any"), BadValue);
    }
}

}