diff --git a/shell/platform/ohos/BUILD.gn b/shell/platform/ohos/BUILD.gn index ff52f307f0de837ef9997842a64af783fd618c66..7131f4c96766b0287ede59ffc2e665accbe0eb0f 100644 --- a/shell/platform/ohos/BUILD.gn +++ b/shell/platform/ohos/BUILD.gn @@ -176,6 +176,12 @@ 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", "testing/ohos_surface_gl_skia_unittests.cpp", "testing/ohos_surface_software_unittests.cpp", "testing/ohos_touch_processor_unittests.cpp", 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 0000000000000000000000000000000000000000..c9a810e5daa0a3a8f43c6007e51e80020f07d87d --- /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 0000000000000000000000000000000000000000..c6c129c0a30876387fa038a0c9ca11c7bfe8109a --- /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 0000000000000000000000000000000000000000..78bd056765e2e4b663f167073fa55b80ed15b530 --- /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 0000000000000000000000000000000000000000..62980266b09e6056113db236ed43044032ea8dec --- /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 0000000000000000000000000000000000000000..096ae8bfe50b41fc77fc1ae73f495af5582e7f06 --- /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 0000000000000000000000000000000000000000..5e1cda2737104ea246098ac915609e6150b7fd16 --- /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