1 /*
2 * Copyright 2021 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 <ui/MockFence.h>
18
19 #include <gtest/gtest.h>
20
21 namespace android::ui {
22
23 using testing::Return;
24
25 class MockFenceTest : public testing::Test {
26 public:
getFenceForTesting() const27 sp<Fence> getFenceForTesting() const { return mMockFence; }
28
getMockFence() const29 const mock::MockFence& getMockFence() const { return *mMockFence; }
30
31 private:
32 sp<mock::MockFence> mMockFence = sp<mock::MockFence>::make();
33 };
34
TEST_F(MockFenceTest,getSignalTime)35 TEST_F(MockFenceTest, getSignalTime) {
36 sp<Fence> fence = getFenceForTesting();
37
38 EXPECT_CALL(getMockFence(), getSignalTime).WillOnce(Return(Fence::SIGNAL_TIME_PENDING));
39 EXPECT_EQ(Fence::SIGNAL_TIME_PENDING, fence->getSignalTime());
40
41 EXPECT_CALL(getMockFence(), getSignalTime).WillOnce(Return(1234));
42 EXPECT_EQ(1234, fence->getSignalTime());
43 }
44
TEST_F(MockFenceTest,getStatus)45 TEST_F(MockFenceTest, getStatus) {
46 sp<Fence> fence = getFenceForTesting();
47
48 EXPECT_CALL(getMockFence(), getStatus).WillOnce(Return(Fence::Status::Unsignaled));
49 EXPECT_EQ(Fence::Status::Unsignaled, fence->getStatus());
50
51 EXPECT_CALL(getMockFence(), getStatus).WillOnce(Return(Fence::Status::Signaled));
52 EXPECT_EQ(Fence::Status::Signaled, fence->getStatus());
53
54 EXPECT_CALL(getMockFence(), getStatus).WillOnce(Return(Fence::Status::Invalid));
55 EXPECT_EQ(Fence::Status::Invalid, fence->getStatus());
56 }
57 } // namespace android::ui
58