From 7fab7185cb4c01147305b4dbbef0b7be1f4997dd Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Tue, 2 Apr 2024 17:31:11 +0000 Subject: [PATCH] test --- impeller/toolkit/android/BUILD.gn | 2 ++ impeller/toolkit/android/proc_table.cc | 5 +++++ impeller/toolkit/android/proc_table.h | 4 ++++ .../android/toolkit_android_unittests.cc | 17 +++++++++++++++++ 4 files changed, 28 insertions(+) diff --git a/impeller/toolkit/android/BUILD.gn b/impeller/toolkit/android/BUILD.gn index fd0dde36bd9bf..fc30a7d0f1cc2 100644 --- a/impeller/toolkit/android/BUILD.gn +++ b/impeller/toolkit/android/BUILD.gn @@ -51,4 +51,6 @@ executable("unittests") { ":unittests_fixtures", "//flutter/testing", ] + + defines = [ "TESTING" ] } diff --git a/impeller/toolkit/android/proc_table.cc b/impeller/toolkit/android/proc_table.cc index 71e6ce5c4d14d..24f9f99008a3d 100644 --- a/impeller/toolkit/android/proc_table.cc +++ b/impeller/toolkit/android/proc_table.cc @@ -14,6 +14,11 @@ const ProcTable& GetProcTable() { return gProcTable; } +// Only used by tests. +ProcTable& GetMutableProcTable() { + return const_cast(GetProcTable()); +} + template void ResolveAndroidProc( AndroidProc& proc, diff --git a/impeller/toolkit/android/proc_table.h b/impeller/toolkit/android/proc_table.h index 83b38a1293c79..af398fd396bf9 100644 --- a/impeller/toolkit/android/proc_table.h +++ b/impeller/toolkit/android/proc_table.h @@ -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_ diff --git a/impeller/toolkit/android/toolkit_android_unittests.cc b/impeller/toolkit/android/toolkit_android_unittests.cc index ff3a7df9daae2..05807ddc1fcc7 100644 --- a/impeller/toolkit/android/toolkit_android_unittests.cc +++ b/impeller/toolkit/android/toolkit_android_unittests.cc @@ -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()); @@ -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});