|
| 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 | +class FlutterTizenTextureRegistrarTest : public ::testing::Test { |
| 17 | + public: |
| 18 | + FlutterTizenTextureRegistrarTest() { |
| 19 | + ecore_init(); |
| 20 | + elm_init(0, nullptr); |
| 21 | + } |
| 22 | + |
| 23 | + protected: |
| 24 | + void SetUp() { |
| 25 | + FlutterDesktopEngineProperties engine_prop = {}; |
| 26 | + engine_prop.assets_path = "foo/flutter_assets"; |
| 27 | + engine_prop.icu_data_path = "foo/icudtl.dat"; |
| 28 | + engine_prop.aot_library_path = "foo/libapp.so"; |
| 29 | + |
| 30 | + FlutterProjectBundle project(engine_prop); |
| 31 | + auto engine = std::make_unique<FlutterTizenEngine>(project); |
| 32 | + engine_ = engine.release(); |
| 33 | + } |
| 34 | + |
| 35 | + void TearDown() { |
| 36 | + if (engine_) { |
| 37 | + delete engine_; |
| 38 | + } |
| 39 | + engine_ = nullptr; |
| 40 | + } |
| 41 | + |
| 42 | + FlutterTizenEngine* engine_; |
| 43 | +}; |
| 44 | + |
| 45 | +TEST_F(FlutterTizenTextureRegistrarTest, CreateDestroy) { |
| 46 | + FlutterTizenTextureRegistrar registrar(engine_); |
| 47 | + |
| 48 | + EXPECT_TRUE(true); |
| 49 | +} |
| 50 | + |
| 51 | +TEST_F(FlutterTizenTextureRegistrarTest, RegisterUnregisterTexture) { |
| 52 | + EngineModifier modifier(engine_); |
| 53 | + |
| 54 | + FlutterTizenTextureRegistrar registrar(engine_); |
| 55 | + |
| 56 | + FlutterDesktopTextureInfo texture_info = {}; |
| 57 | + texture_info.type = kFlutterDesktopPixelBufferTexture; |
| 58 | + texture_info.pixel_buffer_config.callback = |
| 59 | + [](size_t width, size_t height, |
| 60 | + void* user_data) -> const FlutterDesktopPixelBuffer* { |
| 61 | + return nullptr; |
| 62 | + }; |
| 63 | + |
| 64 | + int64_t registered_texture_id = 0; |
| 65 | + bool register_called = false; |
| 66 | + modifier.embedder_api().RegisterExternalTexture = MOCK_ENGINE_PROC( |
| 67 | + RegisterExternalTexture, ([®ister_called, ®istered_texture_id]( |
| 68 | + auto engine, auto texture_id) { |
| 69 | + register_called = true; |
| 70 | + registered_texture_id = texture_id; |
| 71 | + return kSuccess; |
| 72 | + })); |
| 73 | + |
| 74 | + bool unregister_called = false; |
| 75 | + modifier.embedder_api().UnregisterExternalTexture = MOCK_ENGINE_PROC( |
| 76 | + UnregisterExternalTexture, ([&unregister_called, ®istered_texture_id]( |
| 77 | + auto engine, auto texture_id) { |
| 78 | + unregister_called = true; |
| 79 | + EXPECT_EQ(registered_texture_id, texture_id); |
| 80 | + return kSuccess; |
| 81 | + })); |
| 82 | + |
| 83 | + bool mark_frame_available_called = false; |
| 84 | + modifier.embedder_api().MarkExternalTextureFrameAvailable = |
| 85 | + MOCK_ENGINE_PROC(MarkExternalTextureFrameAvailable, |
| 86 | + ([&mark_frame_available_called, ®istered_texture_id]( |
| 87 | + auto engine, auto texture_id) { |
| 88 | + mark_frame_available_called = true; |
| 89 | + EXPECT_EQ(registered_texture_id, texture_id); |
| 90 | + return kSuccess; |
| 91 | + })); |
| 92 | + |
| 93 | + auto texture_id = registrar.RegisterTexture(&texture_info); |
| 94 | + EXPECT_TRUE(register_called); |
| 95 | + EXPECT_NE(texture_id, -1); |
| 96 | + EXPECT_EQ(texture_id, registered_texture_id); |
| 97 | + |
| 98 | + EXPECT_TRUE(registrar.MarkTextureFrameAvailable(texture_id)); |
| 99 | + EXPECT_TRUE(mark_frame_available_called); |
| 100 | + |
| 101 | + EXPECT_TRUE(registrar.UnregisterTexture(texture_id)); |
| 102 | + EXPECT_TRUE(unregister_called); |
| 103 | +} |
| 104 | + |
| 105 | +TEST_F(FlutterTizenTextureRegistrarTest, RegisterUnknownTextureType) { |
| 106 | + EngineModifier modifier(engine_); |
| 107 | + |
| 108 | + FlutterTizenTextureRegistrar registrar(engine_); |
| 109 | + |
| 110 | + FlutterDesktopTextureInfo texture_info = {}; |
| 111 | + texture_info.type = static_cast<FlutterDesktopTextureType>(1234); |
| 112 | + |
| 113 | + auto texture_id = registrar.RegisterTexture(&texture_info); |
| 114 | + |
| 115 | + EXPECT_EQ(texture_id, -1); |
| 116 | +} |
| 117 | + |
| 118 | +TEST_F(FlutterTizenTextureRegistrarTest, PopulateInvalidTexture) { |
| 119 | + FlutterTizenTextureRegistrar registrar(engine_); |
| 120 | + |
| 121 | + auto result = registrar.PopulateTexture(1, 640, 480, nullptr); |
| 122 | + EXPECT_FALSE(result); |
| 123 | +} |
| 124 | + |
| 125 | +} // namespace testing |
| 126 | +} // namespace flutter |
0 commit comments