|
| 1 | +// Copyright 2021 Samsung Electronics Co., Ltd. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +#include <iostream> |
| 6 | + |
| 7 | +#include "flutter/shell/platform/embedder/test_utils/proc_table_replacement.h" |
| 8 | +#include "flutter/shell/platform/tizen/flutter_tizen_engine.h" |
| 9 | +#include "flutter/shell/platform/tizen/flutter_tizen_texture_registrar.h" |
| 10 | +#include "flutter/shell/platform/tizen/testing/engine_modifier.h" |
| 11 | +#include "gtest/gtest.h" |
| 12 | + |
| 13 | +namespace flutter { |
| 14 | +namespace testing { |
| 15 | + |
| 16 | +namespace { |
| 17 | +std::unique_ptr<FlutterTizenEngine> GetTestEngine() { |
| 18 | + FlutterDesktopEngineProperties engine_prop = {}; |
| 19 | + engine_prop.assets_path = "foo/flutter_assets"; |
| 20 | + engine_prop.icu_data_path = "foo/icudtl.dat"; |
| 21 | + engine_prop.aot_library_path = "foo/libapp.so"; |
| 22 | + FlutterProjectBundle project(engine_prop); |
| 23 | + return std::make_unique<FlutterTizenEngine>(project); |
| 24 | +} |
| 25 | +} // namespace |
| 26 | + |
| 27 | +TEST(FlutterTizenTextureRegistrarTest, CreateDestroy) { |
| 28 | + std::unique_ptr<FlutterTizenEngine> engine = GetTestEngine(); |
| 29 | + |
| 30 | + FlutterTizenTextureRegistrar registrar(engine.get()); |
| 31 | + |
| 32 | + EXPECT_TRUE(true); |
| 33 | +} |
| 34 | + |
| 35 | +TEST(FlutterTizenTextureRegistrarTest, RegisterUnregisterTexture) { |
| 36 | + std::unique_ptr<FlutterTizenEngine> engine = GetTestEngine(); |
| 37 | + EngineModifier modifier(engine.get()); |
| 38 | + |
| 39 | + FlutterTizenTextureRegistrar registrar(engine.get()); |
| 40 | + |
| 41 | + FlutterDesktopTextureInfo texture_info = {}; |
| 42 | + texture_info.type = kFlutterDesktopPixelBufferTexture; |
| 43 | + texture_info.pixel_buffer_config.callback = |
| 44 | + [](size_t width, size_t height, |
| 45 | + void* user_data) -> const FlutterDesktopPixelBuffer* { |
| 46 | + return nullptr; |
| 47 | + }; |
| 48 | + |
| 49 | + int64_t registered_texture_id = 0; |
| 50 | + bool register_called = false; |
| 51 | + modifier.embedder_api().RegisterExternalTexture = MOCK_ENGINE_PROC( |
| 52 | + RegisterExternalTexture, ([®ister_called, ®istered_texture_id]( |
| 53 | + auto engine, auto texture_id) { |
| 54 | + register_called = true; |
| 55 | + registered_texture_id = texture_id; |
| 56 | + return kSuccess; |
| 57 | + })); |
| 58 | + |
| 59 | + bool unregister_called = false; |
| 60 | + modifier.embedder_api().UnregisterExternalTexture = MOCK_ENGINE_PROC( |
| 61 | + UnregisterExternalTexture, ([&unregister_called, ®istered_texture_id]( |
| 62 | + auto engine, auto texture_id) { |
| 63 | + unregister_called = true; |
| 64 | + EXPECT_EQ(registered_texture_id, texture_id); |
| 65 | + return kSuccess; |
| 66 | + })); |
| 67 | + |
| 68 | + bool mark_frame_available_called = false; |
| 69 | + modifier.embedder_api().MarkExternalTextureFrameAvailable = |
| 70 | + MOCK_ENGINE_PROC(MarkExternalTextureFrameAvailable, |
| 71 | + ([&mark_frame_available_called, ®istered_texture_id]( |
| 72 | + auto engine, auto texture_id) { |
| 73 | + mark_frame_available_called = true; |
| 74 | + EXPECT_EQ(registered_texture_id, texture_id); |
| 75 | + return kSuccess; |
| 76 | + })); |
| 77 | + |
| 78 | + auto texture_id = registrar.RegisterTexture(&texture_info); |
| 79 | + EXPECT_TRUE(register_called); |
| 80 | + EXPECT_NE(texture_id, -1); |
| 81 | + EXPECT_EQ(texture_id, registered_texture_id); |
| 82 | + |
| 83 | + EXPECT_TRUE(registrar.MarkTextureFrameAvailable(texture_id)); |
| 84 | + EXPECT_TRUE(mark_frame_available_called); |
| 85 | + |
| 86 | + EXPECT_TRUE(registrar.UnregisterTexture(texture_id)); |
| 87 | + EXPECT_TRUE(unregister_called); |
| 88 | +} |
| 89 | + |
| 90 | +TEST(FlutterTizenTextureRegistrarTest, RegisterUnknownTextureType) { |
| 91 | + std::unique_ptr<FlutterTizenEngine> engine = GetTestEngine(); |
| 92 | + EngineModifier modifier(engine.get()); |
| 93 | + |
| 94 | + FlutterTizenTextureRegistrar registrar(engine.get()); |
| 95 | + |
| 96 | + FlutterDesktopTextureInfo texture_info = {}; |
| 97 | + texture_info.type = static_cast<FlutterDesktopTextureType>(1234); |
| 98 | + |
| 99 | + auto texture_id = registrar.RegisterTexture(&texture_info); |
| 100 | + |
| 101 | + EXPECT_EQ(texture_id, -1); |
| 102 | +} |
| 103 | + |
| 104 | +TEST(FlutterTizenTextureRegistrarTest, PopulateInvalidTexture) { |
| 105 | + std::unique_ptr<FlutterTizenEngine> engine = GetTestEngine(); |
| 106 | + |
| 107 | + FlutterTizenTextureRegistrar registrar(engine.get()); |
| 108 | + |
| 109 | + auto result = registrar.PopulateTexture(1, 640, 480, nullptr); |
| 110 | + EXPECT_FALSE(result); |
| 111 | +} |
| 112 | + |
| 113 | +} // namespace testing |
| 114 | +} // namespace flutter |
0 commit comments