2 Copyright (c) 2018-2019 Nokia.
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
18 * This source code is part of the near-RT RIC (RAN Intelligent Controller)
19 * platform project (RICP).
22 #include <type_traits>
24 #include <gmock/gmock.h>
25 #include "private/timer.hpp"
26 #include "private/tst/enginemock.hpp"
28 using namespace shareddatalayer;
29 using namespace shareddatalayer::tst;
30 using namespace testing;
34 class TimerTest: public testing::Test
37 NiceMock<EngineMock> engineMock;
38 const Timer::Duration duration;
39 std::unique_ptr<Timer> timer;
42 duration(std::chrono::duration_cast<Timer::Duration>(std::chrono::seconds(12))),
43 timer(new Timer(engineMock))
51 TEST_F(TimerTest, IsNotCopyableAndIsNotMovable)
53 EXPECT_FALSE(std::is_copy_assignable<Timer>::value);
54 EXPECT_FALSE(std::is_move_assignable<Timer>::value);
55 EXPECT_FALSE(std::is_copy_constructible<Timer>::value);
56 EXPECT_FALSE(std::is_move_constructible<Timer>::value);
59 TEST_F(TimerTest, ArmCallsArmOfAssociatedTimerService)
61 EXPECT_CALL(engineMock, armTimer(_, duration, _))
63 timer->arm(duration, nop);
66 TEST_F(TimerTest, DisarmingCallsDisarmOfAssociatedTimerService)
68 timer->arm(duration, nop);
69 EXPECT_CALL(engineMock, disarmTimer(_))
74 TEST_F(TimerTest, DisarmingUnArmedTimerDoesNothing)
76 EXPECT_CALL(engineMock, disarmTimer(_))
81 TEST_F(TimerTest, DoubleDisarmingDoesNothing)
83 timer->arm(duration, nop);
84 EXPECT_CALL(engineMock, disarmTimer(_))
90 TEST_F(TimerTest, DoubleArmingDisarmsFirst)
93 EXPECT_CALL(engineMock, armTimer(_, duration, _))
95 timer->arm(duration, nop);
96 EXPECT_CALL(engineMock, disarmTimer(_))
98 EXPECT_CALL(engineMock, armTimer(_, duration, _))
100 timer->arm(duration, nop);
101 Mock::VerifyAndClear(&engineMock);
104 TEST_F(TimerTest, DestructorDisarms)
106 timer->arm(duration, nop);
107 EXPECT_CALL(engineMock, disarmTimer(_))
112 TEST_F(TimerTest, AfterTimerHasExpiredItIsNotArmedAnymore)
114 Timer::Callback savedCb;
115 ON_CALL(engineMock, armTimer(_, _, _))
116 .WillByDefault(SaveArg<2>(&savedCb));
117 timer->arm(duration, nop);
119 EXPECT_FALSE(timer->isArmed());
122 TEST_F(TimerTest, ArmingNullCallbackCallsSHAREDDATALAYER_ABORT)
124 EXPECT_EXIT(timer->arm(duration, Timer::Callback()),
125 KilledBySignal(SIGABRT), "timer\\.cpp");