1 /* 2 * Copyright 2020 The Android Open Source Project 3 * 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 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 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. 15 */ 16 17 #include "AsyncCallRecorder.h" 18 #include "Scheduler/TimeKeeper.h" 19 #include "Scheduler/Timer.h" 20 21 #include <gmock/gmock.h> 22 #include <gtest/gtest.h> 23 24 using namespace testing; 25 using namespace std::literals; 26 27 namespace android::scheduler { 28 29 struct TimerTest : testing::Test { 30 static constexpr int mIterations = 20; 31 32 AsyncCallRecorder<void (*)()> mCallbackRecorder; 33 Timer mTimer; 34 timerCallbackandroid::scheduler::TimerTest35 void timerCallback() { mCallbackRecorder.recordCall(); } 36 }; 37 TEST_F(TimerTest,callsCallbackIfScheduledInPast)38TEST_F(TimerTest, callsCallbackIfScheduledInPast) { 39 for (int i = 0; i < mIterations; i++) { 40 mTimer.alarmAt(std::bind(&TimerTest::timerCallback, this), systemTime() - 10'000'00); 41 EXPECT_TRUE(mCallbackRecorder.waitForCall().has_value()); 42 EXPECT_FALSE(mCallbackRecorder.waitForUnexpectedCall().has_value()); 43 } 44 } 45 } // namespace android::scheduler 46