1 // Copyright (C) 2019 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "icing/testing/fake-clock.h"
16
17 #include "gmock/gmock.h"
18 #include "gtest/gtest.h"
19
20 namespace icing {
21 namespace lib {
22
23 namespace {
24
25 using ::testing::Eq;
26
TEST(FakeClockTest,GetSetSystemTimeOk)27 TEST(FakeClockTest, GetSetSystemTimeOk) {
28 FakeClock fake_clock;
29 EXPECT_THAT(fake_clock.GetSystemTimeMilliseconds(), Eq(0));
30
31 fake_clock.SetSystemTimeMilliseconds(10);
32 EXPECT_THAT(fake_clock.GetSystemTimeMilliseconds(), Eq(10));
33
34 fake_clock.SetSystemTimeMilliseconds(-1);
35 EXPECT_THAT(fake_clock.GetSystemTimeMilliseconds(), Eq(-1));
36 }
37
TEST(FakeClockTest,GetSetTimerElapsedTimeOk)38 TEST(FakeClockTest, GetSetTimerElapsedTimeOk) {
39 FakeClock fake_clock;
40 EXPECT_THAT(fake_clock.GetNewTimer()->GetElapsedMilliseconds(), Eq(0));
41
42 fake_clock.SetTimerElapsedMilliseconds(10);
43 EXPECT_THAT(fake_clock.GetNewTimer()->GetElapsedMilliseconds(), Eq(10));
44
45 fake_clock.SetTimerElapsedMilliseconds(-1);
46 EXPECT_THAT(fake_clock.GetNewTimer()->GetElapsedMilliseconds(), Eq(-1));
47 }
48
49 } // namespace
50
51 } // namespace lib
52 } // namespace icing
53