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
// Copyright (C) 2020-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/.

#ifndef STATS_TEST_UTILS_H
#define STATS_TEST_UTILS_H

#include <cc/data.h>
#include <stats/stats_mgr.h>

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

namespace isc {
namespace stats {
namespace test {

/// @brief Type of name x value for statistics.
typedef std::map<std::string, int64_t> StatMap;

/// @brief Compares a statistic to an expected value.
///
/// Attempt to fetch the named statistic from the StatsMgr and if
/// found, compare its observed value to the given value.
/// Fails if the stat is not found or if the values do not match.
///
/// @param name StatsMgr name for the statistic to check.
/// @param expected_value expected value of the statistic.
inline void checkStat(const std::string& name,
                      const isc::util::int128_t expected_value) {
    ObservationPtr const obs(isc::stats::StatsMgr::instance().getObservation(name));

    ASSERT_TRUE(obs) << "stat " << name << " not found ";
    if (obs->getType() == Observation::STAT_INTEGER) {
        EXPECT_EQ(expected_value, obs->getInteger().first)
            << " wrong value for stat " << name;
    } else if (obs->getType() == Observation::STAT_BIG_INTEGER) {
        EXPECT_EQ(expected_value, obs->getBigInteger().first)
            << " wrong value for stat " << name;
    } else {
        GTEST_FAIL() << "unexpected statistic type: "
                     << Observation::typeToText(obs->getType());
    }
}

/// @brief Check if a statistic does not exists.
///
/// @param name StatsMgr name for the statistic to check.
inline void checkNoStat(const std::string& name) {
    using namespace isc::stats;
    EXPECT_FALSE(StatsMgr::instance().getObservation(name));
}

/// @brief Compares StatsMgr statistics against expected values.
///
/// Iterates over a list of statistic names and expected values, attempting
/// to fetch each from the StatsMgr and if found, compare its observed
/// value to the expected value. Fails if any of the expected stats are not
/// found or if the values do not match.
///
/// @param expected_stats Map of expected static names and values.
inline void checkStats(const StatMap& expected_stats) {
    for (auto const& it : expected_stats) {
        checkStat(it.first, it.second);
    }
}

}
}
}

#endif // STATS_TEST_UTILS_H