From 4e072343ed8c79e10fc55dffe6ac9097ba63ff49 Mon Sep 17 00:00:00 2001 From: changleipeng Date: Mon, 21 Oct 2024 17:18:57 +0800 Subject: [PATCH] test Signed-off-by: changleipeng --- BUILD.gn | 6 + shell/platform/ohos/BUILD.gn | 16 +++ .../ohos_assert_provider_unittests.cpp | 34 +++++ .../ohos_context_gl_skia_uinttests.cpp | 105 ++++++++++++++++ .../ohos/testing/ohos_display_uinttests.cpp | 34 +++++ .../testing/ohos_egl_surface_unittests.cpp | 116 ++++++++++++++++++ .../testing/ohos_environment_gl_unittests.cpp | 32 +++++ .../ohos_external_texture_gl_unittests.cpp | 60 +++++++++ 8 files changed, 403 insertions(+) create mode 100644 shell/platform/ohos/testing/ohos_assert_provider_unittests.cpp create mode 100644 shell/platform/ohos/testing/ohos_context_gl_skia_uinttests.cpp create mode 100644 shell/platform/ohos/testing/ohos_display_uinttests.cpp create mode 100644 shell/platform/ohos/testing/ohos_egl_surface_unittests.cpp create mode 100644 shell/platform/ohos/testing/ohos_environment_gl_unittests.cpp create mode 100644 shell/platform/ohos/testing/ohos_external_texture_gl_unittests.cpp diff --git a/BUILD.gn b/BUILD.gn index 7a102d594b..773b42acf8 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -162,6 +162,12 @@ group("unittests") { "//flutter/third_party/txt:txt_unittests", ] + if (is_ohos) { + public_deps += [ + "//flutter/shell/platform/ohos:flutter_ohos_unittests", + ] + } + # The accessibility library only supports Mac and Windows at the moment. if (is_mac || is_win) { public_deps += diff --git a/shell/platform/ohos/BUILD.gn b/shell/platform/ohos/BUILD.gn index c8e36f5796..5b3345eb2c 100644 --- a/shell/platform/ohos/BUILD.gn +++ b/shell/platform/ohos/BUILD.gn @@ -176,10 +176,17 @@ executable("flutter_ohos_unittests") { sources = [ #"testing/mock_texture_registrar.cc", + "testing/ohos_assert_provider_unittests.cpp", + "testing/ohos_context_gl_skia_uinttests.cpp", + "testing/ohos_display_uinttests.cpp", + "testing/ohos_egl_surface_unittests.cpp", + "testing/ohos_environment_gl_unittests.cpp", + "testing/ohos_external_texture_gl_unittests.cpp", ] public_configs = [ "//flutter:config" ] + cflags = ["-Wno-deprecated-declarations"] defines = [ "FLUTTER_ENGINE_NO_PROTOTYPES", @@ -197,6 +204,15 @@ executable("flutter_ohos_unittests") { "//flutter/shell/platform/embedder:embedder_test_utils", "//flutter/testing", ] + + ldflags = ["-lace_ndk.z"] + ldflags += ["-lnative_window"] + ldflags += ["-lnative_vsync"] + ldflags += ["-limage_ndk.z"] + ldflags += ["-lrawfile.z"] + ldflags += ["-lnative_image"] + ldflags += ["-lpixelmap_ndk.z"] + ldflags += ["-lqos"] } shared_library("flutter_shell_native") { diff --git a/shell/platform/ohos/testing/ohos_assert_provider_unittests.cpp b/shell/platform/ohos/testing/ohos_assert_provider_unittests.cpp new file mode 100644 index 0000000000..c9a810e5da --- /dev/null +++ b/shell/platform/ohos/testing/ohos_assert_provider_unittests.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +#include +#include + +#include "flutter/shell/platform/ohos/ohos_asset_provider.h" +#include "gtest/gtest.h" + +namespace flutter { +namespace testing { +TEST(OHOSAssetProviderTest, Create001) +{ + std::shared_ptr provider = std::make_shared(nullptr); + EXPECT_TRUE(provider.get() != nullptr); + std::unique_ptr newProvider = provider->Clone(); + EXPECT_TRUE(newProvider.get() != nullptr); +} +} +} \ No newline at end of file diff --git a/shell/platform/ohos/testing/ohos_context_gl_skia_uinttests.cpp b/shell/platform/ohos/testing/ohos_context_gl_skia_uinttests.cpp new file mode 100644 index 0000000000..c6c129c0a3 --- /dev/null +++ b/shell/platform/ohos/testing/ohos_context_gl_skia_uinttests.cpp @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +#include + +#include "flutter/common/task_runners.h" +#include "flutter/shell/common/thread_host.h" +#include "flutter/shell/platform/ohos/ohos_context_gl_skia.h" +#include "flutter/shell/platform/ohos/ohos_egl_surface.h" +#include "flutter/shell/platform/ohos/surface/ohos_native_window.h" +#include "gtest/gtest.h" + +namespace flutter { +namespace testing { +namespace { +TaskRunners MakeTaskRunners(const std::string& threadLabel) +{ + fml::MessageLoop::EnsureInitializedForCurrentThread(); + auto& loop = fml::MessageLoop::GetCurrent(); + return { + threadLabel, + loop.GetTaskRunner(), // platform + loop.GetTaskRunner(), // raster + loop.GetTaskRunner(), // ui + loop.GetTaskRunner() // io + }; +} + +std::unique_ptr CreateOhosContext() +{ + auto environment = fml::MakeRefCounted(); + std::string threadLabel = ::testing::UnitTest::GetInstance()->current_test_info()->name(); + TaskRunners taskRunners = MakeTaskRunners(threadLabel); + return std::make_unique(OHOSRenderingAPI::kOpenGLES, environment, taskRunners, 0); +} +} // namespace +TEST(OHOSContextGlSkiaTest, CreateOnscreenSurface) +{ + std::unique_ptr context = CreateOhosContext(); + EXPECT_TRUE(context.get() != nullptr); + + auto window = fml::MakeRefCounted(nullptr); + std::unique_ptr surface = context->CreateOnscreenSurface(window); + EXPECT_TRUE(surface.get() != nullptr); +} + +TEST(OHOSContextGlSkiaTest, CreateOffscreenSurface) +{ + std::unique_ptr context = CreateOhosContext(); + EXPECT_TRUE(context.get() != nullptr); + + std::unique_ptr surface = context->CreateOffscreenSurface(); + EXPECT_TRUE(surface->IsValid()); +} + +TEST(OHOSContextGlSkiaTest, CreatePbufferSurface) +{ + std::unique_ptr context = CreateOhosContext(); + EXPECT_TRUE(context.get() != nullptr); + + std::unique_ptr surface = context->CreatePbufferSurface(); + EXPECT_TRUE(surface->IsValid()); +} + +TEST(OHOSContextGlSkiaTest, Environment) +{ + std::unique_ptr context = CreateOhosContext(); + EXPECT_TRUE(context.get() != nullptr); + + fml::RefPtr environment = context->Environment(); + EXPECT_TRUE(environment.get() != nullptr); +} + +TEST(OHOSContextGlSkiaTest, ClearCurrent) +{ + std::unique_ptr context = CreateOhosContext(); + EXPECT_TRUE(context.get() != nullptr); + EXPECT_TRUE(context->ClearCurrent()); +} + +TEST(OHOSContextGlSkiaTest, CreateNewContext) +{ + std::unique_ptr context = CreateOhosContext(); + EXPECT_TRUE(context.get() != nullptr); + + EGLContext newContext = context->CreateNewContext(); + EXPECT_TRUE(newContext != EGL_NO_CONTEXT); +} +} +} + diff --git a/shell/platform/ohos/testing/ohos_display_uinttests.cpp b/shell/platform/ohos/testing/ohos_display_uinttests.cpp new file mode 100644 index 0000000000..78bd056765 --- /dev/null +++ b/shell/platform/ohos/testing/ohos_display_uinttests.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +#include + +#include "flutter/shell/platform/ohos/ohos_display.h" +#include "gtest/gtest.h" + +namespace flutter { +namespace testing { + +const double DEFAULT_FPS = 60; +TEST(OHOSDisplayTest, GetRefreshRate) +{ + std::shared_ptr display = std::make_shared(nullptr); + EXPECT_TRUE(display.get() != nullptr); + EXPECT_EQ(display->GetRefreshRate(), DEFAULT_FPS); +} +} +} \ No newline at end of file diff --git a/shell/platform/ohos/testing/ohos_egl_surface_unittests.cpp b/shell/platform/ohos/testing/ohos_egl_surface_unittests.cpp new file mode 100644 index 0000000000..62980266b0 --- /dev/null +++ b/shell/platform/ohos/testing/ohos_egl_surface_unittests.cpp @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +#include + +#include "flutter/common/task_runners.h" +#include "flutter/shell/common/thread_host.h" +#include "flutter/shell/platform/ohos/ohos_context_gl_skia.h" +#include "flutter/shell/platform/ohos/ohos_egl_surface.h" +#include "gtest/gtest.h" + +namespace flutter { +namespace testing { +namespace { +TaskRunners MakeTaskRunners(const std::string& threadLabel) +{ + fml::MessageLoop::EnsureInitializedForCurrentThread(); + auto& loop = fml::MessageLoop::GetCurrent(); + return { + threadLabel, + loop.GetTaskRunner(), // platform + loop.GetTaskRunner(), // raster + loop.GetTaskRunner(), // ui + loop.GetTaskRunner() // io + }; +} + +std::unique_ptr CreateOhosContext() +{ + fml::RefPtr environment = fml::MakeRefCounted(); + std::string threadLabel = ::testing::UnitTest::GetInstance()->current_test_info()->name(); + TaskRunners taskRunners = MakeTaskRunners(threadLabel); + return std::make_unique(OHOSRenderingAPI::kOpenGLES, environment, taskRunners, 0); +} +} // namespace + +TEST(OHOSEGLSurfaceTest, MakeCurrent) +{ + std::unique_ptr context = CreateOhosContext(); + EXPECT_TRUE(context.get() != nullptr); + + std::unique_ptr surface = context->CreateOffscreenSurface(); + EXPECT_TRUE(surface->IsValid()); + + OhosEGLSurfaceMakeCurrentStatus status = surface->MakeCurrent(); + EXPECT_EQ(status, OhosEGLSurfaceMakeCurrentStatus::kSuccessMadeCurrent); +} + +TEST(OHOSEGLSurfaceTest, SupportsPartialRepaint) +{ + std::unique_ptr context = CreateOhosContext(); + EXPECT_TRUE(context.get() != nullptr); + + std::unique_ptr surface = context->CreateOffscreenSurface(); + EXPECT_TRUE(surface->IsValid()); + + bool res = surface->SupportsPartialRepaint(); + EXPECT_EQ(res, false); +} + +TEST(OHOSEGLSurfaceTest, InitialDamage) +{ + std::unique_ptr context = CreateOhosContext(); + EXPECT_TRUE(context.get() != nullptr); + + std::unique_ptr surface = context->CreateOffscreenSurface(); + EXPECT_TRUE(surface->IsValid()); + + std::optional rect = surface->InitialDamage(); + EXPECT_EQ(rect.has_value(), false); +} + +TEST(OHOSEGLSurfaceTest, SetDamageRegion) +{ + std::unique_ptr context = CreateOhosContext(); + EXPECT_TRUE(context.get() != nullptr); + + std::unique_ptr surface = context->CreateOffscreenSurface(); + EXPECT_TRUE(surface->IsValid()); + + std::optional rect(SkIRect::MakeEmpty()); + surface->SetDamageRegion(rect); + EXPECT_EQ(rect.has_value(), true); + SkISize size = surface->GetSize(); + EXPECT_TRUE(size.width() != 0); + EXPECT_TRUE(size.height() != 0); +} + +TEST(OHOSEGLSurfaceTest, SetPresentationTime) +{ + std::unique_ptr context = CreateOhosContext(); + EXPECT_TRUE(context.get() != nullptr); + + std::unique_ptr surface = context->CreateOffscreenSurface(); + EXPECT_TRUE(surface->IsValid()); + + fml::TimePoint timePoint = fml::TimePoint::CurrentWallTime(); + bool res = surface->SetPresentationTime(timePoint); + EXPECT_EQ(res, false); +} +} +} \ No newline at end of file diff --git a/shell/platform/ohos/testing/ohos_environment_gl_unittests.cpp b/shell/platform/ohos/testing/ohos_environment_gl_unittests.cpp new file mode 100644 index 0000000000..096ae8bfe5 --- /dev/null +++ b/shell/platform/ohos/testing/ohos_environment_gl_unittests.cpp @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +#include + +#include "flutter/shell/platform/ohos/ohos_environment_gl.h" +#include "gtest/gtest.h" + +namespace flutter { +namespace testing { + +TEST(OHOSEnvironmentGLTest, Create) +{ + fml::RefPtr environment = fml::MakeRefCounted(); + EXPECT_TRUE(environment->IsValid()); +} +} +} \ No newline at end of file diff --git a/shell/platform/ohos/testing/ohos_external_texture_gl_unittests.cpp b/shell/platform/ohos/testing/ohos_external_texture_gl_unittests.cpp new file mode 100644 index 0000000000..5e1cda2737 --- /dev/null +++ b/shell/platform/ohos/testing/ohos_external_texture_gl_unittests.cpp @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +#include +#include +#include + +#include "flutter/shell/platform/ohos/ohos_external_texture_gl.h" +#include "gtest/gtest.h" + +namespace flutter { +namespace testing { + +namespace { +TaskRunners MakeTaskRunners(const std::string& threadLabel) +{ + fml::MessageLoop::EnsureInitializedForCurrentThread(); + auto& loop = fml::MessageLoop::GetCurrent(); + return { + threadLabel, + loop.GetTaskRunner(), // platform + loop.GetTaskRunner(), // raster + loop.GetTaskRunner(), // ui + loop.GetTaskRunner() // io + }; +} + +std::shared_ptr CreateOhosContext() +{ + fml::RefPtr environment = fml::MakeRefCounted(); + std::string threadLabel = ::testing::UnitTest::GetInstance()->current_test_info()->name(); + TaskRunners taskRunners = MakeTaskRunners(threadLabel); + return std::make_shared(OHOSRenderingAPI::kOpenGLES, environment, taskRunners, 0); +} +} // namespace + +TEST(OHOSExternalTextureGLTest, OnTextureUnregistered) +{ + std::shared_ptr context = CreateOhosContext(); + EXPECT_TRUE(context.get() != nullptr); + std::shared_ptr surfaceSkia = std::make_shared(context); + std::shared_ptr extTexture = std::make_shared(0, surfaceSkia); + + extTexture->OnTextureUnregistered(); + EXPECT_TRUE(extTexture->first_update_ == false); +} +} +} \ No newline at end of file -- Gitee