1 // Copyright 2018 The Fuchsia Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include <lib/async/time.h> 6 #include <lib/async-testutils/dispatcher_stub.h> 7 #include <unittest/unittest.h> 8 9 10 namespace { 11 12 class FakeClockAsync : public async::DispatcherStub { 13 public: Now()14 zx::time Now() override { return current_time_; } SetTime(zx::time t)15 void SetTime(zx::time t) { current_time_ = t; } 16 17 private: 18 zx::time current_time_; 19 }; 20 time_telling_test()21bool time_telling_test() { 22 BEGIN_TEST; 23 24 FakeClockAsync dispatcher; 25 EXPECT_EQ(0u, dispatcher.Now().get()); 26 EXPECT_EQ(0u, async_now(&dispatcher)); 27 28 dispatcher.SetTime(zx::time(4u)); 29 EXPECT_EQ(4u, dispatcher.Now().get()); 30 EXPECT_EQ(4u, async_now(&dispatcher)); 31 32 dispatcher.SetTime(zx::time(1853u)); 33 EXPECT_EQ(1853u, dispatcher.Now().get()); 34 EXPECT_EQ(1853u, async_now(&dispatcher)); 35 36 END_TEST; 37 } 38 39 } // namespace 40 41 BEGIN_TEST_CASE(time_tests) 42 RUN_TEST(time_telling_test) 43 END_TEST_CASE(time_tests) 44