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
98
99
100
101
102
103 | // Copyright (C) 2018,2021 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 <eval/dependency.h>
#include <eval/eval_context.h>
#include <eval/token.h>
#include <dhcp/pkt4.h>
#include <dhcp/pkt6.h>
#include <dhcp/dhcp4.h>
#include <dhcp/dhcp6.h>
#include <dhcp/option_string.h>
#include <boost/shared_ptr.hpp><--- Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results.
#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.
using namespace std;
using namespace isc::dhcp;
namespace {
/// @brief Test fixture for testing dependency.
///
/// This class provides several convenience objects to be used during testing
/// of the dependency of classification expressions.
class DependencyTest : public ::testing::Test {
public:
/// @brief Constructor
DependencyTest() : result_(true) {
}
/// @brief Destructor
///
/// Reset expression and result.
~DependencyTest() {
e_.reset();
result_ = false;
}
ExpressionPtr e_; ///< An expression
bool result_; ///< A decision
};
// This checks the null expression: it should return false.
TEST_F(DependencyTest, nullExpr) {<--- syntax error
TokenPtr token;
ASSERT_NO_THROW(result_ = dependOnClass(token, "foobar"));
EXPECT_FALSE(result_);
ASSERT_NO_THROW(result_ = dependOnClass(e_, "foobar"));
EXPECT_FALSE(result_);
}
// This checks the empty expression: it should return false.
TEST_F(DependencyTest, emptyExpr) {
e_.reset(new Expression());
ASSERT_NO_THROW(result_ = dependOnClass(e_, "foobar"));
EXPECT_FALSE(result_);
}
// This checks the { "true" } expression: it should return false.
TEST_F(DependencyTest, trueExpr) {
TokenPtr ttrue;
ASSERT_NO_THROW(ttrue.reset(new TokenString("true")));
ASSERT_NO_THROW(result_ = dependOnClass(ttrue, "foobar"));
EXPECT_FALSE(result_);
e_.reset(new Expression());
e_->push_back(ttrue);
ASSERT_NO_THROW(result_ = dependOnClass(e_, "foobar"));
EXPECT_FALSE(result_);
}
// This checks the { member('not-matching') } expression:
// it should return false.
TEST_F(DependencyTest, notMatching) {
TokenPtr notmatching;
ASSERT_NO_THROW(notmatching.reset(new TokenMember("not-matching")));
ASSERT_NO_THROW(result_ = dependOnClass(notmatching, "foobar"));
EXPECT_FALSE(result_);
e_.reset(new Expression());
e_->push_back(notmatching);
ASSERT_NO_THROW(result_ = dependOnClass(e_, "foobar"));
EXPECT_FALSE(result_);
}
// This checks the { member('foobar') } expression: it should return true.
TEST_F(DependencyTest, matching) {
TokenPtr matching;
ASSERT_NO_THROW(matching.reset(new TokenMember("foobar")));
ASSERT_NO_THROW(result_ = dependOnClass(matching, "foobar"));
EXPECT_TRUE(result_);
e_.reset(new Expression());
e_->push_back(matching);
result_ = false;
ASSERT_NO_THROW(result_ = dependOnClass(e_, "foobar"));
EXPECT_TRUE(result_);
}
};
|