unittest_timeout_adjust_func.cpp
Go to the documentation of this file.
1 // Copyright (c) 2020 Pilz GmbH & Co. KG
2 //
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU Lesser General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public License
14 // along with this program. If not, see <https://www.gnu.org/licenses/>.
15 
16 #include <chrono>
17 
18 #include <gtest/gtest.h>
19 
21 
22 using namespace psen_scan_utils;
23 
24 namespace psen_scan_test
25 {
26 TEST(TimeoutAdjustFuncTests, testTimeoutIncrease)
27 {
28  constexpr auto max_timeout{ std::chrono::seconds(77) };
29  constexpr auto timeout_increase{ std::chrono::seconds(7) };
30  constexpr auto my_timeout{ max_timeout - 2 * timeout_increase };
31  ASSERT_EQ(my_timeout + timeout_increase, adjustTimeout(my_timeout, timeout_increase, max_timeout))
32  << "Incorrect timeout increase";
33 }
34 
35 TEST(TimeoutAdjustFuncTests, testMaxTimeoutExceed)
36 {
37  constexpr auto my_timeout{ std::chrono::seconds(75) };
38  constexpr auto timeout_increase{ std::chrono::seconds(7) };
39  constexpr auto max_allowed_timeout{ std::chrono::seconds(77) };
40 
41  ASSERT_EQ(max_allowed_timeout, adjustTimeout(my_timeout, timeout_increase, max_allowed_timeout))
42  << "Incorrect max timeout returned";
43 }
44 
45 TEST(TimeoutAdjustFuncTests, testDefaultTimeoutIncrease)
46 {
47  constexpr auto my_timeout{ std::chrono::seconds(20) };
48  ASSERT_EQ(my_timeout + DEFAULT_TIMEOUT_INCREASE, adjustTimeout(my_timeout)) << "Default timeout increase incorrect";
49 }
50 
51 TEST(TimeoutAdjustFuncTests, testDefaultMaxTimeout)
52 {
53  constexpr auto my_timeout{ DEFAULT_MAX_TIMEOUT - std::chrono::seconds(1) };
54  constexpr auto timeout_increase{ std::chrono::seconds(2) };
55 
56  ASSERT_EQ(DEFAULT_MAX_TIMEOUT, adjustTimeout(my_timeout, timeout_increase)) << "Max default timeout incorrect";
57 }
58 
59 TEST(TimeoutAdjustFuncTests, testMaxTimeoutExceedingTimeoutArgument)
60 {
61  constexpr auto my_timeout{ DEFAULT_MAX_TIMEOUT + std::chrono::seconds(7) };
62  ASSERT_EQ(DEFAULT_MAX_TIMEOUT, adjustTimeout(my_timeout)) << "Max timeout incorrect";
63 }
64 
65 } // namespace psen_scan_test
constexpr auto DEFAULT_TIMEOUT_INCREASE
static std::chrono::steady_clock::duration adjustTimeout(const std::chrono::steady_clock::duration &timeout, const std::chrono::steady_clock::duration timeout_increase=DEFAULT_TIMEOUT_INCREASE, const std::chrono::steady_clock::duration max_timeout=DEFAULT_MAX_TIMEOUT)
Increases the given timeout by the specified timeout increase. If the new timeout exceeds the max tim...
constexpr auto DEFAULT_MAX_TIMEOUT
TEST(TimeoutAdjustFuncTests, testMaxTimeoutExceedingTimeoutArgument)


psen_scan
Author(s):
autogenerated on Mon Feb 28 2022 23:16:20