Skip to content
This repository has been archived by the owner on Feb 25, 2025. It is now read-only.

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-simmons committed Apr 2, 2024
1 parent 8d3530e commit 7fab718
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions impeller/toolkit/android/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,6 @@ executable("unittests") {
":unittests_fixtures",
"//flutter/testing",
]

defines = [ "TESTING" ]
}
5 changes: 5 additions & 0 deletions impeller/toolkit/android/proc_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ const ProcTable& GetProcTable() {
return gProcTable;
}

// Only used by tests.
ProcTable& GetMutableProcTable() {
return const_cast<ProcTable&>(GetProcTable());
}

template <class T>
void ResolveAndroidProc(
AndroidProc<T>& proc,
Expand Down
4 changes: 4 additions & 0 deletions impeller/toolkit/android/proc_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ struct ProcTable {

const ProcTable& GetProcTable();

#ifdef TESTING
ProcTable& GetMutableProcTable();
#endif

} // namespace impeller::android

#endif // FLUTTER_IMPELLER_TOOLKIT_ANDROID_PROC_TABLE_H_
17 changes: 17 additions & 0 deletions impeller/toolkit/android/toolkit_android_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ class ToolkitAndroidTest : public ::testing::Test {
}
};

#define DISABLE_ANDROID_PROC(name) \
struct Disable##name { \
Disable##name() { \
real_proc = GetMutableProcTable().name.proc; \
GetMutableProcTable().name.proc = nullptr; \
} \
~Disable##name() { \
GetMutableProcTable().name.proc = real_proc; \
} \
decltype(name)* real_proc; \
} disable##name;

TEST_F(ToolkitAndroidTest, CanCreateProcTable) {
ProcTable proc_table;
ASSERT_TRUE(proc_table.IsValid());
Expand Down Expand Up @@ -55,6 +67,11 @@ TEST_F(ToolkitAndroidTest, CanGetHardwareBufferIDs) {
ASSERT_TRUE(buffer.GetSystemUniqueID().has_value());
}

TEST_F(ToolkitAndroidTest, HardwareBufferNullIDIfAPIUnavailable) {
DISABLE_ANDROID_PROC(AHardwareBuffer_getId);
ASSERT_FALSE(HardwareBuffer::GetSystemUniqueID(nullptr).has_value());
}

TEST_F(ToolkitAndroidTest, CanDescribeHardwareBufferHandles) {
ASSERT_TRUE(HardwareBuffer::IsAvailableOnPlatform());
auto desc = HardwareBufferDescriptor::MakeForSwapchainImage({100, 100});
Expand Down

0 comments on commit 7fab718

Please sign in to comment.