blob: 45a0042f4a26af5f598cb509ce7153081c8d228e (
plain)
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
|
// Copyright (C) 2018-2023 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/.
#ifndef PACKET_QUEUE_TESTUTILS_H
#define PACKET_QUEUE_TESTUTILS_H
#include <config.h>
#include <dhcp/packet_queue.h>
#include <boost/shared_ptr.hpp>
#include <gtest/gtest.h>
namespace isc {
namespace dhcp {
namespace test {
template<typename PacketQueuePtrType>
void checkInfo(PacketQueuePtrType queue, const std::string& exp_json) {
ASSERT_TRUE(queue) << "packet queue ptr is null";
// Fetch the queue info and verify it has all the expected values.
data::ElementPtr info;
ASSERT_NO_THROW(info = queue->getInfo());
ASSERT_TRUE(info);
data::ElementPtr exp_elems;
ASSERT_NO_THROW(exp_elems = data::Element::fromJSON(exp_json)) <<
" exp_elems is invalid JSON : " << exp_json << " test is broken";
EXPECT_TRUE(exp_elems->equals(*info));
}
#define CHECK_QUEUE_INFO(queue, stream) \
{ \
std::ostringstream oss__; \
oss__ << stream; \
checkInfo(queue, oss__.str().c_str());\
}
template<typename PacketQueuePtrType>
void checkIntStat(PacketQueuePtrType queue, const std::string& name, size_t exp_value) {
ASSERT_TRUE(queue) << "packet queue ptr is null";
data::ElementPtr info;
ASSERT_NO_THROW(info = queue->getInfo());
ASSERT_TRUE(info);
data::ConstElementPtr elem;
ASSERT_NO_THROW(elem = info->get(name)) << "stat: " << name << " not in info" << std::endl;
ASSERT_TRUE(elem);
int64_t value = 0;
ASSERT_NO_THROW(value = elem->intValue());
EXPECT_EQ(exp_value, value) << "stat: " << name << " is wrong" << std::endl;;
}
extern data::ElementPtr makeQueueConfig(const std::string& queue_type, size_t capacity, bool enable_queue=true);
} // namespace test
} // namespace dhcp
} // namespace isc
#endif // PACKET_QUEUE_TESTUTILS_H
|