| File: | home/fedora/workspace/kea-dev/clang-static-analyzer/build/meson-private/tmpxsedttj5/../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc |
| Warning: | line 537, column 10 Value stored to 'start_time' during its initialization is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | // Copyright (C) 2024-2025 Internet Systems Consortium, Inc. ("ISC") |
| 2 | // |
| 3 | // This Source Code Form is subject to the terms of the Mozilla Public |
| 4 | // License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 | // file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 6 | |
| 7 | #include <config.h> |
| 8 | #include <monitored_duration.h> |
| 9 | #include <cc/data.h> |
| 10 | #include <dhcp/dhcp6.h> |
| 11 | #include <util/boost_time_utils.h> |
| 12 | #include <testutils/gtest_utils.h> |
| 13 | #include <testutils/test_to_element.h> |
| 14 | |
| 15 | #include <gtest/gtest.h> |
| 16 | #include <sstream> |
| 17 | #include <unordered_set> |
| 18 | |
| 19 | using namespace isc; |
| 20 | using namespace isc::data; |
| 21 | using namespace isc::dhcp; |
| 22 | using namespace isc::perfmon; |
| 23 | using namespace isc::util; |
| 24 | using namespace isc::test; |
| 25 | using namespace boost::posix_time; |
| 26 | |
| 27 | namespace { |
| 28 | |
| 29 | // Exercises the basic functions of DurationDataInterval. |
| 30 | TEST(DurationDataInterval, basics)static_assert(sizeof("DurationDataInterval") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("basics") > 1, "test_name must not be empty" ); class DurationDataInterval_basics_Test : public ::testing:: Test { public: DurationDataInterval_basics_Test() = default; ~ DurationDataInterval_basics_Test() override = default; DurationDataInterval_basics_Test (const DurationDataInterval_basics_Test &) = delete; DurationDataInterval_basics_Test & operator=( const DurationDataInterval_basics_Test & ) = delete; DurationDataInterval_basics_Test (DurationDataInterval_basics_Test &&) noexcept = delete; DurationDataInterval_basics_Test & operator=( DurationDataInterval_basics_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const DurationDataInterval_basics_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "DurationDataInterval" , "basics", nullptr, nullptr, ::testing::internal::CodeLocation ("../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 30), (::testing::internal::GetTestTypeId()), ::testing::internal ::SuiteApiResolver< ::testing::Test>::GetSetUpCaseOrSuite ("../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 30), ::testing::internal::SuiteApiResolver< ::testing::Test >::GetTearDownCaseOrSuite("../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 30), new ::testing::internal::TestFactoryImpl<DurationDataInterval_basics_Test >); void DurationDataInterval_basics_Test::TestBody() { |
| 31 | auto start_time = PktEvent::now(); |
| 32 | |
| 33 | DurationDataIntervalPtr interval; |
| 34 | |
| 35 | // Default Construct a interval. |
| 36 | interval.reset(new DurationDataInterval()); |
| 37 | ASSERT_TRUE(interval)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(interval)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 37, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "interval", "false", "true") .c_str()) = ::testing::Message (); |
| 38 | |
| 39 | // Verify contents. |
| 40 | // Start time is set to current time by default. |
| 41 | EXPECT_GE(interval->getStartTime(), start_time)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperGE("interval->getStartTime()" , "start_time", interval->getStartTime(), start_time))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 41, gtest_ar.failure_message()) = ::testing::Message(); |
| 42 | EXPECT_EQ(interval->getOccurrences(), 0)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("interval->getOccurrences()" , "0", interval->getOccurrences(), 0))) ; else ::testing:: internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 42, gtest_ar.failure_message()) = ::testing::Message(); |
| 43 | EXPECT_EQ(interval->getMinDuration(), pos_infin)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("interval->getMinDuration()" , "pos_infin", interval->getMinDuration(), pos_infin))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 43, gtest_ar.failure_message()) = ::testing::Message(); |
| 44 | EXPECT_EQ(interval->getMaxDuration(), neg_infin)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("interval->getMaxDuration()" , "neg_infin", interval->getMaxDuration(), neg_infin))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 44, gtest_ar.failure_message()) = ::testing::Message(); |
| 45 | EXPECT_EQ(interval->getTotalDuration(), DurationDataInterval::ZERO_DURATION())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("interval->getTotalDuration()" , "DurationDataInterval::ZERO_DURATION()", interval->getTotalDuration (), DurationDataInterval::ZERO_DURATION()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 45, gtest_ar.failure_message()) = ::testing::Message(); |
| 46 | EXPECT_EQ(interval->getMeanDuration(), DurationDataInterval::ZERO_DURATION())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("interval->getMeanDuration()" , "DurationDataInterval::ZERO_DURATION()", interval->getMeanDuration (), DurationDataInterval::ZERO_DURATION()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 46, gtest_ar.failure_message()) = ::testing::Message(); |
| 47 | |
| 48 | // Verify that start time can be specified. |
| 49 | interval.reset(new DurationDataInterval(start_time + milliseconds(5000))); |
| 50 | ASSERT_TRUE(interval)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(interval)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 50, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "interval", "false", "true") .c_str()) = ::testing::Message (); |
| 51 | EXPECT_EQ(interval->getStartTime() - start_time, milliseconds(5000))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("interval->getStartTime() - start_time" , "milliseconds(5000)", interval->getStartTime() - start_time , milliseconds(5000)))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 51, gtest_ar.failure_message()) = ::testing::Message(); |
| 52 | |
| 53 | // Add 100ms duration and check contents. |
| 54 | Duration d100(milliseconds(100)); |
| 55 | interval->addDuration(d100); |
| 56 | EXPECT_EQ(interval->getOccurrences(), 1)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("interval->getOccurrences()" , "1", interval->getOccurrences(), 1))) ; else ::testing:: internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 56, gtest_ar.failure_message()) = ::testing::Message(); |
| 57 | EXPECT_EQ(interval->getMinDuration(), d100)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("interval->getMinDuration()" , "d100", interval->getMinDuration(), d100))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 57, gtest_ar.failure_message()) = ::testing::Message(); |
| 58 | EXPECT_EQ(interval->getMaxDuration(), d100)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("interval->getMaxDuration()" , "d100", interval->getMaxDuration(), d100))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 58, gtest_ar.failure_message()) = ::testing::Message(); |
| 59 | EXPECT_EQ(interval->getTotalDuration(), d100)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("interval->getTotalDuration()" , "d100", interval->getTotalDuration(), d100))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 59, gtest_ar.failure_message()) = ::testing::Message(); |
| 60 | EXPECT_EQ(interval->getMeanDuration(), d100)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("interval->getMeanDuration()" , "d100", interval->getMeanDuration(), d100))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 60, gtest_ar.failure_message()) = ::testing::Message(); |
| 61 | |
| 62 | // Add 300ms duration and check contents. |
| 63 | Duration d300(milliseconds(300)); |
| 64 | interval->addDuration(d300); |
| 65 | EXPECT_EQ(interval->getOccurrences(), 2)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("interval->getOccurrences()" , "2", interval->getOccurrences(), 2))) ; else ::testing:: internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 65, gtest_ar.failure_message()) = ::testing::Message(); |
| 66 | EXPECT_EQ(interval->getMinDuration(), d100)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("interval->getMinDuration()" , "d100", interval->getMinDuration(), d100))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 66, gtest_ar.failure_message()) = ::testing::Message(); |
| 67 | EXPECT_EQ(interval->getMaxDuration(), d300)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("interval->getMaxDuration()" , "d300", interval->getMaxDuration(), d300))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 67, gtest_ar.failure_message()) = ::testing::Message(); |
| 68 | EXPECT_EQ(interval->getTotalDuration(), d100 + d300)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("interval->getTotalDuration()" , "d100 + d300", interval->getTotalDuration(), d100 + d300 ))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 68, gtest_ar.failure_message()) = ::testing::Message(); |
| 69 | EXPECT_EQ(interval->getMeanDuration(), Duration(milliseconds(200)))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("interval->getMeanDuration()" , "Duration(milliseconds(200))", interval->getMeanDuration (), Duration(milliseconds(200))))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 69, gtest_ar.failure_message()) = ::testing::Message(); |
| 70 | |
| 71 | // Add 50ms duration and check contents. |
| 72 | Duration d50(milliseconds(50)); |
| 73 | interval->addDuration(d50); |
| 74 | EXPECT_EQ(interval->getOccurrences(), 3)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("interval->getOccurrences()" , "3", interval->getOccurrences(), 3))) ; else ::testing:: internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 74, gtest_ar.failure_message()) = ::testing::Message(); |
| 75 | EXPECT_EQ(interval->getMinDuration(), d50)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("interval->getMinDuration()" , "d50", interval->getMinDuration(), d50))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 75, gtest_ar.failure_message()) = ::testing::Message(); |
| 76 | EXPECT_EQ(interval->getMaxDuration(), d300)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("interval->getMaxDuration()" , "d300", interval->getMaxDuration(), d300))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 76, gtest_ar.failure_message()) = ::testing::Message(); |
| 77 | EXPECT_EQ(interval->getTotalDuration(), d100 + d300 + d50)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("interval->getTotalDuration()" , "d100 + d300 + d50", interval->getTotalDuration(), d100 + d300 + d50))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 77, gtest_ar.failure_message()) = ::testing::Message(); |
| 78 | EXPECT_EQ(interval->getMeanDuration(), Duration(milliseconds(150)))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("interval->getMeanDuration()" , "Duration(milliseconds(150))", interval->getMeanDuration (), Duration(milliseconds(150))))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 78, gtest_ar.failure_message()) = ::testing::Message(); |
| 79 | |
| 80 | // Add a zero duration and check contents. |
| 81 | interval->addDuration(DurationDataInterval::ZERO_DURATION()); |
| 82 | EXPECT_EQ(interval->getOccurrences(), 4)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("interval->getOccurrences()" , "4", interval->getOccurrences(), 4))) ; else ::testing:: internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 82, gtest_ar.failure_message()) = ::testing::Message(); |
| 83 | EXPECT_EQ(interval->getMinDuration(), DurationDataInterval::ZERO_DURATION())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("interval->getMinDuration()" , "DurationDataInterval::ZERO_DURATION()", interval->getMinDuration (), DurationDataInterval::ZERO_DURATION()))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 83, gtest_ar.failure_message()) = ::testing::Message(); |
| 84 | EXPECT_EQ(interval->getMaxDuration(), d300)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("interval->getMaxDuration()" , "d300", interval->getMaxDuration(), d300))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 84, gtest_ar.failure_message()) = ::testing::Message(); |
| 85 | EXPECT_EQ(interval->getTotalDuration(), d100 + d300 + d50)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("interval->getTotalDuration()" , "d100 + d300 + d50", interval->getTotalDuration(), d100 + d300 + d50))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 85, gtest_ar.failure_message()) = ::testing::Message(); |
| 86 | EXPECT_EQ(interval->getMeanDuration(), Duration(microseconds(112500)))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("interval->getMeanDuration()" , "Duration(microseconds(112500))", interval->getMeanDuration (), Duration(microseconds(112500))))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 86, gtest_ar.failure_message()) = ::testing::Message(); |
| 87 | } |
| 88 | |
| 89 | // Exercises the basic functions of DurationDataInterval. |
| 90 | TEST(DurationKey, basics)static_assert(sizeof("DurationKey") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("basics") > 1, "test_name must not be empty" ); class DurationKey_basics_Test : public ::testing::Test { public : DurationKey_basics_Test() = default; ~DurationKey_basics_Test () override = default; DurationKey_basics_Test (const DurationKey_basics_Test &) = delete; DurationKey_basics_Test & operator=( const DurationKey_basics_Test &) = delete; DurationKey_basics_Test (DurationKey_basics_Test &&) noexcept = delete; DurationKey_basics_Test & operator=( DurationKey_basics_Test &&) noexcept = delete; private: void TestBody() override; [[maybe_unused] ] static ::testing::TestInfo* const test_info_; }; ::testing:: TestInfo* const DurationKey_basics_Test::test_info_ = ::testing ::internal::MakeAndRegisterTestInfo( "DurationKey", "basics", nullptr, nullptr, ::testing::internal::CodeLocation("../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 90), (::testing::internal::GetTestTypeId()), ::testing::internal ::SuiteApiResolver< ::testing::Test>::GetSetUpCaseOrSuite ("../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 90), ::testing::internal::SuiteApiResolver< ::testing::Test >::GetTearDownCaseOrSuite("../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 90), new ::testing::internal::TestFactoryImpl<DurationKey_basics_Test >); void DurationKey_basics_Test::TestBody() { |
| 91 | DurationKeyPtr key; |
| 92 | |
| 93 | // Create valid v4 key, verify contents and label. |
| 94 | ASSERT_NO_THROW_LOG(key.reset(new DurationKey(AF_INET, DHCPDISCOVER, DHCPOFFER,{ try { key.reset(new DurationKey(2, DHCPDISCOVER, DHCPOFFER, "process_started", "process_completed", SUBNET_ID_GLOBAL)); } catch (const std::exception& ex) { return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 96, "Failed") = ::testing::Message() << "key.reset(new DurationKey(AF_INET, DHCPDISCOVER, DHCPOFFER, \"process_started\", \"process_completed\", SUBNET_ID_GLOBAL))" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 96, "Failed") = ::testing::Message() << "key.reset(new DurationKey(AF_INET, DHCPDISCOVER, DHCPOFFER, \"process_started\", \"process_completed\", SUBNET_ID_GLOBAL))" << " threw non-std::exception"; } } |
| 95 | "process_started", "process_completed",{ try { key.reset(new DurationKey(2, DHCPDISCOVER, DHCPOFFER, "process_started", "process_completed", SUBNET_ID_GLOBAL)); } catch (const std::exception& ex) { return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 96, "Failed") = ::testing::Message() << "key.reset(new DurationKey(AF_INET, DHCPDISCOVER, DHCPOFFER, \"process_started\", \"process_completed\", SUBNET_ID_GLOBAL))" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 96, "Failed") = ::testing::Message() << "key.reset(new DurationKey(AF_INET, DHCPDISCOVER, DHCPOFFER, \"process_started\", \"process_completed\", SUBNET_ID_GLOBAL))" << " threw non-std::exception"; } } |
| 96 | SUBNET_ID_GLOBAL))){ try { key.reset(new DurationKey(2, DHCPDISCOVER, DHCPOFFER, "process_started", "process_completed", SUBNET_ID_GLOBAL)); } catch (const std::exception& ex) { return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 96, "Failed") = ::testing::Message() << "key.reset(new DurationKey(AF_INET, DHCPDISCOVER, DHCPOFFER, \"process_started\", \"process_completed\", SUBNET_ID_GLOBAL))" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 96, "Failed") = ::testing::Message() << "key.reset(new DurationKey(AF_INET, DHCPDISCOVER, DHCPOFFER, \"process_started\", \"process_completed\", SUBNET_ID_GLOBAL))" << " threw non-std::exception"; } }; |
| 97 | ASSERT_TRUE(key)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(key)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 97, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "key", "false", "true") .c_str()) = ::testing::Message(); |
| 98 | EXPECT_EQ(key->getFamily(), AF_INET)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("key->getFamily()" , "2", key->getFamily(), 2))) ; else ::testing::internal:: AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 98, gtest_ar.failure_message()) = ::testing::Message(); |
| 99 | EXPECT_EQ(key->getQueryType(), DHCPDISCOVER)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("key->getQueryType()" , "DHCPDISCOVER", key->getQueryType(), DHCPDISCOVER))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 99, gtest_ar.failure_message()) = ::testing::Message(); |
| 100 | EXPECT_EQ(key->getResponseType(), DHCPOFFER)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("key->getResponseType()" , "DHCPOFFER", key->getResponseType(), DHCPOFFER))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 100, gtest_ar.failure_message()) = ::testing::Message(); |
| 101 | EXPECT_EQ(key->getStartEventLabel(), "process_started")switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("key->getStartEventLabel()" , "\"process_started\"", key->getStartEventLabel(), "process_started" ))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 101, gtest_ar.failure_message()) = ::testing::Message(); |
| 102 | EXPECT_EQ(key->getStopEventLabel(), "process_completed")switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("key->getStopEventLabel()" , "\"process_completed\"", key->getStopEventLabel(), "process_completed" ))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 102, gtest_ar.failure_message()) = ::testing::Message(); |
| 103 | EXPECT_EQ(key->getSubnetId(), SUBNET_ID_GLOBAL)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("key->getSubnetId()" , "SUBNET_ID_GLOBAL", key->getSubnetId(), SUBNET_ID_GLOBAL ))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 103, gtest_ar.failure_message()) = ::testing::Message(); |
| 104 | EXPECT_EQ("DHCPDISCOVER-DHCPOFFER.process_started-process_completed.0",switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"DHCPDISCOVER-DHCPOFFER.process_started-process_completed.0\"" , "key->getLabel()", "DHCPDISCOVER-DHCPOFFER.process_started-process_completed.0" , key->getLabel()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 105, gtest_ar.failure_message()) = ::testing::Message() |
| 105 | key->getLabel())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"DHCPDISCOVER-DHCPOFFER.process_started-process_completed.0\"" , "key->getLabel()", "DHCPDISCOVER-DHCPOFFER.process_started-process_completed.0" , key->getLabel()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 105, gtest_ar.failure_message()) = ::testing::Message(); |
| 106 | EXPECT_EQ("perfmon.DHCPDISCOVER-DHCPOFFER.process_started-process_completed.mean-usecs",switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"perfmon.DHCPDISCOVER-DHCPOFFER.process_started-process_completed.mean-usecs\"" , "key->getStatName(\"mean-usecs\")", "perfmon.DHCPDISCOVER-DHCPOFFER.process_started-process_completed.mean-usecs" , key->getStatName("mean-usecs")))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 107, gtest_ar.failure_message()) = ::testing::Message() |
| 107 | key->getStatName("mean-usecs"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"perfmon.DHCPDISCOVER-DHCPOFFER.process_started-process_completed.mean-usecs\"" , "key->getStatName(\"mean-usecs\")", "perfmon.DHCPDISCOVER-DHCPOFFER.process_started-process_completed.mean-usecs" , key->getStatName("mean-usecs")))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 107, gtest_ar.failure_message()) = ::testing::Message(); |
| 108 | |
| 109 | // Create valid v6 key, verify contents and label. |
| 110 | ASSERT_NO_THROW_LOG(key.reset(new DurationKey(AF_INET6, DHCPV6_SOLICIT, DHCPV6_ADVERTISE,{ try { key.reset(new DurationKey(10, DHCPV6_SOLICIT, DHCPV6_ADVERTISE , "mt_queued", "process_started", 77)); } catch (const std::exception & ex) { return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 111, "Failed") = ::testing::Message() << "key.reset(new DurationKey(AF_INET6, DHCPV6_SOLICIT, DHCPV6_ADVERTISE, \"mt_queued\", \"process_started\", 77))" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 111, "Failed") = ::testing::Message() << "key.reset(new DurationKey(AF_INET6, DHCPV6_SOLICIT, DHCPV6_ADVERTISE, \"mt_queued\", \"process_started\", 77))" << " threw non-std::exception"; } } |
| 111 | "mt_queued", "process_started", 77))){ try { key.reset(new DurationKey(10, DHCPV6_SOLICIT, DHCPV6_ADVERTISE , "mt_queued", "process_started", 77)); } catch (const std::exception & ex) { return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 111, "Failed") = ::testing::Message() << "key.reset(new DurationKey(AF_INET6, DHCPV6_SOLICIT, DHCPV6_ADVERTISE, \"mt_queued\", \"process_started\", 77))" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 111, "Failed") = ::testing::Message() << "key.reset(new DurationKey(AF_INET6, DHCPV6_SOLICIT, DHCPV6_ADVERTISE, \"mt_queued\", \"process_started\", 77))" << " threw non-std::exception"; } }; |
| 112 | ASSERT_TRUE(key)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(key)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 112, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "key", "false", "true") .c_str()) = ::testing::Message(); |
| 113 | EXPECT_EQ(key->getFamily(), AF_INET6)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("key->getFamily()" , "10", key->getFamily(), 10))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 113, gtest_ar.failure_message()) = ::testing::Message(); |
| 114 | EXPECT_EQ(key->getQueryType(), DHCPV6_SOLICIT)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("key->getQueryType()" , "DHCPV6_SOLICIT", key->getQueryType(), DHCPV6_SOLICIT))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 114, gtest_ar.failure_message()) = ::testing::Message(); |
| 115 | EXPECT_EQ(key->getResponseType(), DHCPV6_ADVERTISE)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("key->getResponseType()" , "DHCPV6_ADVERTISE", key->getResponseType(), DHCPV6_ADVERTISE ))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 115, gtest_ar.failure_message()) = ::testing::Message(); |
| 116 | EXPECT_EQ(key->getStartEventLabel(), "mt_queued")switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("key->getStartEventLabel()" , "\"mt_queued\"", key->getStartEventLabel(), "mt_queued") )) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 116, gtest_ar.failure_message()) = ::testing::Message(); |
| 117 | EXPECT_EQ(key->getStopEventLabel(), "process_started")switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("key->getStopEventLabel()" , "\"process_started\"", key->getStopEventLabel(), "process_started" ))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 117, gtest_ar.failure_message()) = ::testing::Message(); |
| 118 | EXPECT_EQ(key->getSubnetId(), 77)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("key->getSubnetId()" , "77", key->getSubnetId(), 77))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 118, gtest_ar.failure_message()) = ::testing::Message(); |
| 119 | EXPECT_EQ("SOLICIT-ADVERTISE.mt_queued-process_started.77",switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"SOLICIT-ADVERTISE.mt_queued-process_started.77\"" , "key->getLabel()", "SOLICIT-ADVERTISE.mt_queued-process_started.77" , key->getLabel()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 120, gtest_ar.failure_message()) = ::testing::Message() |
| 120 | key->getLabel())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"SOLICIT-ADVERTISE.mt_queued-process_started.77\"" , "key->getLabel()", "SOLICIT-ADVERTISE.mt_queued-process_started.77" , key->getLabel()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 120, gtest_ar.failure_message()) = ::testing::Message(); |
| 121 | EXPECT_EQ("subnet-id[77].perfmon.SOLICIT-ADVERTISE.mt_queued-process_started.mean-usecs",switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"subnet-id[77].perfmon.SOLICIT-ADVERTISE.mt_queued-process_started.mean-usecs\"" , "key->getStatName(\"mean-usecs\")", "subnet-id[77].perfmon.SOLICIT-ADVERTISE.mt_queued-process_started.mean-usecs" , key->getStatName("mean-usecs")))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 122, gtest_ar.failure_message()) = ::testing::Message() |
| 122 | key->getStatName("mean-usecs"))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"subnet-id[77].perfmon.SOLICIT-ADVERTISE.mt_queued-process_started.mean-usecs\"" , "key->getStatName(\"mean-usecs\")", "subnet-id[77].perfmon.SOLICIT-ADVERTISE.mt_queued-process_started.mean-usecs" , key->getStatName("mean-usecs")))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 122, gtest_ar.failure_message()) = ::testing::Message(); |
| 123 | |
| 124 | // Make sure constructor catches an insane message pairing. |
| 125 | ASSERT_THROW_MSG(key.reset(new DurationKey(AF_INET6, DHCPV6_ADVERTISE, DHCPV6_SOLICIT,{ try { key.reset(new DurationKey(10, DHCPV6_ADVERTISE, DHCPV6_SOLICIT , "mt_queued", "process_started", 77)); return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 127, "Failed") = ::testing::Message() << "no exception, expected: " << "BadValue"; } catch (const BadValue& ex) { switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("std::string(ex.what())" , "\"Query type not supported by monitoring: ADVERTISE\"", std ::string(ex.what()), "Query type not supported by monitoring: ADVERTISE" ))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 127, gtest_ar.failure_message()) = ::testing::Message(); } catch (...) { return ::testing::internal::AssertHelper(::testing:: TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 127, "Failed") = ::testing::Message() << "wrong exception type thrown, expected: " << "BadValue"; } } |
| 126 | "mt_queued", "process_started", 77)), BadValue,{ try { key.reset(new DurationKey(10, DHCPV6_ADVERTISE, DHCPV6_SOLICIT , "mt_queued", "process_started", 77)); return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 127, "Failed") = ::testing::Message() << "no exception, expected: " << "BadValue"; } catch (const BadValue& ex) { switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("std::string(ex.what())" , "\"Query type not supported by monitoring: ADVERTISE\"", std ::string(ex.what()), "Query type not supported by monitoring: ADVERTISE" ))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 127, gtest_ar.failure_message()) = ::testing::Message(); } catch (...) { return ::testing::internal::AssertHelper(::testing:: TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 127, "Failed") = ::testing::Message() << "wrong exception type thrown, expected: " << "BadValue"; } } |
| 127 | "Query type not supported by monitoring: ADVERTISE"){ try { key.reset(new DurationKey(10, DHCPV6_ADVERTISE, DHCPV6_SOLICIT , "mt_queued", "process_started", 77)); return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 127, "Failed") = ::testing::Message() << "no exception, expected: " << "BadValue"; } catch (const BadValue& ex) { switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("std::string(ex.what())" , "\"Query type not supported by monitoring: ADVERTISE\"", std ::string(ex.what()), "Query type not supported by monitoring: ADVERTISE" ))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 127, gtest_ar.failure_message()) = ::testing::Message(); } catch (...) { return ::testing::internal::AssertHelper(::testing:: TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 127, "Failed") = ::testing::Message() << "wrong exception type thrown, expected: " << "BadValue"; } }; |
| 128 | } |
| 129 | |
| 130 | // Verify v4 message pair validation works. |
| 131 | TEST(DurationKey, validateMessagePairs4)static_assert(sizeof("DurationKey") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("validateMessagePairs4") > 1, "test_name must not be empty" ); class DurationKey_validateMessagePairs4_Test : public ::testing ::Test { public: DurationKey_validateMessagePairs4_Test() = default ; ~DurationKey_validateMessagePairs4_Test() override = default ; DurationKey_validateMessagePairs4_Test (const DurationKey_validateMessagePairs4_Test &) = delete; DurationKey_validateMessagePairs4_Test & operator=( const DurationKey_validateMessagePairs4_Test & ) = delete; DurationKey_validateMessagePairs4_Test (DurationKey_validateMessagePairs4_Test &&) noexcept = delete; DurationKey_validateMessagePairs4_Test & operator=( DurationKey_validateMessagePairs4_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const DurationKey_validateMessagePairs4_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "DurationKey" , "validateMessagePairs4", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 131), (::testing::internal::GetTestTypeId()), ::testing::internal ::SuiteApiResolver< ::testing::Test>::GetSetUpCaseOrSuite ("../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 131), ::testing::internal::SuiteApiResolver< ::testing:: Test>::GetTearDownCaseOrSuite("../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 131), new ::testing::internal::TestFactoryImpl<DurationKey_validateMessagePairs4_Test >); void DurationKey_validateMessagePairs4_Test::TestBody( ) { |
| 132 | // Defines a test scenario. |
| 133 | struct Scenario { |
| 134 | // Query type to use in the scenario. |
| 135 | uint8_t query_type_; |
| 136 | // Valid response types for query type (if any). |
| 137 | std::unordered_set<uint8_t> valid_responses_; |
| 138 | }; |
| 139 | |
| 140 | // List of scenarios to test, one per v4 message type. |
| 141 | std::list<Scenario> scenarios { |
| 142 | {DHCP_NOTYPE, {DHCP_NOTYPE, DHCPOFFER, DHCPACK, DHCPNAK}}, |
| 143 | {DHCPDISCOVER, {DHCP_NOTYPE, DHCPOFFER, DHCPNAK}}, |
| 144 | {DHCPOFFER, {}}, |
| 145 | {DHCPREQUEST, {DHCP_NOTYPE, DHCPACK, DHCPNAK}}, |
| 146 | {DHCPDECLINE, {}}, |
| 147 | {DHCPACK, {}}, |
| 148 | {DHCPNAK, {}}, |
| 149 | {DHCPRELEASE, {}}, |
| 150 | {DHCPINFORM, {DHCP_NOTYPE, DHCPACK}}, |
| 151 | // {DHCPFORCERENEW, {}}, commented out in dhcp4.h |
| 152 | {DHCPLEASEQUERY, {}}, |
| 153 | {DHCPLEASEUNASSIGNED, {}}, |
| 154 | {DHCPLEASEUNKNOWN, {}}, |
| 155 | {DHCPLEASEACTIVE, {}}, |
| 156 | {DHCPBULKLEASEQUERY, {}}, |
| 157 | {DHCPLEASEQUERYDONE, {}}, |
| 158 | // {DHCPACTIVELEASEQUERY, {}}, commented out in dhcp4.h |
| 159 | {DHCPLEASEQUERYSTATUS, {}}, |
| 160 | {DHCPTLS, {}}, |
| 161 | }; |
| 162 | |
| 163 | // Iterate over the scenarios. Attempt to pair each scenario query type with every v4 message |
| 164 | // type as a response type. If the response type is in the scenario's valid list, the pair |
| 165 | // should validate, otherwise it should throw. |
| 166 | for (auto const& scenario : scenarios) { |
| 167 | for (uint8_t response_type = DHCP_NOTYPE; response_type < DHCP_TYPES_EOF; ++response_type) { |
| 168 | if (scenario.valid_responses_.count(response_type)) { |
| 169 | ASSERT_NO_THROW_LOG({ try { DurationKey::validateMessagePair(2, scenario.query_type_ , response_type); } catch (const std::exception& ex) { return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 170, "Failed") = ::testing::Message() << "DurationKey::validateMessagePair(AF_INET, scenario.query_type_, response_type)" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 170, "Failed") = ::testing::Message() << "DurationKey::validateMessagePair(AF_INET, scenario.query_type_, response_type)" << " threw non-std::exception"; } } |
| 170 | DurationKey::validateMessagePair(AF_INET, scenario.query_type_, response_type)){ try { DurationKey::validateMessagePair(2, scenario.query_type_ , response_type); } catch (const std::exception& ex) { return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 170, "Failed") = ::testing::Message() << "DurationKey::validateMessagePair(AF_INET, scenario.query_type_, response_type)" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 170, "Failed") = ::testing::Message() << "DurationKey::validateMessagePair(AF_INET, scenario.query_type_, response_type)" << " threw non-std::exception"; } }; |
| 171 | } else { |
| 172 | ASSERT_THROW(switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { bool gtest_caught_expected = false; try { if ( ::testing::internal::AlwaysTrue()) { DurationKey::validateMessagePair (2, scenario.query_type_, response_type); } else static_assert (true, ""); } catch (BadValue const&) { gtest_caught_expected = true; } catch (typename std::conditional< std::is_same< typename std::remove_cv<typename std::remove_reference< BadValue>::type>::type, std::exception>::value, const ::testing::internal::NeverThrown&, const std::exception& >::type e) { gtest_msg.value = "Expected: " "DurationKey::validateMessagePair(2, scenario.query_type_, response_type)" " throws an exception of type " "BadValue" ".\n Actual: it throws " ; gtest_msg.value += ::testing::internal::GetTypeName(typeid( e)); gtest_msg.value += " with description \""; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testthrow_174 ; } catch (...) { gtest_msg.value = "Expected: " "DurationKey::validateMessagePair(2, scenario.query_type_, response_type)" " throws an exception of type " "BadValue" ".\n Actual: it throws a different type." ; goto gtest_label_testthrow_174; } if (!gtest_caught_expected ) { gtest_msg.value = "Expected: " "DurationKey::validateMessagePair(2, scenario.query_type_, response_type)" " throws an exception of type " "BadValue" ".\n Actual: it throws nothing." ; goto gtest_label_testthrow_174; } } else gtest_label_testthrow_174 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 174, gtest_msg.value.c_str()) = ::testing::Message() |
| 173 | DurationKey::validateMessagePair(AF_INET, scenario.query_type_, response_type),switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { bool gtest_caught_expected = false; try { if ( ::testing::internal::AlwaysTrue()) { DurationKey::validateMessagePair (2, scenario.query_type_, response_type); } else static_assert (true, ""); } catch (BadValue const&) { gtest_caught_expected = true; } catch (typename std::conditional< std::is_same< typename std::remove_cv<typename std::remove_reference< BadValue>::type>::type, std::exception>::value, const ::testing::internal::NeverThrown&, const std::exception& >::type e) { gtest_msg.value = "Expected: " "DurationKey::validateMessagePair(2, scenario.query_type_, response_type)" " throws an exception of type " "BadValue" ".\n Actual: it throws " ; gtest_msg.value += ::testing::internal::GetTypeName(typeid( e)); gtest_msg.value += " with description \""; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testthrow_174 ; } catch (...) { gtest_msg.value = "Expected: " "DurationKey::validateMessagePair(2, scenario.query_type_, response_type)" " throws an exception of type " "BadValue" ".\n Actual: it throws a different type." ; goto gtest_label_testthrow_174; } if (!gtest_caught_expected ) { gtest_msg.value = "Expected: " "DurationKey::validateMessagePair(2, scenario.query_type_, response_type)" " throws an exception of type " "BadValue" ".\n Actual: it throws nothing." ; goto gtest_label_testthrow_174; } } else gtest_label_testthrow_174 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 174, gtest_msg.value.c_str()) = ::testing::Message() |
| 174 | BadValue)switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { bool gtest_caught_expected = false; try { if ( ::testing::internal::AlwaysTrue()) { DurationKey::validateMessagePair (2, scenario.query_type_, response_type); } else static_assert (true, ""); } catch (BadValue const&) { gtest_caught_expected = true; } catch (typename std::conditional< std::is_same< typename std::remove_cv<typename std::remove_reference< BadValue>::type>::type, std::exception>::value, const ::testing::internal::NeverThrown&, const std::exception& >::type e) { gtest_msg.value = "Expected: " "DurationKey::validateMessagePair(2, scenario.query_type_, response_type)" " throws an exception of type " "BadValue" ".\n Actual: it throws " ; gtest_msg.value += ::testing::internal::GetTypeName(typeid( e)); gtest_msg.value += " with description \""; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testthrow_174 ; } catch (...) { gtest_msg.value = "Expected: " "DurationKey::validateMessagePair(2, scenario.query_type_, response_type)" " throws an exception of type " "BadValue" ".\n Actual: it throws a different type." ; goto gtest_label_testthrow_174; } if (!gtest_caught_expected ) { gtest_msg.value = "Expected: " "DurationKey::validateMessagePair(2, scenario.query_type_, response_type)" " throws an exception of type " "BadValue" ".\n Actual: it throws nothing." ; goto gtest_label_testthrow_174; } } else gtest_label_testthrow_174 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 174, gtest_msg.value.c_str()) = ::testing::Message(); |
| 175 | } |
| 176 | } |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | // Verify v6 message pair validation works. |
| 181 | TEST(DurationKey, validateMessagePairs6)static_assert(sizeof("DurationKey") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("validateMessagePairs6") > 1, "test_name must not be empty" ); class DurationKey_validateMessagePairs6_Test : public ::testing ::Test { public: DurationKey_validateMessagePairs6_Test() = default ; ~DurationKey_validateMessagePairs6_Test() override = default ; DurationKey_validateMessagePairs6_Test (const DurationKey_validateMessagePairs6_Test &) = delete; DurationKey_validateMessagePairs6_Test & operator=( const DurationKey_validateMessagePairs6_Test & ) = delete; DurationKey_validateMessagePairs6_Test (DurationKey_validateMessagePairs6_Test &&) noexcept = delete; DurationKey_validateMessagePairs6_Test & operator=( DurationKey_validateMessagePairs6_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const DurationKey_validateMessagePairs6_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "DurationKey" , "validateMessagePairs6", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 181), (::testing::internal::GetTestTypeId()), ::testing::internal ::SuiteApiResolver< ::testing::Test>::GetSetUpCaseOrSuite ("../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 181), ::testing::internal::SuiteApiResolver< ::testing:: Test>::GetTearDownCaseOrSuite("../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 181), new ::testing::internal::TestFactoryImpl<DurationKey_validateMessagePairs6_Test >); void DurationKey_validateMessagePairs6_Test::TestBody( ) { |
| 182 | // Defines a test scenario. |
| 183 | struct Scenario { |
| 184 | // Query type to use in the scenario. |
| 185 | uint8_t query_type_; |
| 186 | // Valid response types for query type (if any). |
| 187 | std::unordered_set<uint8_t> valid_responses_; |
| 188 | }; |
| 189 | |
| 190 | // List of scenarios to test, one per v6 message type. |
| 191 | std::list<Scenario> scenarios { |
| 192 | {DHCPV6_NOTYPE, {DHCPV6_NOTYPE, DHCPV6_ADVERTISE, DHCPV6_REPLY}}, |
| 193 | {DHCPV6_SOLICIT, {DHCPV6_NOTYPE, DHCPV6_ADVERTISE, DHCPV6_REPLY}}, |
| 194 | {DHCPV6_ADVERTISE, {}}, |
| 195 | {DHCPV6_REQUEST, {DHCPV6_NOTYPE, DHCPV6_REPLY}}, |
| 196 | {DHCPV6_CONFIRM, {DHCPV6_NOTYPE, DHCPV6_REPLY}}, |
| 197 | {DHCPV6_RENEW, {DHCPV6_NOTYPE, DHCPV6_REPLY}}, |
| 198 | {DHCPV6_REBIND, {DHCPV6_NOTYPE, DHCPV6_REPLY}}, |
| 199 | {DHCPV6_REPLY, {}}, |
| 200 | {DHCPV6_RELEASE, {}}, |
| 201 | {DHCPV6_DECLINE, {}}, |
| 202 | {DHCPV6_RECONFIGURE, {}}, |
| 203 | {DHCPV6_INFORMATION_REQUEST, {}}, |
| 204 | {DHCPV6_RELAY_FORW, {}}, |
| 205 | {DHCPV6_RELAY_REPL, {}}, |
| 206 | {DHCPV6_LEASEQUERY, {}}, |
| 207 | {DHCPV6_LEASEQUERY_REPLY, {}}, |
| 208 | {DHCPV6_LEASEQUERY_DONE, {}}, |
| 209 | {DHCPV6_LEASEQUERY_DATA, {}}, |
| 210 | {DHCPV6_RECONFIGURE_REQUEST, {}}, |
| 211 | {DHCPV6_RECONFIGURE_REPLY, {}}, |
| 212 | {DHCPV6_DHCPV4_QUERY, {}}, |
| 213 | {DHCPV6_DHCPV4_RESPONSE, {}}, |
| 214 | {DHCPV6_ACTIVELEASEQUERY, {}}, |
| 215 | {DHCPV6_STARTTLS, {}}, |
| 216 | {DHCPV6_BNDUPD, {}}, |
| 217 | {DHCPV6_BNDREPLY, {}}, |
| 218 | {DHCPV6_POOLREQ, {}}, |
| 219 | {DHCPV6_POOLRESP, {}}, |
| 220 | {DHCPV6_UPDREQ, {}}, |
| 221 | {DHCPV6_UPDREQALL, {}}, |
| 222 | {DHCPV6_UPDDONE, {}}, |
| 223 | {DHCPV6_CONNECT, {}}, |
| 224 | {DHCPV6_CONNECTREPLY, {}}, |
| 225 | {DHCPV6_DISCONNECT, {}}, |
| 226 | {DHCPV6_STATE, {}}, |
| 227 | {DHCPV6_CONTACT, {}} |
| 228 | }; |
| 229 | |
| 230 | // Iterate over the scenarios. Attempt to pair each scenario query type with every v6 message |
| 231 | // type as a response type. If the response type is in the scenario's valid list, the pair |
| 232 | // should validate, otherwise it should throw. |
| 233 | for (auto const& scenario : scenarios) { |
| 234 | for (uint8_t response_type = DHCPV6_NOTYPE; response_type < DHCPV6_TYPES_EOF; ++response_type) { |
| 235 | if (scenario.valid_responses_.count(response_type)) { |
| 236 | ASSERT_NO_THROW_LOG({ try { DurationKey::validateMessagePair(10, scenario.query_type_ , response_type); } catch (const std::exception& ex) { return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 237, "Failed") = ::testing::Message() << "DurationKey::validateMessagePair(AF_INET6, scenario.query_type_, response_type)" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 237, "Failed") = ::testing::Message() << "DurationKey::validateMessagePair(AF_INET6, scenario.query_type_, response_type)" << " threw non-std::exception"; } } |
| 237 | DurationKey::validateMessagePair(AF_INET6, scenario.query_type_, response_type)){ try { DurationKey::validateMessagePair(10, scenario.query_type_ , response_type); } catch (const std::exception& ex) { return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 237, "Failed") = ::testing::Message() << "DurationKey::validateMessagePair(AF_INET6, scenario.query_type_, response_type)" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 237, "Failed") = ::testing::Message() << "DurationKey::validateMessagePair(AF_INET6, scenario.query_type_, response_type)" << " threw non-std::exception"; } }; |
| 238 | } else { |
| 239 | ASSERT_THROW(switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { bool gtest_caught_expected = false; try { if ( ::testing::internal::AlwaysTrue()) { DurationKey::validateMessagePair (10, scenario.query_type_, response_type); } else static_assert (true, ""); } catch (BadValue const&) { gtest_caught_expected = true; } catch (typename std::conditional< std::is_same< typename std::remove_cv<typename std::remove_reference< BadValue>::type>::type, std::exception>::value, const ::testing::internal::NeverThrown&, const std::exception& >::type e) { gtest_msg.value = "Expected: " "DurationKey::validateMessagePair(10, scenario.query_type_, response_type)" " throws an exception of type " "BadValue" ".\n Actual: it throws " ; gtest_msg.value += ::testing::internal::GetTypeName(typeid( e)); gtest_msg.value += " with description \""; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testthrow_241 ; } catch (...) { gtest_msg.value = "Expected: " "DurationKey::validateMessagePair(10, scenario.query_type_, response_type)" " throws an exception of type " "BadValue" ".\n Actual: it throws a different type." ; goto gtest_label_testthrow_241; } if (!gtest_caught_expected ) { gtest_msg.value = "Expected: " "DurationKey::validateMessagePair(10, scenario.query_type_, response_type)" " throws an exception of type " "BadValue" ".\n Actual: it throws nothing." ; goto gtest_label_testthrow_241; } } else gtest_label_testthrow_241 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 241, gtest_msg.value.c_str()) = ::testing::Message() |
| 240 | DurationKey::validateMessagePair(AF_INET6, scenario.query_type_, response_type),switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { bool gtest_caught_expected = false; try { if ( ::testing::internal::AlwaysTrue()) { DurationKey::validateMessagePair (10, scenario.query_type_, response_type); } else static_assert (true, ""); } catch (BadValue const&) { gtest_caught_expected = true; } catch (typename std::conditional< std::is_same< typename std::remove_cv<typename std::remove_reference< BadValue>::type>::type, std::exception>::value, const ::testing::internal::NeverThrown&, const std::exception& >::type e) { gtest_msg.value = "Expected: " "DurationKey::validateMessagePair(10, scenario.query_type_, response_type)" " throws an exception of type " "BadValue" ".\n Actual: it throws " ; gtest_msg.value += ::testing::internal::GetTypeName(typeid( e)); gtest_msg.value += " with description \""; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testthrow_241 ; } catch (...) { gtest_msg.value = "Expected: " "DurationKey::validateMessagePair(10, scenario.query_type_, response_type)" " throws an exception of type " "BadValue" ".\n Actual: it throws a different type." ; goto gtest_label_testthrow_241; } if (!gtest_caught_expected ) { gtest_msg.value = "Expected: " "DurationKey::validateMessagePair(10, scenario.query_type_, response_type)" " throws an exception of type " "BadValue" ".\n Actual: it throws nothing." ; goto gtest_label_testthrow_241; } } else gtest_label_testthrow_241 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 241, gtest_msg.value.c_str()) = ::testing::Message() |
| 241 | BadValue)switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { bool gtest_caught_expected = false; try { if ( ::testing::internal::AlwaysTrue()) { DurationKey::validateMessagePair (10, scenario.query_type_, response_type); } else static_assert (true, ""); } catch (BadValue const&) { gtest_caught_expected = true; } catch (typename std::conditional< std::is_same< typename std::remove_cv<typename std::remove_reference< BadValue>::type>::type, std::exception>::value, const ::testing::internal::NeverThrown&, const std::exception& >::type e) { gtest_msg.value = "Expected: " "DurationKey::validateMessagePair(10, scenario.query_type_, response_type)" " throws an exception of type " "BadValue" ".\n Actual: it throws " ; gtest_msg.value += ::testing::internal::GetTypeName(typeid( e)); gtest_msg.value += " with description \""; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testthrow_241 ; } catch (...) { gtest_msg.value = "Expected: " "DurationKey::validateMessagePair(10, scenario.query_type_, response_type)" " throws an exception of type " "BadValue" ".\n Actual: it throws a different type." ; goto gtest_label_testthrow_241; } if (!gtest_caught_expected ) { gtest_msg.value = "Expected: " "DurationKey::validateMessagePair(10, scenario.query_type_, response_type)" " throws an exception of type " "BadValue" ".\n Actual: it throws nothing." ; goto gtest_label_testthrow_241; } } else gtest_label_testthrow_241 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 241, gtest_msg.value.c_str()) = ::testing::Message(); |
| 242 | } |
| 243 | } |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | /// @brief Verify DurationKey equality operator |
| 248 | TEST(DurationKey, equalityOperators)static_assert(sizeof("DurationKey") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("equalityOperators") > 1, "test_name must not be empty" ); class DurationKey_equalityOperators_Test : public ::testing ::Test { public: DurationKey_equalityOperators_Test() = default ; ~DurationKey_equalityOperators_Test() override = default; DurationKey_equalityOperators_Test (const DurationKey_equalityOperators_Test &) = delete; DurationKey_equalityOperators_Test & operator=( const DurationKey_equalityOperators_Test & ) = delete; DurationKey_equalityOperators_Test (DurationKey_equalityOperators_Test &&) noexcept = delete; DurationKey_equalityOperators_Test & operator=( DurationKey_equalityOperators_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const DurationKey_equalityOperators_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "DurationKey" , "equalityOperators", nullptr, nullptr, ::testing::internal:: CodeLocation("../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 248), (::testing::internal::GetTestTypeId()), ::testing::internal ::SuiteApiResolver< ::testing::Test>::GetSetUpCaseOrSuite ("../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 248), ::testing::internal::SuiteApiResolver< ::testing:: Test>::GetTearDownCaseOrSuite("../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 248), new ::testing::internal::TestFactoryImpl<DurationKey_equalityOperators_Test >); void DurationKey_equalityOperators_Test::TestBody() { |
| 249 | DurationKeyPtr refkey; |
| 250 | DurationKeyPtr compkey; |
| 251 | |
| 252 | ASSERT_NO_THROW_LOG(refkey.reset(new DurationKey(AF_INET6, DHCPV6_REQUEST, DHCPV6_REPLY,{ try { refkey.reset(new DurationKey(10, DHCPV6_REQUEST, DHCPV6_REPLY , "event_2", "event_3", 100)); } catch (const std::exception& ex) { return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 253, "Failed") = ::testing::Message() << "refkey.reset(new DurationKey(AF_INET6, DHCPV6_REQUEST, DHCPV6_REPLY, \"event_2\", \"event_3\", 100))" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 253, "Failed") = ::testing::Message() << "refkey.reset(new DurationKey(AF_INET6, DHCPV6_REQUEST, DHCPV6_REPLY, \"event_2\", \"event_3\", 100))" << " threw non-std::exception"; } } |
| 253 | "event_2", "event_3", 100))){ try { refkey.reset(new DurationKey(10, DHCPV6_REQUEST, DHCPV6_REPLY , "event_2", "event_3", 100)); } catch (const std::exception& ex) { return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 253, "Failed") = ::testing::Message() << "refkey.reset(new DurationKey(AF_INET6, DHCPV6_REQUEST, DHCPV6_REPLY, \"event_2\", \"event_3\", 100))" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 253, "Failed") = ::testing::Message() << "refkey.reset(new DurationKey(AF_INET6, DHCPV6_REQUEST, DHCPV6_REPLY, \"event_2\", \"event_3\", 100))" << " threw non-std::exception"; } }; |
| 254 | |
| 255 | ASSERT_NO_THROW_LOG(compkey.reset(new DurationKey(AF_INET6, DHCPV6_REQUEST, DHCPV6_REPLY,{ try { compkey.reset(new DurationKey(10, DHCPV6_REQUEST, DHCPV6_REPLY , "event_2", "event_3", 100)); } catch (const std::exception& ex) { return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 256, "Failed") = ::testing::Message() << "compkey.reset(new DurationKey(AF_INET6, DHCPV6_REQUEST, DHCPV6_REPLY, \"event_2\", \"event_3\", 100))" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 256, "Failed") = ::testing::Message() << "compkey.reset(new DurationKey(AF_INET6, DHCPV6_REQUEST, DHCPV6_REPLY, \"event_2\", \"event_3\", 100))" << " threw non-std::exception"; } } |
| 256 | "event_2", "event_3", 100))){ try { compkey.reset(new DurationKey(10, DHCPV6_REQUEST, DHCPV6_REPLY , "event_2", "event_3", 100)); } catch (const std::exception& ex) { return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 256, "Failed") = ::testing::Message() << "compkey.reset(new DurationKey(AF_INET6, DHCPV6_REQUEST, DHCPV6_REPLY, \"event_2\", \"event_3\", 100))" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 256, "Failed") = ::testing::Message() << "compkey.reset(new DurationKey(AF_INET6, DHCPV6_REQUEST, DHCPV6_REPLY, \"event_2\", \"event_3\", 100))" << " threw non-std::exception"; } }; |
| 257 | EXPECT_EQ(*compkey, *refkey)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("*compkey" , "*refkey", *compkey, *refkey))) ; else ::testing::internal:: AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 257, gtest_ar.failure_message()) = ::testing::Message(); |
| 258 | |
| 259 | ASSERT_NO_THROW_LOG(compkey.reset(new DurationKey(AF_INET6, DHCPV6_SOLICIT, DHCPV6_REPLY,{ try { compkey.reset(new DurationKey(10, DHCPV6_SOLICIT, DHCPV6_REPLY , "event_2", "event_3", 100)); } catch (const std::exception& ex) { return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 260, "Failed") = ::testing::Message() << "compkey.reset(new DurationKey(AF_INET6, DHCPV6_SOLICIT, DHCPV6_REPLY, \"event_2\", \"event_3\", 100))" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 260, "Failed") = ::testing::Message() << "compkey.reset(new DurationKey(AF_INET6, DHCPV6_SOLICIT, DHCPV6_REPLY, \"event_2\", \"event_3\", 100))" << " threw non-std::exception"; } } |
| 260 | "event_2", "event_3", 100))){ try { compkey.reset(new DurationKey(10, DHCPV6_SOLICIT, DHCPV6_REPLY , "event_2", "event_3", 100)); } catch (const std::exception& ex) { return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 260, "Failed") = ::testing::Message() << "compkey.reset(new DurationKey(AF_INET6, DHCPV6_SOLICIT, DHCPV6_REPLY, \"event_2\", \"event_3\", 100))" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 260, "Failed") = ::testing::Message() << "compkey.reset(new DurationKey(AF_INET6, DHCPV6_SOLICIT, DHCPV6_REPLY, \"event_2\", \"event_3\", 100))" << " threw non-std::exception"; } }; |
| 261 | EXPECT_NE(*compkey, *refkey)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperNE("*compkey", "*refkey" , *compkey, *refkey))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 261, gtest_ar.failure_message()) = ::testing::Message(); |
| 262 | } |
| 263 | |
| 264 | // Verifies the DurationKey::toElement() |
| 265 | TEST(DurationKey, toElement)static_assert(sizeof("DurationKey") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("toElement") > 1, "test_name must not be empty" ); class DurationKey_toElement_Test : public ::testing::Test { public: DurationKey_toElement_Test() = default; ~DurationKey_toElement_Test () override = default; DurationKey_toElement_Test (const DurationKey_toElement_Test &) = delete; DurationKey_toElement_Test & operator=( const DurationKey_toElement_Test &) = delete; DurationKey_toElement_Test (DurationKey_toElement_Test &&) noexcept = delete; DurationKey_toElement_Test & operator=( DurationKey_toElement_Test &&) noexcept = delete; private: void TestBody() override; [[maybe_unused] ] static ::testing::TestInfo* const test_info_; }; ::testing:: TestInfo* const DurationKey_toElement_Test::test_info_ = ::testing ::internal::MakeAndRegisterTestInfo( "DurationKey", "toElement" , nullptr, nullptr, ::testing::internal::CodeLocation("../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 265), (::testing::internal::GetTestTypeId()), ::testing::internal ::SuiteApiResolver< ::testing::Test>::GetSetUpCaseOrSuite ("../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 265), ::testing::internal::SuiteApiResolver< ::testing:: Test>::GetTearDownCaseOrSuite("../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 265), new ::testing::internal::TestFactoryImpl<DurationKey_toElement_Test >); void DurationKey_toElement_Test::TestBody() { |
| 266 | DurationKeyPtr key; |
| 267 | |
| 268 | // Create valid v4 key, verify contents and label. |
| 269 | ASSERT_NO_THROW_LOG(key.reset(new DurationKey(AF_INET, DHCPDISCOVER, DHCPOFFER,{ try { key.reset(new DurationKey(2, DHCPDISCOVER, DHCPOFFER, "process_started", "process_completed", SUBNET_ID_GLOBAL)); } catch (const std::exception& ex) { return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 271, "Failed") = ::testing::Message() << "key.reset(new DurationKey(AF_INET, DHCPDISCOVER, DHCPOFFER, \"process_started\", \"process_completed\", SUBNET_ID_GLOBAL))" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 271, "Failed") = ::testing::Message() << "key.reset(new DurationKey(AF_INET, DHCPDISCOVER, DHCPOFFER, \"process_started\", \"process_completed\", SUBNET_ID_GLOBAL))" << " threw non-std::exception"; } } |
| 270 | "process_started", "process_completed",{ try { key.reset(new DurationKey(2, DHCPDISCOVER, DHCPOFFER, "process_started", "process_completed", SUBNET_ID_GLOBAL)); } catch (const std::exception& ex) { return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 271, "Failed") = ::testing::Message() << "key.reset(new DurationKey(AF_INET, DHCPDISCOVER, DHCPOFFER, \"process_started\", \"process_completed\", SUBNET_ID_GLOBAL))" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 271, "Failed") = ::testing::Message() << "key.reset(new DurationKey(AF_INET, DHCPDISCOVER, DHCPOFFER, \"process_started\", \"process_completed\", SUBNET_ID_GLOBAL))" << " threw non-std::exception"; } } |
| 271 | SUBNET_ID_GLOBAL))){ try { key.reset(new DurationKey(2, DHCPDISCOVER, DHCPOFFER, "process_started", "process_completed", SUBNET_ID_GLOBAL)); } catch (const std::exception& ex) { return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 271, "Failed") = ::testing::Message() << "key.reset(new DurationKey(AF_INET, DHCPDISCOVER, DHCPOFFER, \"process_started\", \"process_completed\", SUBNET_ID_GLOBAL))" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 271, "Failed") = ::testing::Message() << "key.reset(new DurationKey(AF_INET, DHCPDISCOVER, DHCPOFFER, \"process_started\", \"process_completed\", SUBNET_ID_GLOBAL))" << " threw non-std::exception"; } }; |
| 272 | ASSERT_TRUE(key)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(key)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 272, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "key", "false", "true") .c_str()) = ::testing::Message(); |
| 273 | |
| 274 | std::string expected_json = |
| 275 | R"({ |
| 276 | "query-type": "DHCPDISCOVER", |
| 277 | "response-type": "DHCPOFFER", |
| 278 | "start-event": "process_started", |
| 279 | "stop-event": "process_completed", |
| 280 | "subnet-id": 0 |
| 281 | })"; |
| 282 | |
| 283 | runToElementTest(expected_json, *key); |
| 284 | |
| 285 | // Create valid v6 key, verify contents and label. |
| 286 | ASSERT_NO_THROW_LOG(key.reset(new DurationKey(AF_INET6, DHCPV6_SOLICIT, DHCPV6_ADVERTISE,{ try { key.reset(new DurationKey(10, DHCPV6_SOLICIT, DHCPV6_ADVERTISE , "mt_queued", "process_started", 77)); } catch (const std::exception & ex) { return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 287, "Failed") = ::testing::Message() << "key.reset(new DurationKey(AF_INET6, DHCPV6_SOLICIT, DHCPV6_ADVERTISE, \"mt_queued\", \"process_started\", 77))" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 287, "Failed") = ::testing::Message() << "key.reset(new DurationKey(AF_INET6, DHCPV6_SOLICIT, DHCPV6_ADVERTISE, \"mt_queued\", \"process_started\", 77))" << " threw non-std::exception"; } } |
| 287 | "mt_queued", "process_started", 77))){ try { key.reset(new DurationKey(10, DHCPV6_SOLICIT, DHCPV6_ADVERTISE , "mt_queued", "process_started", 77)); } catch (const std::exception & ex) { return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 287, "Failed") = ::testing::Message() << "key.reset(new DurationKey(AF_INET6, DHCPV6_SOLICIT, DHCPV6_ADVERTISE, \"mt_queued\", \"process_started\", 77))" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 287, "Failed") = ::testing::Message() << "key.reset(new DurationKey(AF_INET6, DHCPV6_SOLICIT, DHCPV6_ADVERTISE, \"mt_queued\", \"process_started\", 77))" << " threw non-std::exception"; } }; |
| 288 | ASSERT_TRUE(key)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(key)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 288, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "key", "false", "true") .c_str()) = ::testing::Message(); |
| 289 | |
| 290 | expected_json = |
| 291 | R"({ |
| 292 | "query-type": "SOLICIT", |
| 293 | "response-type": "ADVERTISE", |
| 294 | "start-event": "mt_queued", |
| 295 | "stop-event": "process_started", |
| 296 | "subnet-id": 77 |
| 297 | })"; |
| 298 | |
| 299 | runToElementTest(expected_json, *key); |
| 300 | } |
| 301 | |
| 302 | // Verifies MonitoredDuration valid construction. |
| 303 | TEST(MonitoredDuration, validConstructors)static_assert(sizeof("MonitoredDuration") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("validConstructors") > 1, "test_name must not be empty" ); class MonitoredDuration_validConstructors_Test : public :: testing::Test { public: MonitoredDuration_validConstructors_Test () = default; ~MonitoredDuration_validConstructors_Test() override = default; MonitoredDuration_validConstructors_Test (const MonitoredDuration_validConstructors_Test &) = delete; MonitoredDuration_validConstructors_Test & operator=( const MonitoredDuration_validConstructors_Test & ) = delete; MonitoredDuration_validConstructors_Test (MonitoredDuration_validConstructors_Test &&) noexcept = delete; MonitoredDuration_validConstructors_Test & operator=( MonitoredDuration_validConstructors_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const MonitoredDuration_validConstructors_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "MonitoredDuration" , "validConstructors", nullptr, nullptr, ::testing::internal:: CodeLocation("../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 303), (::testing::internal::GetTestTypeId()), ::testing::internal ::SuiteApiResolver< ::testing::Test>::GetSetUpCaseOrSuite ("../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 303), ::testing::internal::SuiteApiResolver< ::testing:: Test>::GetTearDownCaseOrSuite("../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 303), new ::testing::internal::TestFactoryImpl<MonitoredDuration_validConstructors_Test >); void MonitoredDuration_validConstructors_Test::TestBody () { |
| 304 | MonitoredDurationPtr mond; |
| 305 | Duration interval_duration(seconds(60)); |
| 306 | |
| 307 | // Create valid v4 duration, verify contents and label. |
| 308 | ASSERT_NO_THROW_LOG(mond.reset(new MonitoredDuration(AF_INET, DHCPDISCOVER, DHCPOFFER,{ try { mond.reset(new MonitoredDuration(2, DHCPDISCOVER, DHCPOFFER , "process_started", "process_completed", SUBNET_ID_GLOBAL, interval_duration )); } catch (const std::exception& ex) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 310, "Failed") = ::testing::Message() << "mond.reset(new MonitoredDuration(AF_INET, DHCPDISCOVER, DHCPOFFER, \"process_started\", \"process_completed\", SUBNET_ID_GLOBAL, interval_duration))" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 310, "Failed") = ::testing::Message() << "mond.reset(new MonitoredDuration(AF_INET, DHCPDISCOVER, DHCPOFFER, \"process_started\", \"process_completed\", SUBNET_ID_GLOBAL, interval_duration))" << " threw non-std::exception"; } } |
| 309 | "process_started", "process_completed",{ try { mond.reset(new MonitoredDuration(2, DHCPDISCOVER, DHCPOFFER , "process_started", "process_completed", SUBNET_ID_GLOBAL, interval_duration )); } catch (const std::exception& ex) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 310, "Failed") = ::testing::Message() << "mond.reset(new MonitoredDuration(AF_INET, DHCPDISCOVER, DHCPOFFER, \"process_started\", \"process_completed\", SUBNET_ID_GLOBAL, interval_duration))" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 310, "Failed") = ::testing::Message() << "mond.reset(new MonitoredDuration(AF_INET, DHCPDISCOVER, DHCPOFFER, \"process_started\", \"process_completed\", SUBNET_ID_GLOBAL, interval_duration))" << " threw non-std::exception"; } } |
| 310 | SUBNET_ID_GLOBAL, interval_duration))){ try { mond.reset(new MonitoredDuration(2, DHCPDISCOVER, DHCPOFFER , "process_started", "process_completed", SUBNET_ID_GLOBAL, interval_duration )); } catch (const std::exception& ex) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 310, "Failed") = ::testing::Message() << "mond.reset(new MonitoredDuration(AF_INET, DHCPDISCOVER, DHCPOFFER, \"process_started\", \"process_completed\", SUBNET_ID_GLOBAL, interval_duration))" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 310, "Failed") = ::testing::Message() << "mond.reset(new MonitoredDuration(AF_INET, DHCPDISCOVER, DHCPOFFER, \"process_started\", \"process_completed\", SUBNET_ID_GLOBAL, interval_duration))" << " threw non-std::exception"; } }; |
| 311 | ASSERT_TRUE(mond)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(mond)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 311, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "mond", "false", "true") .c_str()) = ::testing::Message(); |
| 312 | EXPECT_EQ(mond->getFamily(), AF_INET)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("mond->getFamily()" , "2", mond->getFamily(), 2))) ; else ::testing::internal:: AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 312, gtest_ar.failure_message()) = ::testing::Message(); |
| 313 | EXPECT_EQ(mond->getQueryType(), DHCPDISCOVER)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("mond->getQueryType()" , "DHCPDISCOVER", mond->getQueryType(), DHCPDISCOVER))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 313, gtest_ar.failure_message()) = ::testing::Message(); |
| 314 | EXPECT_EQ(mond->getResponseType(), DHCPOFFER)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("mond->getResponseType()" , "DHCPOFFER", mond->getResponseType(), DHCPOFFER))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 314, gtest_ar.failure_message()) = ::testing::Message(); |
| 315 | EXPECT_EQ(mond->getStartEventLabel(), "process_started")switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("mond->getStartEventLabel()" , "\"process_started\"", mond->getStartEventLabel(), "process_started" ))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 315, gtest_ar.failure_message()) = ::testing::Message(); |
| 316 | EXPECT_EQ(mond->getStopEventLabel(), "process_completed")switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("mond->getStopEventLabel()" , "\"process_completed\"", mond->getStopEventLabel(), "process_completed" ))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 316, gtest_ar.failure_message()) = ::testing::Message(); |
| 317 | EXPECT_EQ(mond->getSubnetId(), SUBNET_ID_GLOBAL)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("mond->getSubnetId()" , "SUBNET_ID_GLOBAL", mond->getSubnetId(), SUBNET_ID_GLOBAL ))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 317, gtest_ar.failure_message()) = ::testing::Message(); |
| 318 | EXPECT_EQ("DHCPDISCOVER-DHCPOFFER.process_started-process_completed.0", mond->getLabel())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"DHCPDISCOVER-DHCPOFFER.process_started-process_completed.0\"" , "mond->getLabel()", "DHCPDISCOVER-DHCPOFFER.process_started-process_completed.0" , mond->getLabel()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 318, gtest_ar.failure_message()) = ::testing::Message(); |
| 319 | EXPECT_EQ(mond->getIntervalDuration(), interval_duration)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("mond->getIntervalDuration()" , "interval_duration", mond->getIntervalDuration(), interval_duration ))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 319, gtest_ar.failure_message()) = ::testing::Message(); |
| 320 | EXPECT_FALSE(mond->getCurrentInterval())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(mond->getCurrentInterval ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 320, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "mond->getCurrentInterval()", "true", "false") .c_str()) = ::testing::Message(); |
| 321 | EXPECT_FALSE(mond->getPreviousInterval())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(mond->getPreviousInterval ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 321, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "mond->getPreviousInterval()", "true", "false") .c_str() ) = ::testing::Message(); |
| 322 | |
| 323 | // Create valid v6 key and use that to create an alarm. Verify contents and label. |
| 324 | DurationKeyPtr key; |
| 325 | ASSERT_NO_THROW_LOG(key.reset(new DurationKey(AF_INET6, DHCPV6_SOLICIT, DHCPV6_ADVERTISE,{ try { key.reset(new DurationKey(10, DHCPV6_SOLICIT, DHCPV6_ADVERTISE , "mt_queued", "process_started", 77)); } catch (const std::exception & ex) { return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 326, "Failed") = ::testing::Message() << "key.reset(new DurationKey(AF_INET6, DHCPV6_SOLICIT, DHCPV6_ADVERTISE, \"mt_queued\", \"process_started\", 77))" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 326, "Failed") = ::testing::Message() << "key.reset(new DurationKey(AF_INET6, DHCPV6_SOLICIT, DHCPV6_ADVERTISE, \"mt_queued\", \"process_started\", 77))" << " threw non-std::exception"; } } |
| 326 | "mt_queued", "process_started", 77))){ try { key.reset(new DurationKey(10, DHCPV6_SOLICIT, DHCPV6_ADVERTISE , "mt_queued", "process_started", 77)); } catch (const std::exception & ex) { return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 326, "Failed") = ::testing::Message() << "key.reset(new DurationKey(AF_INET6, DHCPV6_SOLICIT, DHCPV6_ADVERTISE, \"mt_queued\", \"process_started\", 77))" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 326, "Failed") = ::testing::Message() << "key.reset(new DurationKey(AF_INET6, DHCPV6_SOLICIT, DHCPV6_ADVERTISE, \"mt_queued\", \"process_started\", 77))" << " threw non-std::exception"; } }; |
| 327 | |
| 328 | ASSERT_NO_THROW_LOG(mond.reset(new MonitoredDuration(*key, interval_duration))){ try { mond.reset(new MonitoredDuration(*key, interval_duration )); } catch (const std::exception& ex) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 328, "Failed") = ::testing::Message() << "mond.reset(new MonitoredDuration(*key, interval_duration))" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 328, "Failed") = ::testing::Message() << "mond.reset(new MonitoredDuration(*key, interval_duration))" << " threw non-std::exception"; } }; |
| 329 | ASSERT_TRUE(mond)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(mond)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 329, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "mond", "false", "true") .c_str()) = ::testing::Message(); |
| 330 | EXPECT_EQ(mond->getFamily(), AF_INET6)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("mond->getFamily()" , "10", mond->getFamily(), 10))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 330, gtest_ar.failure_message()) = ::testing::Message(); |
| 331 | EXPECT_EQ(mond->getQueryType(), DHCPV6_SOLICIT)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("mond->getQueryType()" , "DHCPV6_SOLICIT", mond->getQueryType(), DHCPV6_SOLICIT)) ) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 331, gtest_ar.failure_message()) = ::testing::Message(); |
| 332 | EXPECT_EQ(mond->getResponseType(), DHCPV6_ADVERTISE)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("mond->getResponseType()" , "DHCPV6_ADVERTISE", mond->getResponseType(), DHCPV6_ADVERTISE ))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 332, gtest_ar.failure_message()) = ::testing::Message(); |
| 333 | EXPECT_EQ(mond->getStartEventLabel(), "mt_queued")switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("mond->getStartEventLabel()" , "\"mt_queued\"", mond->getStartEventLabel(), "mt_queued" ))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 333, gtest_ar.failure_message()) = ::testing::Message(); |
| 334 | EXPECT_EQ(mond->getStopEventLabel(), "process_started")switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("mond->getStopEventLabel()" , "\"process_started\"", mond->getStopEventLabel(), "process_started" ))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 334, gtest_ar.failure_message()) = ::testing::Message(); |
| 335 | EXPECT_EQ(mond->getSubnetId(), 77)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("mond->getSubnetId()" , "77", mond->getSubnetId(), 77))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 335, gtest_ar.failure_message()) = ::testing::Message(); |
| 336 | EXPECT_EQ("SOLICIT-ADVERTISE.mt_queued-process_started.77", mond->getLabel())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("\"SOLICIT-ADVERTISE.mt_queued-process_started.77\"" , "mond->getLabel()", "SOLICIT-ADVERTISE.mt_queued-process_started.77" , mond->getLabel()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 336, gtest_ar.failure_message()) = ::testing::Message(); |
| 337 | EXPECT_EQ(mond->getIntervalDuration(), interval_duration)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("mond->getIntervalDuration()" , "interval_duration", mond->getIntervalDuration(), interval_duration ))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 337, gtest_ar.failure_message()) = ::testing::Message(); |
| 338 | EXPECT_FALSE(mond->getCurrentInterval())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(mond->getCurrentInterval ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 338, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "mond->getCurrentInterval()", "true", "false") .c_str()) = ::testing::Message(); |
| 339 | EXPECT_FALSE(mond->getPreviousInterval())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(mond->getPreviousInterval ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 339, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "mond->getPreviousInterval()", "true", "false") .c_str() ) = ::testing::Message(); |
| 340 | } |
| 341 | |
| 342 | // Verifies Copy construction. Since current and previous intervals are not |
| 343 | // exposed, this test relies on addSample() to alter them. |
| 344 | TEST(MonitoredDuration, copyConstructors)static_assert(sizeof("MonitoredDuration") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("copyConstructors") > 1, "test_name must not be empty" ); class MonitoredDuration_copyConstructors_Test : public ::testing ::Test { public: MonitoredDuration_copyConstructors_Test() = default ; ~MonitoredDuration_copyConstructors_Test() override = default ; MonitoredDuration_copyConstructors_Test (const MonitoredDuration_copyConstructors_Test &) = delete; MonitoredDuration_copyConstructors_Test & operator=( const MonitoredDuration_copyConstructors_Test & ) = delete; MonitoredDuration_copyConstructors_Test (MonitoredDuration_copyConstructors_Test &&) noexcept = delete; MonitoredDuration_copyConstructors_Test & operator=( MonitoredDuration_copyConstructors_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const MonitoredDuration_copyConstructors_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "MonitoredDuration" , "copyConstructors", nullptr, nullptr, ::testing::internal:: CodeLocation("../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 344), (::testing::internal::GetTestTypeId()), ::testing::internal ::SuiteApiResolver< ::testing::Test>::GetSetUpCaseOrSuite ("../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 344), ::testing::internal::SuiteApiResolver< ::testing:: Test>::GetTearDownCaseOrSuite("../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 344), new ::testing::internal::TestFactoryImpl<MonitoredDuration_copyConstructors_Test >); void MonitoredDuration_copyConstructors_Test::TestBody () { |
| 345 | MonitoredDurationPtr mond; |
| 346 | Duration interval_duration(microseconds(10)); |
| 347 | |
| 348 | // Create valid v4 duration, verify contents and label. |
| 349 | ASSERT_NO_THROW_LOG(mond.reset(new MonitoredDuration(AF_INET, DHCPDISCOVER, DHCPOFFER,{ try { mond.reset(new MonitoredDuration(2, DHCPDISCOVER, DHCPOFFER , "process_started", "process_completed", SUBNET_ID_GLOBAL, interval_duration )); } catch (const std::exception& ex) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 351, "Failed") = ::testing::Message() << "mond.reset(new MonitoredDuration(AF_INET, DHCPDISCOVER, DHCPOFFER, \"process_started\", \"process_completed\", SUBNET_ID_GLOBAL, interval_duration))" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 351, "Failed") = ::testing::Message() << "mond.reset(new MonitoredDuration(AF_INET, DHCPDISCOVER, DHCPOFFER, \"process_started\", \"process_completed\", SUBNET_ID_GLOBAL, interval_duration))" << " threw non-std::exception"; } } |
| 350 | "process_started", "process_completed",{ try { mond.reset(new MonitoredDuration(2, DHCPDISCOVER, DHCPOFFER , "process_started", "process_completed", SUBNET_ID_GLOBAL, interval_duration )); } catch (const std::exception& ex) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 351, "Failed") = ::testing::Message() << "mond.reset(new MonitoredDuration(AF_INET, DHCPDISCOVER, DHCPOFFER, \"process_started\", \"process_completed\", SUBNET_ID_GLOBAL, interval_duration))" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 351, "Failed") = ::testing::Message() << "mond.reset(new MonitoredDuration(AF_INET, DHCPDISCOVER, DHCPOFFER, \"process_started\", \"process_completed\", SUBNET_ID_GLOBAL, interval_duration))" << " threw non-std::exception"; } } |
| 351 | SUBNET_ID_GLOBAL, interval_duration))){ try { mond.reset(new MonitoredDuration(2, DHCPDISCOVER, DHCPOFFER , "process_started", "process_completed", SUBNET_ID_GLOBAL, interval_duration )); } catch (const std::exception& ex) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 351, "Failed") = ::testing::Message() << "mond.reset(new MonitoredDuration(AF_INET, DHCPDISCOVER, DHCPOFFER, \"process_started\", \"process_completed\", SUBNET_ID_GLOBAL, interval_duration))" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 351, "Failed") = ::testing::Message() << "mond.reset(new MonitoredDuration(AF_INET, DHCPDISCOVER, DHCPOFFER, \"process_started\", \"process_completed\", SUBNET_ID_GLOBAL, interval_duration))" << " threw non-std::exception"; } }; |
| 352 | |
| 353 | // Make a copy. |
| 354 | MonitoredDurationPtr duplicate; |
| 355 | duplicate.reset(new MonitoredDuration(*mond)); |
| 356 | |
| 357 | // Should have different pointers. |
| 358 | EXPECT_NE(duplicate, mond)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperNE("duplicate", "mond" , duplicate, mond))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 358, gtest_ar.failure_message()) = ::testing::Message(); |
| 359 | |
| 360 | // Key values should be equal (DurationKey::operator==). |
| 361 | EXPECT_EQ(*duplicate, *mond)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("*duplicate" , "*mond", *duplicate, *mond))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 361, gtest_ar.failure_message()) = ::testing::Message(); |
| 362 | |
| 363 | // Check non-key members. |
| 364 | EXPECT_EQ(duplicate->getIntervalDuration(), mond->getIntervalDuration())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("duplicate->getIntervalDuration()" , "mond->getIntervalDuration()", duplicate->getIntervalDuration (), mond->getIntervalDuration()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 364, gtest_ar.failure_message()) = ::testing::Message(); |
| 365 | EXPECT_FALSE(duplicate->getCurrentInterval())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(duplicate->getCurrentInterval ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 365, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "duplicate->getCurrentInterval()", "true", "false") .c_str ()) = ::testing::Message(); |
| 366 | EXPECT_FALSE(duplicate->getPreviousInterval())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(duplicate->getPreviousInterval ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 366, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "duplicate->getPreviousInterval()", "true", "false") .c_str ()) = ::testing::Message(); |
| 367 | |
| 368 | // Add a sample to the original. |
| 369 | EXPECT_FALSE(mond->addSample(microseconds(2)))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(mond->addSample( microseconds(2))))) ; else ::testing::internal::AssertHelper( ::testing::TestPartResult::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 369, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "mond->addSample(microseconds(2))", "true", "false") .c_str ()) = ::testing::Message(); |
| 370 | |
| 371 | // Make a new copy. |
| 372 | duplicate.reset(new MonitoredDuration(*mond)); |
| 373 | |
| 374 | // Current intervals should exist. |
| 375 | ASSERT_TRUE(mond->getCurrentInterval())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(mond->getCurrentInterval ())) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 375, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "mond->getCurrentInterval()", "false", "true") .c_str()) = ::testing::Message(); |
| 376 | ASSERT_TRUE(duplicate->getCurrentInterval())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(duplicate->getCurrentInterval ())) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 376, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "duplicate->getCurrentInterval()", "false", "true") .c_str ()) = ::testing::Message(); |
| 377 | // They should not be the same object but the content should be equal. |
| 378 | EXPECT_NE(duplicate->getCurrentInterval(), mond->getCurrentInterval())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperNE("duplicate->getCurrentInterval()" , "mond->getCurrentInterval()", duplicate->getCurrentInterval (), mond->getCurrentInterval()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 378, gtest_ar.failure_message()) = ::testing::Message(); |
| 379 | EXPECT_EQ(*duplicate->getCurrentInterval(), *mond->getCurrentInterval())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("*duplicate->getCurrentInterval()" , "*mond->getCurrentInterval()", *duplicate->getCurrentInterval (), *mond->getCurrentInterval()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 379, gtest_ar.failure_message()) = ::testing::Message(); |
| 380 | // Previous interval should not exist. |
| 381 | ASSERT_FALSE(mond->getPreviousInterval())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(mond->getPreviousInterval ()))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 381, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "mond->getPreviousInterval()", "true", "false") .c_str() ) = ::testing::Message(); |
| 382 | ASSERT_FALSE(duplicate->getPreviousInterval())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(duplicate->getPreviousInterval ()))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 382, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "duplicate->getPreviousInterval()", "true", "false") .c_str ()) = ::testing::Message(); |
| 383 | |
| 384 | // Sleep past interval duration. |
| 385 | usleep(20); |
| 386 | |
| 387 | // Add another sample to the original. |
| 388 | EXPECT_TRUE(mond->addSample(microseconds(2)))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(mond->addSample(microseconds (2)))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 388, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "mond->addSample(microseconds(2))", "false", "true") .c_str ()) = ::testing::Message(); |
| 389 | |
| 390 | // Make a new copy. |
| 391 | duplicate.reset(new MonitoredDuration(*mond)); |
| 392 | |
| 393 | // Current intervals should exist. |
| 394 | ASSERT_TRUE(mond->getCurrentInterval())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(mond->getCurrentInterval ())) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 394, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "mond->getCurrentInterval()", "false", "true") .c_str()) = ::testing::Message(); |
| 395 | ASSERT_TRUE(duplicate->getCurrentInterval())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(duplicate->getCurrentInterval ())) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 395, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "duplicate->getCurrentInterval()", "false", "true") .c_str ()) = ::testing::Message(); |
| 396 | // They should not be the same object but the content should be equal. |
| 397 | EXPECT_NE(duplicate->getCurrentInterval(), mond->getCurrentInterval())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperNE("duplicate->getCurrentInterval()" , "mond->getCurrentInterval()", duplicate->getCurrentInterval (), mond->getCurrentInterval()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 397, gtest_ar.failure_message()) = ::testing::Message(); |
| 398 | EXPECT_EQ(*duplicate->getCurrentInterval(), *mond->getCurrentInterval())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("*duplicate->getCurrentInterval()" , "*mond->getCurrentInterval()", *duplicate->getCurrentInterval (), *mond->getCurrentInterval()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 398, gtest_ar.failure_message()) = ::testing::Message(); |
| 399 | |
| 400 | // Current previous should exist. |
| 401 | ASSERT_TRUE(mond->getPreviousInterval())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(mond->getPreviousInterval ())) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 401, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "mond->getPreviousInterval()", "false", "true") .c_str() ) = ::testing::Message(); |
| 402 | ASSERT_TRUE(duplicate->getPreviousInterval())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(duplicate->getPreviousInterval ())) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 402, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "duplicate->getPreviousInterval()", "false", "true") .c_str ()) = ::testing::Message(); |
| 403 | // They should not be the same object but the content should be equal. |
| 404 | EXPECT_NE(duplicate->getPreviousInterval(), mond->getPreviousInterval())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperNE("duplicate->getPreviousInterval()" , "mond->getPreviousInterval()", duplicate->getPreviousInterval (), mond->getPreviousInterval()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 404, gtest_ar.failure_message()) = ::testing::Message(); |
| 405 | EXPECT_EQ(*duplicate->getPreviousInterval(), *mond->getPreviousInterval())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("*duplicate->getPreviousInterval()" , "*mond->getPreviousInterval()", *duplicate->getPreviousInterval (), *mond->getPreviousInterval()))) ; else ::testing::internal ::AssertHelper(::testing::TestPartResult::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 405, gtest_ar.failure_message()) = ::testing::Message(); |
| 406 | } |
| 407 | |
| 408 | // Verifies MonitoredDuration invalid construction. |
| 409 | TEST(MonitoredDuration, invalidConstructors)static_assert(sizeof("MonitoredDuration") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("invalidConstructors") > 1, "test_name must not be empty" ); class MonitoredDuration_invalidConstructors_Test : public :: testing::Test { public: MonitoredDuration_invalidConstructors_Test () = default; ~MonitoredDuration_invalidConstructors_Test() override = default; MonitoredDuration_invalidConstructors_Test (const MonitoredDuration_invalidConstructors_Test &) = delete; MonitoredDuration_invalidConstructors_Test & operator=( const MonitoredDuration_invalidConstructors_Test &) = delete; MonitoredDuration_invalidConstructors_Test ( MonitoredDuration_invalidConstructors_Test &&) noexcept = delete; MonitoredDuration_invalidConstructors_Test & operator =( MonitoredDuration_invalidConstructors_Test &&) noexcept = delete; private: void TestBody() override; [[maybe_unused] ] static ::testing::TestInfo* const test_info_; }; ::testing:: TestInfo* const MonitoredDuration_invalidConstructors_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "MonitoredDuration" , "invalidConstructors", nullptr, nullptr, ::testing::internal ::CodeLocation("../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 409), (::testing::internal::GetTestTypeId()), ::testing::internal ::SuiteApiResolver< ::testing::Test>::GetSetUpCaseOrSuite ("../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 409), ::testing::internal::SuiteApiResolver< ::testing:: Test>::GetTearDownCaseOrSuite("../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 409), new ::testing::internal::TestFactoryImpl<MonitoredDuration_invalidConstructors_Test >); void MonitoredDuration_invalidConstructors_Test::TestBody () { |
| 410 | MonitoredDurationPtr mond; |
| 411 | |
| 412 | // Make sure we catch an invalid message pairing. |
| 413 | Duration interval_duration = seconds(60); |
| 414 | ASSERT_THROW_MSG(mond.reset(new MonitoredDuration(AF_INET, DHCPDISCOVER, DHCPDISCOVER,{ try { mond.reset(new MonitoredDuration(2, DHCPDISCOVER, DHCPDISCOVER , "process_started", "process_completed", SUBNET_ID_GLOBAL, interval_duration )); return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 418, "Failed") = ::testing::Message() << "no exception, expected: " << "BadValue"; } catch (const BadValue& ex) { switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("std::string(ex.what())" , "\"Response type: DHCPDISCOVER not valid for query type: DHCPDISCOVER\"" , std::string(ex.what()), "Response type: DHCPDISCOVER not valid for query type: DHCPDISCOVER" ))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 418, gtest_ar.failure_message()) = ::testing::Message(); } catch (...) { return ::testing::internal::AssertHelper(::testing:: TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 418, "Failed") = ::testing::Message() << "wrong exception type thrown, expected: " << "BadValue"; } } |
| 415 | "process_started", "process_completed",{ try { mond.reset(new MonitoredDuration(2, DHCPDISCOVER, DHCPDISCOVER , "process_started", "process_completed", SUBNET_ID_GLOBAL, interval_duration )); return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 418, "Failed") = ::testing::Message() << "no exception, expected: " << "BadValue"; } catch (const BadValue& ex) { switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("std::string(ex.what())" , "\"Response type: DHCPDISCOVER not valid for query type: DHCPDISCOVER\"" , std::string(ex.what()), "Response type: DHCPDISCOVER not valid for query type: DHCPDISCOVER" ))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 418, gtest_ar.failure_message()) = ::testing::Message(); } catch (...) { return ::testing::internal::AssertHelper(::testing:: TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 418, "Failed") = ::testing::Message() << "wrong exception type thrown, expected: " << "BadValue"; } } |
| 416 | SUBNET_ID_GLOBAL, interval_duration)),{ try { mond.reset(new MonitoredDuration(2, DHCPDISCOVER, DHCPDISCOVER , "process_started", "process_completed", SUBNET_ID_GLOBAL, interval_duration )); return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 418, "Failed") = ::testing::Message() << "no exception, expected: " << "BadValue"; } catch (const BadValue& ex) { switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("std::string(ex.what())" , "\"Response type: DHCPDISCOVER not valid for query type: DHCPDISCOVER\"" , std::string(ex.what()), "Response type: DHCPDISCOVER not valid for query type: DHCPDISCOVER" ))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 418, gtest_ar.failure_message()) = ::testing::Message(); } catch (...) { return ::testing::internal::AssertHelper(::testing:: TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 418, "Failed") = ::testing::Message() << "wrong exception type thrown, expected: " << "BadValue"; } } |
| 417 | BadValue,{ try { mond.reset(new MonitoredDuration(2, DHCPDISCOVER, DHCPDISCOVER , "process_started", "process_completed", SUBNET_ID_GLOBAL, interval_duration )); return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 418, "Failed") = ::testing::Message() << "no exception, expected: " << "BadValue"; } catch (const BadValue& ex) { switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("std::string(ex.what())" , "\"Response type: DHCPDISCOVER not valid for query type: DHCPDISCOVER\"" , std::string(ex.what()), "Response type: DHCPDISCOVER not valid for query type: DHCPDISCOVER" ))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 418, gtest_ar.failure_message()) = ::testing::Message(); } catch (...) { return ::testing::internal::AssertHelper(::testing:: TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 418, "Failed") = ::testing::Message() << "wrong exception type thrown, expected: " << "BadValue"; } } |
| 418 | "Response type: DHCPDISCOVER not valid for query type: DHCPDISCOVER"){ try { mond.reset(new MonitoredDuration(2, DHCPDISCOVER, DHCPDISCOVER , "process_started", "process_completed", SUBNET_ID_GLOBAL, interval_duration )); return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 418, "Failed") = ::testing::Message() << "no exception, expected: " << "BadValue"; } catch (const BadValue& ex) { switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("std::string(ex.what())" , "\"Response type: DHCPDISCOVER not valid for query type: DHCPDISCOVER\"" , std::string(ex.what()), "Response type: DHCPDISCOVER not valid for query type: DHCPDISCOVER" ))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 418, gtest_ar.failure_message()) = ::testing::Message(); } catch (...) { return ::testing::internal::AssertHelper(::testing:: TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 418, "Failed") = ::testing::Message() << "wrong exception type thrown, expected: " << "BadValue"; } }; |
| 419 | |
| 420 | // Interval duration cannot be zero. |
| 421 | interval_duration = DurationDataInterval::ZERO_DURATION(); |
| 422 | ASSERT_THROW_MSG(mond.reset(new MonitoredDuration(AF_INET, DHCPDISCOVER, DHCPOFFER,{ try { mond.reset(new MonitoredDuration(2, DHCPDISCOVER, DHCPOFFER , "process_started", "process_completed", SUBNET_ID_GLOBAL, interval_duration )); return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 427, "Failed") = ::testing::Message() << "no exception, expected: " << "BadValue"; } catch (const BadValue& ex) { switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("std::string(ex.what())" , "\"MonitoredDuration - interval_duration 00:00:00,\" \" is invalid, it must be greater than 0\"" , std::string(ex.what()), "MonitoredDuration - interval_duration 00:00:00," " is invalid, it must be greater than 0"))) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 427, gtest_ar.failure_message()) = ::testing::Message(); } catch (...) { return ::testing::internal::AssertHelper(::testing:: TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 427, "Failed") = ::testing::Message() << "wrong exception type thrown, expected: " << "BadValue"; } } |
| 423 | "process_started", "process_completed",{ try { mond.reset(new MonitoredDuration(2, DHCPDISCOVER, DHCPOFFER , "process_started", "process_completed", SUBNET_ID_GLOBAL, interval_duration )); return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 427, "Failed") = ::testing::Message() << "no exception, expected: " << "BadValue"; } catch (const BadValue& ex) { switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("std::string(ex.what())" , "\"MonitoredDuration - interval_duration 00:00:00,\" \" is invalid, it must be greater than 0\"" , std::string(ex.what()), "MonitoredDuration - interval_duration 00:00:00," " is invalid, it must be greater than 0"))) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 427, gtest_ar.failure_message()) = ::testing::Message(); } catch (...) { return ::testing::internal::AssertHelper(::testing:: TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 427, "Failed") = ::testing::Message() << "wrong exception type thrown, expected: " << "BadValue"; } } |
| 424 | SUBNET_ID_GLOBAL, interval_duration)),{ try { mond.reset(new MonitoredDuration(2, DHCPDISCOVER, DHCPOFFER , "process_started", "process_completed", SUBNET_ID_GLOBAL, interval_duration )); return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 427, "Failed") = ::testing::Message() << "no exception, expected: " << "BadValue"; } catch (const BadValue& ex) { switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("std::string(ex.what())" , "\"MonitoredDuration - interval_duration 00:00:00,\" \" is invalid, it must be greater than 0\"" , std::string(ex.what()), "MonitoredDuration - interval_duration 00:00:00," " is invalid, it must be greater than 0"))) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 427, gtest_ar.failure_message()) = ::testing::Message(); } catch (...) { return ::testing::internal::AssertHelper(::testing:: TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 427, "Failed") = ::testing::Message() << "wrong exception type thrown, expected: " << "BadValue"; } } |
| 425 | BadValue,{ try { mond.reset(new MonitoredDuration(2, DHCPDISCOVER, DHCPOFFER , "process_started", "process_completed", SUBNET_ID_GLOBAL, interval_duration )); return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 427, "Failed") = ::testing::Message() << "no exception, expected: " << "BadValue"; } catch (const BadValue& ex) { switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("std::string(ex.what())" , "\"MonitoredDuration - interval_duration 00:00:00,\" \" is invalid, it must be greater than 0\"" , std::string(ex.what()), "MonitoredDuration - interval_duration 00:00:00," " is invalid, it must be greater than 0"))) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 427, gtest_ar.failure_message()) = ::testing::Message(); } catch (...) { return ::testing::internal::AssertHelper(::testing:: TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 427, "Failed") = ::testing::Message() << "wrong exception type thrown, expected: " << "BadValue"; } } |
| 426 | "MonitoredDuration - interval_duration 00:00:00,"{ try { mond.reset(new MonitoredDuration(2, DHCPDISCOVER, DHCPOFFER , "process_started", "process_completed", SUBNET_ID_GLOBAL, interval_duration )); return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 427, "Failed") = ::testing::Message() << "no exception, expected: " << "BadValue"; } catch (const BadValue& ex) { switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("std::string(ex.what())" , "\"MonitoredDuration - interval_duration 00:00:00,\" \" is invalid, it must be greater than 0\"" , std::string(ex.what()), "MonitoredDuration - interval_duration 00:00:00," " is invalid, it must be greater than 0"))) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 427, gtest_ar.failure_message()) = ::testing::Message(); } catch (...) { return ::testing::internal::AssertHelper(::testing:: TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 427, "Failed") = ::testing::Message() << "wrong exception type thrown, expected: " << "BadValue"; } } |
| 427 | " is invalid, it must be greater than 0"){ try { mond.reset(new MonitoredDuration(2, DHCPDISCOVER, DHCPOFFER , "process_started", "process_completed", SUBNET_ID_GLOBAL, interval_duration )); return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 427, "Failed") = ::testing::Message() << "no exception, expected: " << "BadValue"; } catch (const BadValue& ex) { switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("std::string(ex.what())" , "\"MonitoredDuration - interval_duration 00:00:00,\" \" is invalid, it must be greater than 0\"" , std::string(ex.what()), "MonitoredDuration - interval_duration 00:00:00," " is invalid, it must be greater than 0"))) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 427, gtest_ar.failure_message()) = ::testing::Message(); } catch (...) { return ::testing::internal::AssertHelper(::testing:: TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 427, "Failed") = ::testing::Message() << "wrong exception type thrown, expected: " << "BadValue"; } }; |
| 428 | |
| 429 | // Interval duration cannot be negative. |
| 430 | ASSERT_THROW_MSG(mond.reset(new MonitoredDuration(AF_INET, DHCPDISCOVER, DHCPOFFER,{ try { mond.reset(new MonitoredDuration(2, DHCPDISCOVER, DHCPOFFER , "process_started", "process_completed", SUBNET_ID_GLOBAL, seconds (-5))); return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 435, "Failed") = ::testing::Message() << "no exception, expected: " << "BadValue"; } catch (const BadValue& ex) { switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("std::string(ex.what())" , "\"MonitoredDuration - interval_duration -00:00:05,\" \" is invalid, it must be greater than 0\"" , std::string(ex.what()), "MonitoredDuration - interval_duration -00:00:05," " is invalid, it must be greater than 0"))) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 435, gtest_ar.failure_message()) = ::testing::Message(); } catch (...) { return ::testing::internal::AssertHelper(::testing:: TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 435, "Failed") = ::testing::Message() << "wrong exception type thrown, expected: " << "BadValue"; } } |
| 431 | "process_started", "process_completed",{ try { mond.reset(new MonitoredDuration(2, DHCPDISCOVER, DHCPOFFER , "process_started", "process_completed", SUBNET_ID_GLOBAL, seconds (-5))); return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 435, "Failed") = ::testing::Message() << "no exception, expected: " << "BadValue"; } catch (const BadValue& ex) { switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("std::string(ex.what())" , "\"MonitoredDuration - interval_duration -00:00:05,\" \" is invalid, it must be greater than 0\"" , std::string(ex.what()), "MonitoredDuration - interval_duration -00:00:05," " is invalid, it must be greater than 0"))) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 435, gtest_ar.failure_message()) = ::testing::Message(); } catch (...) { return ::testing::internal::AssertHelper(::testing:: TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 435, "Failed") = ::testing::Message() << "wrong exception type thrown, expected: " << "BadValue"; } } |
| 432 | SUBNET_ID_GLOBAL, seconds(-5))),{ try { mond.reset(new MonitoredDuration(2, DHCPDISCOVER, DHCPOFFER , "process_started", "process_completed", SUBNET_ID_GLOBAL, seconds (-5))); return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 435, "Failed") = ::testing::Message() << "no exception, expected: " << "BadValue"; } catch (const BadValue& ex) { switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("std::string(ex.what())" , "\"MonitoredDuration - interval_duration -00:00:05,\" \" is invalid, it must be greater than 0\"" , std::string(ex.what()), "MonitoredDuration - interval_duration -00:00:05," " is invalid, it must be greater than 0"))) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 435, gtest_ar.failure_message()) = ::testing::Message(); } catch (...) { return ::testing::internal::AssertHelper(::testing:: TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 435, "Failed") = ::testing::Message() << "wrong exception type thrown, expected: " << "BadValue"; } } |
| 433 | BadValue,{ try { mond.reset(new MonitoredDuration(2, DHCPDISCOVER, DHCPOFFER , "process_started", "process_completed", SUBNET_ID_GLOBAL, seconds (-5))); return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 435, "Failed") = ::testing::Message() << "no exception, expected: " << "BadValue"; } catch (const BadValue& ex) { switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("std::string(ex.what())" , "\"MonitoredDuration - interval_duration -00:00:05,\" \" is invalid, it must be greater than 0\"" , std::string(ex.what()), "MonitoredDuration - interval_duration -00:00:05," " is invalid, it must be greater than 0"))) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 435, gtest_ar.failure_message()) = ::testing::Message(); } catch (...) { return ::testing::internal::AssertHelper(::testing:: TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 435, "Failed") = ::testing::Message() << "wrong exception type thrown, expected: " << "BadValue"; } } |
| 434 | "MonitoredDuration - interval_duration -00:00:05,"{ try { mond.reset(new MonitoredDuration(2, DHCPDISCOVER, DHCPOFFER , "process_started", "process_completed", SUBNET_ID_GLOBAL, seconds (-5))); return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 435, "Failed") = ::testing::Message() << "no exception, expected: " << "BadValue"; } catch (const BadValue& ex) { switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("std::string(ex.what())" , "\"MonitoredDuration - interval_duration -00:00:05,\" \" is invalid, it must be greater than 0\"" , std::string(ex.what()), "MonitoredDuration - interval_duration -00:00:05," " is invalid, it must be greater than 0"))) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 435, gtest_ar.failure_message()) = ::testing::Message(); } catch (...) { return ::testing::internal::AssertHelper(::testing:: TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 435, "Failed") = ::testing::Message() << "wrong exception type thrown, expected: " << "BadValue"; } } |
| 435 | " is invalid, it must be greater than 0"){ try { mond.reset(new MonitoredDuration(2, DHCPDISCOVER, DHCPOFFER , "process_started", "process_completed", SUBNET_ID_GLOBAL, seconds (-5))); return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 435, "Failed") = ::testing::Message() << "no exception, expected: " << "BadValue"; } catch (const BadValue& ex) { switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("std::string(ex.what())" , "\"MonitoredDuration - interval_duration -00:00:05,\" \" is invalid, it must be greater than 0\"" , std::string(ex.what()), "MonitoredDuration - interval_duration -00:00:05," " is invalid, it must be greater than 0"))) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 435, gtest_ar.failure_message()) = ::testing::Message(); } catch (...) { return ::testing::internal::AssertHelper(::testing:: TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 435, "Failed") = ::testing::Message() << "wrong exception type thrown, expected: " << "BadValue"; } }; |
| 436 | |
| 437 | // Create valid v6 key. |
| 438 | DurationKeyPtr key; |
| 439 | ASSERT_NO_THROW_LOG(key.reset(new DurationKey(AF_INET6, DHCPV6_SOLICIT, DHCPV6_ADVERTISE,{ try { key.reset(new DurationKey(10, DHCPV6_SOLICIT, DHCPV6_ADVERTISE , "mt_queued", "process_started", 77)); } catch (const std::exception & ex) { return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 440, "Failed") = ::testing::Message() << "key.reset(new DurationKey(AF_INET6, DHCPV6_SOLICIT, DHCPV6_ADVERTISE, \"mt_queued\", \"process_started\", 77))" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 440, "Failed") = ::testing::Message() << "key.reset(new DurationKey(AF_INET6, DHCPV6_SOLICIT, DHCPV6_ADVERTISE, \"mt_queued\", \"process_started\", 77))" << " threw non-std::exception"; } } |
| 440 | "mt_queued", "process_started", 77))){ try { key.reset(new DurationKey(10, DHCPV6_SOLICIT, DHCPV6_ADVERTISE , "mt_queued", "process_started", 77)); } catch (const std::exception & ex) { return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 440, "Failed") = ::testing::Message() << "key.reset(new DurationKey(AF_INET6, DHCPV6_SOLICIT, DHCPV6_ADVERTISE, \"mt_queued\", \"process_started\", 77))" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 440, "Failed") = ::testing::Message() << "key.reset(new DurationKey(AF_INET6, DHCPV6_SOLICIT, DHCPV6_ADVERTISE, \"mt_queued\", \"process_started\", 77))" << " threw non-std::exception"; } }; |
| 441 | |
| 442 | // Interval duration cannot be zero. |
| 443 | ASSERT_THROW_MSG(mond.reset(new MonitoredDuration(*key, interval_duration)),{ try { mond.reset(new MonitoredDuration(*key, interval_duration )); return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 446, "Failed") = ::testing::Message() << "no exception, expected: " << "BadValue"; } catch (const BadValue& ex) { switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("std::string(ex.what())" , "\"MonitoredDuration - interval_duration 00:00:00,\" \" is invalid, it must be greater than 0\"" , std::string(ex.what()), "MonitoredDuration - interval_duration 00:00:00," " is invalid, it must be greater than 0"))) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 446, gtest_ar.failure_message()) = ::testing::Message(); } catch (...) { return ::testing::internal::AssertHelper(::testing:: TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 446, "Failed") = ::testing::Message() << "wrong exception type thrown, expected: " << "BadValue"; } } |
| 444 | BadValue,{ try { mond.reset(new MonitoredDuration(*key, interval_duration )); return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 446, "Failed") = ::testing::Message() << "no exception, expected: " << "BadValue"; } catch (const BadValue& ex) { switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("std::string(ex.what())" , "\"MonitoredDuration - interval_duration 00:00:00,\" \" is invalid, it must be greater than 0\"" , std::string(ex.what()), "MonitoredDuration - interval_duration 00:00:00," " is invalid, it must be greater than 0"))) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 446, gtest_ar.failure_message()) = ::testing::Message(); } catch (...) { return ::testing::internal::AssertHelper(::testing:: TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 446, "Failed") = ::testing::Message() << "wrong exception type thrown, expected: " << "BadValue"; } } |
| 445 | "MonitoredDuration - interval_duration 00:00:00,"{ try { mond.reset(new MonitoredDuration(*key, interval_duration )); return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 446, "Failed") = ::testing::Message() << "no exception, expected: " << "BadValue"; } catch (const BadValue& ex) { switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("std::string(ex.what())" , "\"MonitoredDuration - interval_duration 00:00:00,\" \" is invalid, it must be greater than 0\"" , std::string(ex.what()), "MonitoredDuration - interval_duration 00:00:00," " is invalid, it must be greater than 0"))) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 446, gtest_ar.failure_message()) = ::testing::Message(); } catch (...) { return ::testing::internal::AssertHelper(::testing:: TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 446, "Failed") = ::testing::Message() << "wrong exception type thrown, expected: " << "BadValue"; } } |
| 446 | " is invalid, it must be greater than 0"){ try { mond.reset(new MonitoredDuration(*key, interval_duration )); return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 446, "Failed") = ::testing::Message() << "no exception, expected: " << "BadValue"; } catch (const BadValue& ex) { switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("std::string(ex.what())" , "\"MonitoredDuration - interval_duration 00:00:00,\" \" is invalid, it must be greater than 0\"" , std::string(ex.what()), "MonitoredDuration - interval_duration 00:00:00," " is invalid, it must be greater than 0"))) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 446, gtest_ar.failure_message()) = ::testing::Message(); } catch (...) { return ::testing::internal::AssertHelper(::testing:: TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 446, "Failed") = ::testing::Message() << "wrong exception type thrown, expected: " << "BadValue"; } }; |
| 447 | |
| 448 | // Interval duration cannot be negative. |
| 449 | ASSERT_THROW_MSG(mond.reset(new MonitoredDuration(*key, seconds(-5))),{ try { mond.reset(new MonitoredDuration(*key, seconds(-5))); return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 452, "Failed") = ::testing::Message() << "no exception, expected: " << "BadValue"; } catch (const BadValue& ex) { switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("std::string(ex.what())" , "\"MonitoredDuration - interval_duration -00:00:05,\" \" is invalid, it must be greater than 0\"" , std::string(ex.what()), "MonitoredDuration - interval_duration -00:00:05," " is invalid, it must be greater than 0"))) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 452, gtest_ar.failure_message()) = ::testing::Message(); } catch (...) { return ::testing::internal::AssertHelper(::testing:: TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 452, "Failed") = ::testing::Message() << "wrong exception type thrown, expected: " << "BadValue"; } } |
| 450 | BadValue,{ try { mond.reset(new MonitoredDuration(*key, seconds(-5))); return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 452, "Failed") = ::testing::Message() << "no exception, expected: " << "BadValue"; } catch (const BadValue& ex) { switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("std::string(ex.what())" , "\"MonitoredDuration - interval_duration -00:00:05,\" \" is invalid, it must be greater than 0\"" , std::string(ex.what()), "MonitoredDuration - interval_duration -00:00:05," " is invalid, it must be greater than 0"))) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 452, gtest_ar.failure_message()) = ::testing::Message(); } catch (...) { return ::testing::internal::AssertHelper(::testing:: TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 452, "Failed") = ::testing::Message() << "wrong exception type thrown, expected: " << "BadValue"; } } |
| 451 | "MonitoredDuration - interval_duration -00:00:05,"{ try { mond.reset(new MonitoredDuration(*key, seconds(-5))); return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 452, "Failed") = ::testing::Message() << "no exception, expected: " << "BadValue"; } catch (const BadValue& ex) { switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("std::string(ex.what())" , "\"MonitoredDuration - interval_duration -00:00:05,\" \" is invalid, it must be greater than 0\"" , std::string(ex.what()), "MonitoredDuration - interval_duration -00:00:05," " is invalid, it must be greater than 0"))) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 452, gtest_ar.failure_message()) = ::testing::Message(); } catch (...) { return ::testing::internal::AssertHelper(::testing:: TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 452, "Failed") = ::testing::Message() << "wrong exception type thrown, expected: " << "BadValue"; } } |
| 452 | " is invalid, it must be greater than 0"){ try { mond.reset(new MonitoredDuration(*key, seconds(-5))); return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 452, "Failed") = ::testing::Message() << "no exception, expected: " << "BadValue"; } catch (const BadValue& ex) { switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("std::string(ex.what())" , "\"MonitoredDuration - interval_duration -00:00:05,\" \" is invalid, it must be greater than 0\"" , std::string(ex.what()), "MonitoredDuration - interval_duration -00:00:05," " is invalid, it must be greater than 0"))) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 452, gtest_ar.failure_message()) = ::testing::Message(); } catch (...) { return ::testing::internal::AssertHelper(::testing:: TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 452, "Failed") = ::testing::Message() << "wrong exception type thrown, expected: " << "BadValue"; } }; |
| 453 | } |
| 454 | |
| 455 | // Exercises MonitoredDuration::addSample() and MonitoredDuration::clear(). |
| 456 | TEST(MonitoredDuration, addSampleAndClear)static_assert(sizeof("MonitoredDuration") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("addSampleAndClear") > 1, "test_name must not be empty" ); class MonitoredDuration_addSampleAndClear_Test : public :: testing::Test { public: MonitoredDuration_addSampleAndClear_Test () = default; ~MonitoredDuration_addSampleAndClear_Test() override = default; MonitoredDuration_addSampleAndClear_Test (const MonitoredDuration_addSampleAndClear_Test &) = delete; MonitoredDuration_addSampleAndClear_Test & operator=( const MonitoredDuration_addSampleAndClear_Test & ) = delete; MonitoredDuration_addSampleAndClear_Test (MonitoredDuration_addSampleAndClear_Test &&) noexcept = delete; MonitoredDuration_addSampleAndClear_Test & operator=( MonitoredDuration_addSampleAndClear_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const MonitoredDuration_addSampleAndClear_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "MonitoredDuration" , "addSampleAndClear", nullptr, nullptr, ::testing::internal:: CodeLocation("../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 456), (::testing::internal::GetTestTypeId()), ::testing::internal ::SuiteApiResolver< ::testing::Test>::GetSetUpCaseOrSuite ("../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 456), ::testing::internal::SuiteApiResolver< ::testing:: Test>::GetTearDownCaseOrSuite("../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 456), new ::testing::internal::TestFactoryImpl<MonitoredDuration_addSampleAndClear_Test >); void MonitoredDuration_addSampleAndClear_Test::TestBody () { |
| 457 | MonitoredDurationPtr mond; |
| 458 | Duration interval_duration(milliseconds(50)); |
| 459 | |
| 460 | // Create valid v4 duration with interval duration of 50ms. |
| 461 | ASSERT_NO_THROW_LOG(mond.reset(new MonitoredDuration(AF_INET, DHCPDISCOVER, DHCPOFFER,{ try { mond.reset(new MonitoredDuration(2, DHCPDISCOVER, DHCPOFFER , "process_started", "process_completed", SUBNET_ID_GLOBAL, interval_duration )); } catch (const std::exception& ex) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 463, "Failed") = ::testing::Message() << "mond.reset(new MonitoredDuration(AF_INET, DHCPDISCOVER, DHCPOFFER, \"process_started\", \"process_completed\", SUBNET_ID_GLOBAL, interval_duration))" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 463, "Failed") = ::testing::Message() << "mond.reset(new MonitoredDuration(AF_INET, DHCPDISCOVER, DHCPOFFER, \"process_started\", \"process_completed\", SUBNET_ID_GLOBAL, interval_duration))" << " threw non-std::exception"; } } |
| 462 | "process_started", "process_completed",{ try { mond.reset(new MonitoredDuration(2, DHCPDISCOVER, DHCPOFFER , "process_started", "process_completed", SUBNET_ID_GLOBAL, interval_duration )); } catch (const std::exception& ex) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 463, "Failed") = ::testing::Message() << "mond.reset(new MonitoredDuration(AF_INET, DHCPDISCOVER, DHCPOFFER, \"process_started\", \"process_completed\", SUBNET_ID_GLOBAL, interval_duration))" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 463, "Failed") = ::testing::Message() << "mond.reset(new MonitoredDuration(AF_INET, DHCPDISCOVER, DHCPOFFER, \"process_started\", \"process_completed\", SUBNET_ID_GLOBAL, interval_duration))" << " threw non-std::exception"; } } |
| 463 | SUBNET_ID_GLOBAL, interval_duration))){ try { mond.reset(new MonitoredDuration(2, DHCPDISCOVER, DHCPOFFER , "process_started", "process_completed", SUBNET_ID_GLOBAL, interval_duration )); } catch (const std::exception& ex) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 463, "Failed") = ::testing::Message() << "mond.reset(new MonitoredDuration(AF_INET, DHCPDISCOVER, DHCPOFFER, \"process_started\", \"process_completed\", SUBNET_ID_GLOBAL, interval_duration))" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 463, "Failed") = ::testing::Message() << "mond.reset(new MonitoredDuration(AF_INET, DHCPDISCOVER, DHCPOFFER, \"process_started\", \"process_completed\", SUBNET_ID_GLOBAL, interval_duration))" << " threw non-std::exception"; } }; |
| 464 | ASSERT_TRUE(mond)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(mond)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 464, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "mond", "false", "true") .c_str()) = ::testing::Message(); |
| 465 | |
| 466 | // Initially there are no intervals. |
| 467 | EXPECT_FALSE(mond->getCurrentInterval())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(mond->getCurrentInterval ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 467, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "mond->getCurrentInterval()", "true", "false") .c_str()) = ::testing::Message(); |
| 468 | EXPECT_FALSE(mond->getPreviousInterval())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(mond->getPreviousInterval ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 468, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "mond->getPreviousInterval()", "true", "false") .c_str() ) = ::testing::Message(); |
| 469 | |
| 470 | auto two_ms = milliseconds(2); |
| 471 | bool should_report = false; |
| 472 | |
| 473 | // Add a sample and verify nothing to report and that it creates a |
| 474 | // current interval. |
| 475 | ASSERT_NO_THROW(should_report = mond->addSample(two_ms))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { should_report = mond->addSample(two_ms); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_475; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_475; } } else gtest_label_testnothrow_475 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 475, ("Expected: " "should_report = mond->addSample(two_ms)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); |
| 476 | EXPECT_FALSE(should_report)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(should_report))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 476, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "should_report", "true", "false") .c_str()) = ::testing::Message (); |
| 477 | DurationDataIntervalPtr current_interval = mond->getCurrentInterval(); |
| 478 | ASSERT_TRUE(current_interval)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(current_interval)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 478, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "current_interval", "false", "true") .c_str()) = ::testing:: Message(); |
| 479 | |
| 480 | // First pass, we should only have a current interval, |
| 481 | // nothing to report, one occurrence and a total duration of 10ms. |
| 482 | EXPECT_FALSE(mond->getPreviousInterval())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(mond->getPreviousInterval ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 482, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "mond->getPreviousInterval()", "true", "false") .c_str() ) = ::testing::Message(); |
| 483 | EXPECT_FALSE(should_report)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(should_report))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 483, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "should_report", "true", "false") .c_str()) = ::testing::Message (); |
| 484 | EXPECT_EQ(current_interval->getOccurrences(), 1)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("current_interval->getOccurrences()" , "1", current_interval->getOccurrences(), 1))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 484, gtest_ar.failure_message()) = ::testing::Message(); |
| 485 | EXPECT_EQ(current_interval->getTotalDuration(), two_ms)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("current_interval->getTotalDuration()" , "two_ms", current_interval->getTotalDuration(), two_ms)) ) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 485, gtest_ar.failure_message()) = ::testing::Message(); |
| 486 | |
| 487 | // Save a copy of the current interval pointer. |
| 488 | DurationDataIntervalPtr original_interval = current_interval; |
| 489 | |
| 490 | // Add 4 two ms samples during the current interval. |
| 491 | DurationDataIntervalPtr previous_interval; |
| 492 | for (int i = 1; i < 5; ++i) { |
| 493 | // Add a two ms sample, it should return false as its not |
| 494 | // time to report. |
| 495 | ASSERT_NO_THROW(should_report = mond->addSample(two_ms))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { should_report = mond->addSample(two_ms); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_495; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_495; } } else gtest_label_testnothrow_495 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 495, ("Expected: " "should_report = mond->addSample(two_ms)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); |
| 496 | EXPECT_FALSE(should_report)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(should_report))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 496, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "should_report", "true", "false") .c_str()) = ::testing::Message (); |
| 497 | current_interval = mond->getCurrentInterval(); |
| 498 | ASSERT_TRUE(current_interval)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(current_interval)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 498, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "current_interval", "false", "true") .c_str()) = ::testing:: Message(); |
| 499 | |
| 500 | // Make sure the current interval hasn't been replaced and we |
| 501 | // have no previous interval. |
| 502 | EXPECT_EQ(current_interval, original_interval)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("current_interval" , "original_interval", current_interval, original_interval))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 502, gtest_ar.failure_message()) = ::testing::Message(); |
| 503 | EXPECT_FALSE(mond->getPreviousInterval())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(mond->getPreviousInterval ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 503, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "mond->getPreviousInterval()", "true", "false") .c_str() ) = ::testing::Message(); |
| 504 | // Verify the sample was added. |
| 505 | EXPECT_EQ(current_interval->getOccurrences(), (i + 1))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("current_interval->getOccurrences()" , "(i + 1)", current_interval->getOccurrences(), (i + 1))) ) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 505, gtest_ar.failure_message()) = ::testing::Message(); |
| 506 | EXPECT_EQ(current_interval->getTotalDuration(), (two_ms * (i + 1)))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("current_interval->getTotalDuration()" , "(two_ms * (i + 1))", current_interval->getTotalDuration (), (two_ms * (i + 1))))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 506, gtest_ar.failure_message()) = ::testing::Message(); |
| 507 | } |
| 508 | |
| 509 | // Sleep til past the end of interval |
| 510 | usleep(60 * 1000); |
| 511 | |
| 512 | // Add another sample. |
| 513 | ASSERT_NO_THROW(should_report = mond->addSample(two_ms))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { should_report = mond->addSample(two_ms); } else static_assert (true, ""); } catch (std::exception const& e) { gtest_msg .value = "it throws "; gtest_msg.value += ::testing::internal ::GetTypeName(typeid(e)); gtest_msg.value += " with description \"" ; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_513; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_513; } } else gtest_label_testnothrow_513 : return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 513, ("Expected: " "should_report = mond->addSample(two_ms)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value ) .c_str()) = ::testing::Message(); |
| 514 | current_interval = mond->getCurrentInterval(); |
| 515 | ASSERT_TRUE(current_interval)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(current_interval)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 515, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "current_interval", "false", "true") .c_str()) = ::testing:: Message(); |
| 516 | |
| 517 | // We should have crossed the interval boundary. |
| 518 | // Previous interval should be equal to the original interval and |
| 519 | // should_report should be true. The new current interval should |
| 520 | // have 1 occurrence and a total of 10ms. |
| 521 | previous_interval = mond->getPreviousInterval(); |
| 522 | EXPECT_TRUE(previous_interval)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(previous_interval)) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 522, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "previous_interval", "false", "true") .c_str()) = ::testing ::Message(); |
| 523 | EXPECT_EQ(previous_interval, original_interval)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("previous_interval" , "original_interval", previous_interval, original_interval)) ) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 523, gtest_ar.failure_message()) = ::testing::Message(); |
| 524 | EXPECT_TRUE(should_report)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(should_report)) ; else ::testing::internal::AssertHelper(::testing::TestPartResult:: kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 524, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "should_report", "false", "true") .c_str()) = ::testing::Message (); |
| 525 | EXPECT_EQ(current_interval->getOccurrences(), 1)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("current_interval->getOccurrences()" , "1", current_interval->getOccurrences(), 1))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 525, gtest_ar.failure_message()) = ::testing::Message(); |
| 526 | EXPECT_EQ(current_interval->getTotalDuration(), two_ms)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("current_interval->getTotalDuration()" , "two_ms", current_interval->getTotalDuration(), two_ms)) ) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 526, gtest_ar.failure_message()) = ::testing::Message(); |
| 527 | |
| 528 | // Verify that clear wipes the intervals. |
| 529 | ASSERT_NO_THROW_LOG(mond->clear()){ try { mond->clear(); } catch (const std::exception& ex ) { return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 529, "Failed") = ::testing::Message() << "mond->clear()" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 529, "Failed") = ::testing::Message() << "mond->clear()" << " threw non-std::exception"; } }; |
| 530 | EXPECT_FALSE(mond->getCurrentInterval())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(mond->getCurrentInterval ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 530, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "mond->getCurrentInterval()", "true", "false") .c_str()) = ::testing::Message(); |
| 531 | EXPECT_FALSE(mond->getPreviousInterval())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(mond->getPreviousInterval ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 531, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "mond->getPreviousInterval()", "true", "false") .c_str() ) = ::testing::Message(); |
| 532 | } |
| 533 | |
| 534 | TEST(MonitoredDuration, expireInterval)static_assert(sizeof("MonitoredDuration") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("expireInterval") > 1, "test_name must not be empty" ); class MonitoredDuration_expireInterval_Test : public ::testing ::Test { public: MonitoredDuration_expireInterval_Test() = default ; ~MonitoredDuration_expireInterval_Test() override = default ; MonitoredDuration_expireInterval_Test (const MonitoredDuration_expireInterval_Test &) = delete; MonitoredDuration_expireInterval_Test & operator=( const MonitoredDuration_expireInterval_Test & ) = delete; MonitoredDuration_expireInterval_Test (MonitoredDuration_expireInterval_Test &&) noexcept = delete; MonitoredDuration_expireInterval_Test & operator=( MonitoredDuration_expireInterval_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const MonitoredDuration_expireInterval_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "MonitoredDuration" , "expireInterval", nullptr, nullptr, ::testing::internal::CodeLocation ("../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 534), (::testing::internal::GetTestTypeId()), ::testing::internal ::SuiteApiResolver< ::testing::Test>::GetSetUpCaseOrSuite ("../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 534), ::testing::internal::SuiteApiResolver< ::testing:: Test>::GetTearDownCaseOrSuite("../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 534), new ::testing::internal::TestFactoryImpl<MonitoredDuration_expireInterval_Test >); void MonitoredDuration_expireInterval_Test::TestBody() { |
| 535 | MonitoredDurationPtr mond; |
| 536 | Duration interval_duration(milliseconds(50)); |
| 537 | auto start_time = PktEvent::now(); |
Value stored to 'start_time' during its initialization is never read | |
| 538 | auto ten_ms = milliseconds(10); |
| 539 | |
| 540 | // Create valid v4 duration with interval duration of 50ms. |
| 541 | ASSERT_NO_THROW_LOG(mond.reset(new MonitoredDuration(AF_INET, DHCPDISCOVER, DHCPOFFER,{ try { mond.reset(new MonitoredDuration(2, DHCPDISCOVER, DHCPOFFER , "process_started", "process_completed", SUBNET_ID_GLOBAL, interval_duration )); } catch (const std::exception& ex) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 543, "Failed") = ::testing::Message() << "mond.reset(new MonitoredDuration(AF_INET, DHCPDISCOVER, DHCPOFFER, \"process_started\", \"process_completed\", SUBNET_ID_GLOBAL, interval_duration))" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 543, "Failed") = ::testing::Message() << "mond.reset(new MonitoredDuration(AF_INET, DHCPDISCOVER, DHCPOFFER, \"process_started\", \"process_completed\", SUBNET_ID_GLOBAL, interval_duration))" << " threw non-std::exception"; } } |
| 542 | "process_started", "process_completed",{ try { mond.reset(new MonitoredDuration(2, DHCPDISCOVER, DHCPOFFER , "process_started", "process_completed", SUBNET_ID_GLOBAL, interval_duration )); } catch (const std::exception& ex) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 543, "Failed") = ::testing::Message() << "mond.reset(new MonitoredDuration(AF_INET, DHCPDISCOVER, DHCPOFFER, \"process_started\", \"process_completed\", SUBNET_ID_GLOBAL, interval_duration))" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 543, "Failed") = ::testing::Message() << "mond.reset(new MonitoredDuration(AF_INET, DHCPDISCOVER, DHCPOFFER, \"process_started\", \"process_completed\", SUBNET_ID_GLOBAL, interval_duration))" << " threw non-std::exception"; } } |
| 543 | SUBNET_ID_GLOBAL, interval_duration))){ try { mond.reset(new MonitoredDuration(2, DHCPDISCOVER, DHCPOFFER , "process_started", "process_completed", SUBNET_ID_GLOBAL, interval_duration )); } catch (const std::exception& ex) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 543, "Failed") = ::testing::Message() << "mond.reset(new MonitoredDuration(AF_INET, DHCPDISCOVER, DHCPOFFER, \"process_started\", \"process_completed\", SUBNET_ID_GLOBAL, interval_duration))" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 543, "Failed") = ::testing::Message() << "mond.reset(new MonitoredDuration(AF_INET, DHCPDISCOVER, DHCPOFFER, \"process_started\", \"process_completed\", SUBNET_ID_GLOBAL, interval_duration))" << " threw non-std::exception"; } }; |
| 544 | ASSERT_TRUE(mond)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(mond)) ; else return :: testing::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 544, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "mond", "false", "true") .c_str()) = ::testing::Message(); |
| 545 | |
| 546 | // Initially there are no intervals. |
| 547 | EXPECT_FALSE(mond->getCurrentInterval())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(mond->getCurrentInterval ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 547, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "mond->getCurrentInterval()", "true", "false") .c_str()) = ::testing::Message(); |
| 548 | EXPECT_FALSE(mond->getPreviousInterval())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(mond->getPreviousInterval ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 548, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "mond->getPreviousInterval()", "true", "false") .c_str() ) = ::testing::Message(); |
| 549 | EXPECT_EQ(mond->getCurrentIntervalStart(), PktEvent::MIN_TIME())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("mond->getCurrentIntervalStart()" , "PktEvent::MIN_TIME()", mond->getCurrentIntervalStart(), PktEvent::MIN_TIME()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 549, gtest_ar.failure_message()) = ::testing::Message(); |
| 550 | |
| 551 | ASSERT_THROW_MSG(mond->expireCurrentInterval(), InvalidOperation,{ try { mond->expireCurrentInterval(); return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 553, "Failed") = ::testing::Message() << "no exception, expected: " << "InvalidOperation"; } catch (const InvalidOperation & ex) { switch (0) case 0: default: if (const ::testing:: AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare ("std::string(ex.what())", "\"MonitoredDuration::expireInterval - no current interval for:\" \" DHCPDISCOVER-DHCPOFFER.process_started-process_completed.0\"" , std::string(ex.what()), "MonitoredDuration::expireInterval - no current interval for:" " DHCPDISCOVER-DHCPOFFER.process_started-process_completed.0" ))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 553, gtest_ar.failure_message()) = ::testing::Message(); } catch (...) { return ::testing::internal::AssertHelper(::testing:: TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 553, "Failed") = ::testing::Message() << "wrong exception type thrown, expected: " << "InvalidOperation"; } } |
| 552 | "MonitoredDuration::expireInterval - no current interval for:"{ try { mond->expireCurrentInterval(); return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 553, "Failed") = ::testing::Message() << "no exception, expected: " << "InvalidOperation"; } catch (const InvalidOperation & ex) { switch (0) case 0: default: if (const ::testing:: AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare ("std::string(ex.what())", "\"MonitoredDuration::expireInterval - no current interval for:\" \" DHCPDISCOVER-DHCPOFFER.process_started-process_completed.0\"" , std::string(ex.what()), "MonitoredDuration::expireInterval - no current interval for:" " DHCPDISCOVER-DHCPOFFER.process_started-process_completed.0" ))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 553, gtest_ar.failure_message()) = ::testing::Message(); } catch (...) { return ::testing::internal::AssertHelper(::testing:: TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 553, "Failed") = ::testing::Message() << "wrong exception type thrown, expected: " << "InvalidOperation"; } } |
| 553 | " DHCPDISCOVER-DHCPOFFER.process_started-process_completed.0"){ try { mond->expireCurrentInterval(); return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 553, "Failed") = ::testing::Message() << "no exception, expected: " << "InvalidOperation"; } catch (const InvalidOperation & ex) { switch (0) case 0: default: if (const ::testing:: AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare ("std::string(ex.what())", "\"MonitoredDuration::expireInterval - no current interval for:\" \" DHCPDISCOVER-DHCPOFFER.process_started-process_completed.0\"" , std::string(ex.what()), "MonitoredDuration::expireInterval - no current interval for:" " DHCPDISCOVER-DHCPOFFER.process_started-process_completed.0" ))) ; else return ::testing::internal::AssertHelper(::testing ::TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 553, gtest_ar.failure_message()) = ::testing::Message(); } catch (...) { return ::testing::internal::AssertHelper(::testing:: TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 553, "Failed") = ::testing::Message() << "wrong exception type thrown, expected: " << "InvalidOperation"; } }; |
| 554 | |
| 555 | ASSERT_NO_THROW(mond->addSample(ten_ms))switch (0) case 0: default: if (::testing::internal::TrueWithString gtest_msg{}) { try { if (::testing::internal::AlwaysTrue()) { mond->addSample(ten_ms); } else static_assert(true, ""); } catch (std::exception const& e) { gtest_msg.value = "it throws " ; gtest_msg.value += ::testing::internal::GetTypeName(typeid( e)); gtest_msg.value += " with description \""; gtest_msg.value += e.what(); gtest_msg.value += "\"."; goto gtest_label_testnothrow_555 ; } catch (...) { gtest_msg.value = "it throws."; goto gtest_label_testnothrow_555 ; } } else gtest_label_testnothrow_555 : return ::testing::internal ::AssertHelper(::testing::TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 555, ("Expected: " "mond->addSample(ten_ms)" " doesn't throw an exception.\n" " Actual: " + gtest_msg.value) .c_str()) = ::testing::Message (); |
| 556 | auto current_interval = mond->getCurrentInterval(); |
| 557 | ASSERT_TRUE(current_interval)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(current_interval)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 557, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "current_interval", "false", "true") .c_str()) = ::testing:: Message(); |
| 558 | EXPECT_EQ(current_interval->getOccurrences(), 1)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("current_interval->getOccurrences()" , "1", current_interval->getOccurrences(), 1))) ; else ::testing ::internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 558, gtest_ar.failure_message()) = ::testing::Message(); |
| 559 | EXPECT_EQ(current_interval->getTotalDuration(), ten_ms)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("current_interval->getTotalDuration()" , "ten_ms", current_interval->getTotalDuration(), ten_ms)) ) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 559, gtest_ar.failure_message()) = ::testing::Message(); |
| 560 | EXPECT_FALSE(mond->getPreviousInterval())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(mond->getPreviousInterval ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 560, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "mond->getPreviousInterval()", "true", "false") .c_str() ) = ::testing::Message(); |
| 561 | EXPECT_GE(mond->getCurrentIntervalStart(), start_time)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::CmpHelperGE("mond->getCurrentIntervalStart()" , "start_time", mond->getCurrentIntervalStart(), start_time ))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 561, gtest_ar.failure_message()) = ::testing::Message(); |
| 562 | EXPECT_EQ(mond->getCurrentIntervalStart(), current_interval->getStartTime())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("mond->getCurrentIntervalStart()" , "current_interval->getStartTime()", mond->getCurrentIntervalStart (), current_interval->getStartTime()))) ; else ::testing:: internal::AssertHelper(::testing::TestPartResult::kNonFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 562, gtest_ar.failure_message()) = ::testing::Message(); |
| 563 | |
| 564 | ASSERT_NO_THROW_LOG(mond->expireCurrentInterval()){ try { mond->expireCurrentInterval(); } catch (const std:: exception& ex) { return ::testing::internal::AssertHelper (::testing::TestPartResult::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 564, "Failed") = ::testing::Message() << "mond->expireCurrentInterval()" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 564, "Failed") = ::testing::Message() << "mond->expireCurrentInterval()" << " threw non-std::exception"; } }; |
| 565 | EXPECT_FALSE(mond->getCurrentInterval())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(!(mond->getCurrentInterval ()))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 565, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "mond->getCurrentInterval()", "true", "false") .c_str()) = ::testing::Message(); |
| 566 | |
| 567 | auto previous_interval = mond->getPreviousInterval(); |
| 568 | EXPECT_EQ(previous_interval, current_interval)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("previous_interval" , "current_interval", previous_interval, current_interval))) ; else ::testing::internal::AssertHelper(::testing::TestPartResult ::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 568, gtest_ar.failure_message()) = ::testing::Message(); |
| 569 | EXPECT_EQ(mond->getCurrentIntervalStart(), PktEvent::MIN_TIME())switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("mond->getCurrentIntervalStart()" , "PktEvent::MIN_TIME()", mond->getCurrentIntervalStart(), PktEvent::MIN_TIME()))) ; else ::testing::internal::AssertHelper (::testing::TestPartResult::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 569, gtest_ar.failure_message()) = ::testing::Message(); |
| 570 | } |
| 571 | |
| 572 | // Verifies the MonitoredDuration::toElement(). We do not bother with |
| 573 | // a v6 version of this test as family only influences DurationKey content |
| 574 | // and that is tested elsewhere. |
| 575 | TEST(MonitoredDuration, toElement)static_assert(sizeof("MonitoredDuration") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("toElement") > 1, "test_name must not be empty" ); class MonitoredDuration_toElement_Test : public ::testing:: Test { public: MonitoredDuration_toElement_Test() = default; ~ MonitoredDuration_toElement_Test() override = default; MonitoredDuration_toElement_Test (const MonitoredDuration_toElement_Test &) = delete; MonitoredDuration_toElement_Test & operator=( const MonitoredDuration_toElement_Test & ) = delete; MonitoredDuration_toElement_Test (MonitoredDuration_toElement_Test &&) noexcept = delete; MonitoredDuration_toElement_Test & operator=( MonitoredDuration_toElement_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const MonitoredDuration_toElement_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "MonitoredDuration" , "toElement", nullptr, nullptr, ::testing::internal::CodeLocation ("../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 575), (::testing::internal::GetTestTypeId()), ::testing::internal ::SuiteApiResolver< ::testing::Test>::GetSetUpCaseOrSuite ("../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 575), ::testing::internal::SuiteApiResolver< ::testing:: Test>::GetTearDownCaseOrSuite("../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 575), new ::testing::internal::TestFactoryImpl<MonitoredDuration_toElement_Test >); void MonitoredDuration_toElement_Test::TestBody() { |
| 576 | MonitoredDurationPtr duration; |
| 577 | Duration interval_duration(milliseconds(50)); |
| 578 | |
| 579 | // Create valid v4 duration. |
| 580 | ASSERT_NO_THROW_LOG(duration.reset(new MonitoredDuration(AF_INET, DHCPDISCOVER, DHCPOFFER,{ try { duration.reset(new MonitoredDuration(2, DHCPDISCOVER, DHCPOFFER, "process_started", "process_completed", SUBNET_ID_GLOBAL , interval_duration)); } catch (const std::exception& ex) { return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 582, "Failed") = ::testing::Message() << "duration.reset(new MonitoredDuration(AF_INET, DHCPDISCOVER, DHCPOFFER, \"process_started\", \"process_completed\", SUBNET_ID_GLOBAL, interval_duration))" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 582, "Failed") = ::testing::Message() << "duration.reset(new MonitoredDuration(AF_INET, DHCPDISCOVER, DHCPOFFER, \"process_started\", \"process_completed\", SUBNET_ID_GLOBAL, interval_duration))" << " threw non-std::exception"; } } |
| 581 | "process_started", "process_completed",{ try { duration.reset(new MonitoredDuration(2, DHCPDISCOVER, DHCPOFFER, "process_started", "process_completed", SUBNET_ID_GLOBAL , interval_duration)); } catch (const std::exception& ex) { return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 582, "Failed") = ::testing::Message() << "duration.reset(new MonitoredDuration(AF_INET, DHCPDISCOVER, DHCPOFFER, \"process_started\", \"process_completed\", SUBNET_ID_GLOBAL, interval_duration))" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 582, "Failed") = ::testing::Message() << "duration.reset(new MonitoredDuration(AF_INET, DHCPDISCOVER, DHCPOFFER, \"process_started\", \"process_completed\", SUBNET_ID_GLOBAL, interval_duration))" << " threw non-std::exception"; } } |
| 582 | SUBNET_ID_GLOBAL, interval_duration))){ try { duration.reset(new MonitoredDuration(2, DHCPDISCOVER, DHCPOFFER, "process_started", "process_completed", SUBNET_ID_GLOBAL , interval_duration)); } catch (const std::exception& ex) { return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 582, "Failed") = ::testing::Message() << "duration.reset(new MonitoredDuration(AF_INET, DHCPDISCOVER, DHCPOFFER, \"process_started\", \"process_completed\", SUBNET_ID_GLOBAL, interval_duration))" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 582, "Failed") = ::testing::Message() << "duration.reset(new MonitoredDuration(AF_INET, DHCPDISCOVER, DHCPOFFER, \"process_started\", \"process_completed\", SUBNET_ID_GLOBAL, interval_duration))" << " threw non-std::exception"; } }; |
| 583 | ASSERT_TRUE(duration)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(duration)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 583, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "duration", "false", "true") .c_str()) = ::testing::Message (); |
| 584 | duration->addSample(microseconds(5)); |
| 585 | duration->addSample(microseconds(2)); |
| 586 | duration->addSample(microseconds(7)); |
| 587 | |
| 588 | ElementPtr ref_duration_elem = Element::createMap(); |
| 589 | // Add the key. |
| 590 | ElementPtr ref_key_elem = Element::createMap(); |
| 591 | ref_key_elem->set("query-type", Element::create("DHCPDISCOVER")); |
| 592 | ref_key_elem->set("response-type", Element::create("DHCPOFFER")); |
| 593 | ref_key_elem->set("start-event", Element::create("process_started")); |
| 594 | ref_key_elem->set("stop-event", Element::create("process_completed")); |
| 595 | ref_key_elem->set("subnet-id", Element::create(SUBNET_ID_GLOBAL)); |
| 596 | ref_duration_elem->set("duration-key", ref_key_elem); |
| 597 | |
| 598 | // Add the data. Should have empty values as we do not have a previous interval. |
| 599 | ref_duration_elem->set("mean-duration-usecs", Element::create(0)); |
| 600 | ref_duration_elem->set("max-duration-usecs", Element::create(0)); |
| 601 | ref_duration_elem->set("min-duration-usecs", Element::create(0)); |
| 602 | ref_duration_elem->set("occurrences", Element::create(0)); |
| 603 | ref_duration_elem->set("start-time", Element::create("<none>")); |
| 604 | ref_duration_elem->set("total-duration-usecs", Element::create(0)); |
| 605 | |
| 606 | std::string expected_json = |
| 607 | R"({ |
| 608 | "mean-duration-usecs": 0, |
| 609 | "duration-key": { |
| 610 | "query-type": "DHCPDISCOVER", |
| 611 | "response-type": "DHCPOFFER", |
| 612 | "start-event": "process_started", |
| 613 | "stop-event": "process_completed", |
| 614 | "subnet-id": 0 }, |
| 615 | "max-duration-usecs": 0, |
| 616 | "min-duration-usecs": 0, |
| 617 | "occurrences": 0, |
| 618 | "start-time": "<none>", |
| 619 | "total-duration-usecs": 0 |
| 620 | })"; |
| 621 | |
| 622 | // Check toElement() against expected JSON. |
| 623 | runToElementTest(expected_json, *duration); |
| 624 | |
| 625 | // Now expire the current interval so we'll have a previous interval. |
| 626 | duration->expireCurrentInterval(); |
| 627 | auto previous_interval = duration->getPreviousInterval(); |
| 628 | ASSERT_TRUE(previous_interval)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(previous_interval)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 628, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "previous_interval", "false", "true") .c_str()) = ::testing ::Message(); |
| 629 | |
| 630 | std::ostringstream oss; |
| 631 | oss << |
| 632 | R"({ |
| 633 | "mean-duration-usecs": 4, |
| 634 | "duration-key": { |
| 635 | "query-type": "DHCPDISCOVER", |
| 636 | "response-type": "DHCPOFFER", |
| 637 | "start-event": "process_started", |
| 638 | "stop-event": "process_completed", |
| 639 | "subnet-id": 0 }, |
| 640 | "max-duration-usecs": 7, |
| 641 | "min-duration-usecs": 2, |
| 642 | "occurrences": 3, |
| 643 | "start-time": ")" |
| 644 | << ptimeToText(previous_interval->getStartTime()) |
| 645 | << R"(", "total-duration-usecs": 14 })"; |
| 646 | |
| 647 | // Check toElement() against expected JSON. |
| 648 | runToElementTest(oss.str(), *duration); |
| 649 | } |
| 650 | |
| 651 | // Verifies the MonitoredDuration::toElement(). We do not bother with |
| 652 | // a v4 version of this test as family only influences DurationKey content |
| 653 | // and that is tested elsewhere. |
| 654 | TEST(MonitoredDuration, toValueRow)static_assert(sizeof("MonitoredDuration") > 1, "test_suite_name must not be empty" ); static_assert(sizeof("toValueRow") > 1, "test_name must not be empty" ); class MonitoredDuration_toValueRow_Test : public ::testing ::Test { public: MonitoredDuration_toValueRow_Test() = default ; ~MonitoredDuration_toValueRow_Test() override = default; MonitoredDuration_toValueRow_Test (const MonitoredDuration_toValueRow_Test &) = delete; MonitoredDuration_toValueRow_Test & operator=( const MonitoredDuration_toValueRow_Test & ) = delete; MonitoredDuration_toValueRow_Test (MonitoredDuration_toValueRow_Test &&) noexcept = delete; MonitoredDuration_toValueRow_Test & operator=( MonitoredDuration_toValueRow_Test && ) noexcept = delete; private: void TestBody() override; [[maybe_unused ]] static ::testing::TestInfo* const test_info_; }; ::testing ::TestInfo* const MonitoredDuration_toValueRow_Test::test_info_ = ::testing::internal::MakeAndRegisterTestInfo( "MonitoredDuration" , "toValueRow", nullptr, nullptr, ::testing::internal::CodeLocation ("../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 654), (::testing::internal::GetTestTypeId()), ::testing::internal ::SuiteApiResolver< ::testing::Test>::GetSetUpCaseOrSuite ("../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 654), ::testing::internal::SuiteApiResolver< ::testing:: Test>::GetTearDownCaseOrSuite("../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 654), new ::testing::internal::TestFactoryImpl<MonitoredDuration_toValueRow_Test >); void MonitoredDuration_toValueRow_Test::TestBody() { |
| 655 | MonitoredDurationPtr duration; |
| 656 | Duration interval_duration(milliseconds(50)); |
| 657 | |
| 658 | // Create valid v4 duration. |
| 659 | ASSERT_NO_THROW_LOG(duration.reset(new MonitoredDuration(AF_INET6, DHCPV6_SOLICIT, DHCPV6_ADVERTISE,{ try { duration.reset(new MonitoredDuration(10, DHCPV6_SOLICIT , DHCPV6_ADVERTISE, "process_started", "process_completed", SUBNET_ID_GLOBAL , interval_duration)); } catch (const std::exception& ex) { return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 661, "Failed") = ::testing::Message() << "duration.reset(new MonitoredDuration(AF_INET6, DHCPV6_SOLICIT, DHCPV6_ADVERTISE, \"process_started\", \"process_completed\", SUBNET_ID_GLOBAL, interval_duration))" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 661, "Failed") = ::testing::Message() << "duration.reset(new MonitoredDuration(AF_INET6, DHCPV6_SOLICIT, DHCPV6_ADVERTISE, \"process_started\", \"process_completed\", SUBNET_ID_GLOBAL, interval_duration))" << " threw non-std::exception"; } } |
| 660 | "process_started", "process_completed",{ try { duration.reset(new MonitoredDuration(10, DHCPV6_SOLICIT , DHCPV6_ADVERTISE, "process_started", "process_completed", SUBNET_ID_GLOBAL , interval_duration)); } catch (const std::exception& ex) { return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 661, "Failed") = ::testing::Message() << "duration.reset(new MonitoredDuration(AF_INET6, DHCPV6_SOLICIT, DHCPV6_ADVERTISE, \"process_started\", \"process_completed\", SUBNET_ID_GLOBAL, interval_duration))" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 661, "Failed") = ::testing::Message() << "duration.reset(new MonitoredDuration(AF_INET6, DHCPV6_SOLICIT, DHCPV6_ADVERTISE, \"process_started\", \"process_completed\", SUBNET_ID_GLOBAL, interval_duration))" << " threw non-std::exception"; } } |
| 661 | SUBNET_ID_GLOBAL, interval_duration))){ try { duration.reset(new MonitoredDuration(10, DHCPV6_SOLICIT , DHCPV6_ADVERTISE, "process_started", "process_completed", SUBNET_ID_GLOBAL , interval_duration)); } catch (const std::exception& ex) { return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 661, "Failed") = ::testing::Message() << "duration.reset(new MonitoredDuration(AF_INET6, DHCPV6_SOLICIT, DHCPV6_ADVERTISE, \"process_started\", \"process_completed\", SUBNET_ID_GLOBAL, interval_duration))" << " threw type: " << typeid(ex).name() << ", what: " << ex.what(); } catch (...) { return ::testing ::internal::AssertHelper(::testing::TestPartResult::kFatalFailure , "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 661, "Failed") = ::testing::Message() << "duration.reset(new MonitoredDuration(AF_INET6, DHCPV6_SOLICIT, DHCPV6_ADVERTISE, \"process_started\", \"process_completed\", SUBNET_ID_GLOBAL, interval_duration))" << " threw non-std::exception"; } }; |
| 662 | ASSERT_TRUE(duration)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(duration)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 662, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "duration", "false", "true") .c_str()) = ::testing::Message (); |
| 663 | duration->addSample(microseconds(5)); |
| 664 | duration->addSample(microseconds(2)); |
| 665 | duration->addSample(microseconds(7)); |
| 666 | |
| 667 | ElementPtr ref_row_elem = Element::createList(); |
| 668 | // Add key values first. |
| 669 | ref_row_elem->add(Element::create("SOLICIT")); // query-type |
| 670 | ref_row_elem->add(Element::create("ADVERTISE")); // response-type |
| 671 | ref_row_elem->add(Element::create("process_started")); // start-event |
| 672 | ref_row_elem->add(Element::create("process_completed")); // stop-event |
| 673 | ref_row_elem->add(Element::create(SUBNET_ID_GLOBAL)); // subnet-id |
| 674 | |
| 675 | // Remember where the data values begin. |
| 676 | auto data_start = ref_row_elem->size(); |
| 677 | |
| 678 | // Add the data values. Should have empty values as we do not have a previous interval. |
| 679 | ref_row_elem->add(Element::create("<none>")); // start-time |
| 680 | ref_row_elem->add(Element::create(0)); // occurrences |
| 681 | ref_row_elem->add(Element::create(0)); // min-duration-usecs |
| 682 | ref_row_elem->add(Element::create(0)); // max-duration-usecs |
| 683 | ref_row_elem->add(Element::create(0)); // total-duration-usecs |
| 684 | ref_row_elem->add(Element::create(0)); // mean-duration-usecs |
| 685 | |
| 686 | // Generate the valueRow Element and compare it to the reference. |
| 687 | auto row_elem = duration->toValueRow(); |
| 688 | |
| 689 | ASSERT_TRUE(row_elem)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(row_elem)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 689, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "row_elem", "false", "true") .c_str()) = ::testing::Message (); |
| 690 | EXPECT_EQ(prettyPrint(ref_row_elem), prettyPrint(row_elem))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("prettyPrint(ref_row_elem)" , "prettyPrint(row_elem)", prettyPrint(ref_row_elem), prettyPrint (row_elem)))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 690, gtest_ar.failure_message()) = ::testing::Message(); |
| 691 | |
| 692 | // Now expire the current interval so we'll have a previous interval. |
| 693 | duration->expireCurrentInterval(); |
| 694 | auto previous_interval = duration->getPreviousInterval(); |
| 695 | ASSERT_TRUE(previous_interval)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(previous_interval)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult ::kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 695, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "previous_interval", "false", "true") .c_str()) = ::testing ::Message(); |
| 696 | |
| 697 | // Remove the old reference data values. |
| 698 | while (ref_row_elem->size() > data_start) { |
| 699 | ref_row_elem->remove(data_start); |
| 700 | } |
| 701 | |
| 702 | // Add the new reference data values. |
| 703 | ref_row_elem->add(Element::create(ptimeToText(previous_interval->getStartTime()))); |
| 704 | ref_row_elem->add(Element::create(3)); // occurrences |
| 705 | ref_row_elem->add(Element::create(2)); // min-duration-usecs |
| 706 | ref_row_elem->add(Element::create(7)); // max-duration-usecs |
| 707 | ref_row_elem->add(Element::create(14)); // total-duration-usecs |
| 708 | ref_row_elem->add(Element::create(4)); // mean-duration-usecs |
| 709 | |
| 710 | // Generate the valueRow Element and compare it to the reference. |
| 711 | row_elem = duration->toValueRow(); |
| 712 | ASSERT_TRUE(row_elem)switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar_ = ::testing::AssertionResult(row_elem)) ; else return ::testing::internal::AssertHelper(::testing::TestPartResult:: kFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 712, ::testing::internal::GetBoolAssertionFailureMessage( gtest_ar_ , "row_elem", "false", "true") .c_str()) = ::testing::Message (); |
| 713 | EXPECT_EQ(prettyPrint(ref_row_elem), prettyPrint(row_elem))switch (0) case 0: default: if (const ::testing::AssertionResult gtest_ar = (::testing::internal::EqHelper::Compare("prettyPrint(ref_row_elem)" , "prettyPrint(row_elem)", prettyPrint(ref_row_elem), prettyPrint (row_elem)))) ; else ::testing::internal::AssertHelper(::testing ::TestPartResult::kNonFatalFailure, "../../../src/hooks/dhcp/perfmon/tests/monitored_duration_unittests.cc" , 713, gtest_ar.failure_message()) = ::testing::Message(); |
| 714 | } |
| 715 | |
| 716 | } // end of anonymous namespace |