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.
17 #include <type_traits>
19 #include <gmock/gmock.h>
20 #include "private/timer.hpp"
21 #include "private/tst/enginemock.hpp"
23 using namespace shareddatalayer;
24 using namespace shareddatalayer::tst;
25 using namespace testing;
29 class TimerTest: public testing::Test
32 NiceMock<EngineMock> engineMock;
33 const Timer::Duration duration;
34 std::unique_ptr<Timer> timer;
37 duration(std::chrono::duration_cast<Timer::Duration>(std::chrono::seconds(12))),
38 timer(new Timer(engineMock))
46 TEST_F(TimerTest, IsNotCopyableAndIsNotMovable)
48 EXPECT_FALSE(std::is_copy_assignable<Timer>::value);
49 EXPECT_FALSE(std::is_move_assignable<Timer>::value);
50 EXPECT_FALSE(std::is_copy_constructible<Timer>::value);
51 EXPECT_FALSE(std::is_move_constructible<Timer>::value);
54 TEST_F(TimerTest, ArmCallsArmOfAssociatedTimerService)
56 EXPECT_CALL(engineMock, armTimer(_, duration, _))
58 timer->arm(duration, nop);
61 TEST_F(TimerTest, DisarmingCallsDisarmOfAssociatedTimerService)
63 timer->arm(duration, nop);
64 EXPECT_CALL(engineMock, disarmTimer(_))
69 TEST_F(TimerTest, DisarmingUnArmedTimerDoesNothing)
71 EXPECT_CALL(engineMock, disarmTimer(_))
76 TEST_F(TimerTest, DoubleDisarmingDoesNothing)
78 timer->arm(duration, nop);
79 EXPECT_CALL(engineMock, disarmTimer(_))
85 TEST_F(TimerTest, DoubleArmingDisarmsFirst)
88 EXPECT_CALL(engineMock, armTimer(_, duration, _))
90 timer->arm(duration, nop);
91 EXPECT_CALL(engineMock, disarmTimer(_))
93 EXPECT_CALL(engineMock, armTimer(_, duration, _))
95 timer->arm(duration, nop);
96 Mock::VerifyAndClear(&engineMock);
99 TEST_F(TimerTest, DestructorDisarms)
101 timer->arm(duration, nop);
102 EXPECT_CALL(engineMock, disarmTimer(_))
107 TEST_F(TimerTest, AfterTimerHasExpiredItIsNotArmedAnymore)
109 Timer::Callback savedCb;
110 ON_CALL(engineMock, armTimer(_, _, _))
111 .WillByDefault(SaveArg<2>(&savedCb));
112 timer->arm(duration, nop);
114 EXPECT_FALSE(timer->isArmed());
117 TEST_F(TimerTest, ArmingNullCallbackCallsSHAREDDATALAYER_ABORT)
119 EXPECT_EXIT(timer->arm(duration, Timer::Callback()),
120 KilledBySignal(SIGABRT), "timer\\.cpp");