1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include <gtest/gtest.h> 17 #include <sys/mman.h> 18 19 #include "ohos_adapter_helper.h" 20 21 #define private public 22 #include "ohos_drawing_text_adapter_impl.h" 23 #include "ohos_drawing_text_adapter.h" 24 25 using namespace testing; 26 using namespace testing::ext; 27 28 namespace OHOS { 29 namespace NWeb { 30 namespace { 31 const int NWEB_ERROR = -1; 32 const int RESULT_OK = 0; 33 } 34 35 class DrawingTextAdapterImplTest : public testing::Test { 36 public: 37 static void SetUpTestCase(); 38 static void TearDownTestCase(); 39 void SetUp(); 40 void TearDown(); 41 }; 42 SetUpTestCase()43 void DrawingTextAdapterImplTest::SetUpTestCase() {} 44 TearDownTestCase()45 void DrawingTextAdapterImplTest::TearDownTestCase() {} 46 SetUp()47 void DrawingTextAdapterImplTest::SetUp() {} 48 TearDown()49 void DrawingTextAdapterImplTest::TearDown() {} 50 51 /** 52 * @tc.name: DrawingTextAdapterImplTest_001. 53 * @tc.desc: test DrawingTextFontAdapterImpl GetSystemFontFullNamesByType. 54 * @tc.type: FUNC. 55 * @tc.require: 56 */ 57 HWTEST_F(DrawingTextAdapterImplTest, DrawingTextAdapterImplTest_001, TestSize.Level1) 58 { 59 std::shared_ptr<OhosDrawingTextFontAdapterImpl> drawingTextFontAdapter = 60 std::make_shared<OhosDrawingTextFontAdapterImpl>(); 61 EXPECT_TRUE(drawingTextFontAdapter != nullptr); 62 63 ArkWeb_Drawing_SystemFontType systemFontType = ArkWeb_Drawing_SystemFontType::ALL; 64 void* drawingArray = nullptr; 65 int32_t errorCode = drawingTextFontAdapter->GetSystemFontFullNamesByType(systemFontType, &drawingArray); 66 EXPECT_EQ(errorCode, RESULT_OK); 67 EXPECT_NE(drawingArray, nullptr); 68 69 systemFontType = ArkWeb_Drawing_SystemFontType::GENERIC; 70 errorCode = drawingTextFontAdapter->GetSystemFontFullNamesByType(systemFontType, &drawingArray); 71 EXPECT_EQ(errorCode, RESULT_OK); 72 } 73 74 /** 75 * @tc.name: DrawingTextAdapterImplTest_002. 76 * @tc.desc: test DrawingTextFontAdapterImpl GetFontDescriptorByFullName. 77 * @tc.type: FUNC. 78 * @tc.require: 79 */ 80 HWTEST_F(DrawingTextAdapterImplTest, DrawingTextAdapterImplTest_002, TestSize.Level1) 81 { 82 std::shared_ptr<OhosDrawingTextFontAdapterImpl> drawingTextFontAdapter = 83 std::make_shared<OhosDrawingTextFontAdapterImpl>(); 84 EXPECT_TRUE(drawingTextFontAdapter != nullptr); 85 86 void* drawingString = nullptr; 87 ArkWeb_Drawing_SystemFontType systemFontType = ArkWeb_Drawing_SystemFontType::GENERIC; 88 void* drawingFontDescriptor = nullptr; 89 int32_t errorCode = drawingTextFontAdapter->GetFontDescriptorByFullName( 90 drawingString, systemFontType, &drawingFontDescriptor); 91 92 EXPECT_EQ(errorCode, NWEB_ERROR); 93 EXPECT_EQ(drawingFontDescriptor, nullptr); 94 } 95 96 /** 97 * @tc.name: DrawingTextAdapterImplTest_003. 98 * @tc.desc: test DrawingTextFontAdapterImpl GetSystemFontFullNameByIndex. 99 * @tc.type: FUNC. 100 * @tc.require: 101 */ 102 HWTEST_F(DrawingTextAdapterImplTest, DrawingTextAdapterImplTest_003, TestSize.Level1) 103 { 104 std::shared_ptr<OhosDrawingTextFontAdapterImpl> drawingTextFontAdapter = 105 std::make_shared<OhosDrawingTextFontAdapterImpl>(); 106 EXPECT_TRUE(drawingTextFontAdapter != nullptr); 107 108 void* drawingArray = nullptr; 109 int32_t indexOfFullName = 0; 110 const void* drawingString = nullptr; 111 int32_t errorCode = drawingTextFontAdapter->GetSystemFontFullNameByIndex( 112 drawingArray, indexOfFullName, &drawingString); 113 114 EXPECT_EQ(errorCode, NWEB_ERROR); 115 EXPECT_EQ(drawingArray, nullptr); 116 } 117 118 /** 119 * @tc.name: DrawingTextAdapterImplTest_004. 120 * @tc.desc: test DrawingTextFontAdapterImpl DestroySystemFontFullNames. 121 * @tc.type: FUNC. 122 * @tc.require: 123 */ 124 HWTEST_F(DrawingTextAdapterImplTest, DrawingTextAdapterImplTest_004, TestSize.Level1) 125 { 126 std::shared_ptr<OhosDrawingTextFontAdapterImpl> drawingTextFontAdapter = 127 std::make_shared<OhosDrawingTextFontAdapterImpl>(); 128 EXPECT_TRUE(drawingTextFontAdapter != nullptr); 129 130 void* drawingArray = nullptr; 131 drawingTextFontAdapter->DestroySystemFontFullNames(drawingArray); 132 133 EXPECT_EQ(drawingArray, nullptr); 134 } 135 136 /** 137 * @tc.name: DrawingTextAdapterImplTest_005. 138 * @tc.desc: test OhosDrawingTextTypographyAdapterImpl GetSystemFontConfigInfo. 139 * @tc.type: FUNC. 140 * @tc.require: 141 */ 142 HWTEST_F(DrawingTextAdapterImplTest, DrawingTextAdapterImplTest_005, TestSize.Level1) 143 { 144 std::shared_ptr<OhosDrawingTextTypographyAdapterImpl> drawingTextTypographyAdapter = 145 std::make_shared<OhosDrawingTextTypographyAdapterImpl>(); 146 EXPECT_TRUE(drawingTextTypographyAdapter != nullptr); 147 148 void* fontConfigInfoErrorCode = nullptr; 149 void* fontConfigInfo = nullptr; 150 int32_t errorCode = drawingTextTypographyAdapter->GetSystemFontConfigInfo(fontConfigInfoErrorCode, 151 &fontConfigInfo); 152 153 EXPECT_EQ(errorCode, RESULT_OK); 154 EXPECT_NE(fontConfigInfo, nullptr); 155 } 156 157 /** 158 * @tc.name: DrawingTextAdapterImplTest_006. 159 * @tc.desc: test OhosDrawingTextTypographyAdapterImpl GetDrawingArraySize. 160 * @tc.type: FUNC. 161 * @tc.require: 162 */ 163 HWTEST_F(DrawingTextAdapterImplTest, DrawingTextAdapterImplTest_006, TestSize.Level1) 164 { 165 std::shared_ptr<OhosDrawingTextTypographyAdapterImpl> drawingTextTypographyAdapter = 166 std::make_shared<OhosDrawingTextTypographyAdapterImpl>(); 167 EXPECT_TRUE(drawingTextTypographyAdapter != nullptr); 168 169 void* drawingArray = nullptr; 170 int32_t sizeOfArray = 0; 171 int32_t errorCode = drawingTextTypographyAdapter->GetDrawingArraySize(drawingArray, sizeOfArray); 172 173 EXPECT_EQ(errorCode, RESULT_OK); 174 EXPECT_NE(sizeOfArray, NWEB_ERROR); 175 } 176 177 /** 178 * @tc.name: DrawingTextAdapterImplTest_007. 179 * @tc.desc: test OhosDrawingTextTypographyAdapterImpl DestroySystemFontConfigInfo. 180 * @tc.type: FUNC. 181 * @tc.require: 182 */ 183 HWTEST_F(DrawingTextAdapterImplTest, DrawingTextAdapterImplTest_007, TestSize.Level1) 184 { 185 std::shared_ptr<OhosDrawingTextTypographyAdapterImpl> drawingTextTypographyAdapter = 186 std::make_shared<OhosDrawingTextTypographyAdapterImpl>(); 187 EXPECT_TRUE(drawingTextTypographyAdapter != nullptr); 188 189 void* fontConfigInfo = nullptr; 190 drawingTextTypographyAdapter->DestroySystemFontConfigInfo(fontConfigInfo); 191 192 EXPECT_EQ(fontConfigInfo, nullptr); 193 } 194 195 /** 196 * @tc.name: DrawingTextAdapterImplTest_008. 197 * @tc.desc: test OhosDrawingTextTypographyAdapterImpl DestroySystemFontDescriptor. 198 * @tc.type: FUNC. 199 * @tc.require: 200 */ 201 HWTEST_F(DrawingTextAdapterImplTest, DrawingTextAdapterImplTest_008, TestSize.Level1) 202 { 203 std::shared_ptr<OhosDrawingTextFontAdapterImpl> drawingTextFontAdapter = 204 std::make_shared<OhosDrawingTextFontAdapterImpl>(); 205 EXPECT_TRUE(drawingTextFontAdapter != nullptr); 206 207 void* drawingString = nullptr; 208 ArkWeb_Drawing_SystemFontType systemFontType = ArkWeb_Drawing_SystemFontType::GENERIC; 209 void* drawingFontDescriptor = nullptr; 210 int32_t errorCode = drawingTextFontAdapter->GetFontDescriptorByFullName( 211 drawingString, systemFontType, &drawingFontDescriptor); 212 213 EXPECT_EQ(errorCode, NWEB_ERROR); 214 drawingTextFontAdapter->DestroyFontDescriptor(drawingFontDescriptor); 215 drawingFontDescriptor = nullptr; 216 } 217 218 /** 219 * @tc.name : DrawingTextAdapterImplTest_009 220 * @tc.number: Test GetSystemFontFullNamesByType function when drawingArray is nullptr 221 * @tc.desc : FUNC. 222 */ 223 HWTEST_F(DrawingTextAdapterImplTest, DrawingTextAdapterImplTest_009, TestSize.Level1) 224 { 225 std::shared_ptr<OhosDrawingTextFontAdapterImpl> drawingTextFontAdapter = 226 std::make_shared<OhosDrawingTextFontAdapterImpl>(); 227 int32_t systemFontType = -1; 228 void* drawingArray = nullptr; 229 EXPECT_EQ(-1, drawingTextFontAdapter->GetSystemFontFullNamesByType(systemFontType, &drawingArray)); 230 } 231 232 /** 233 * @tc.name : DrawingTextAdapterImplTest_010 234 * @tc.number: Test if GetInstance() returns the same instance when called multiple times. 235 * @tc.desc : FUNC 236 */ 237 HWTEST_F(DrawingTextAdapterImplTest, DrawingTextAdapterImplTest_010, TestSize.Level1) 238 { 239 std::shared_ptr<OhosDrawingTextFontAdapterImpl> drawingTextFontAdapter = 240 std::make_shared<OhosDrawingTextFontAdapterImpl>(); 241 auto& instance1 = drawingTextFontAdapter->GetInstance(); 242 auto& instance2 = drawingTextFontAdapter->GetInstance(); 243 EXPECT_EQ(&instance1, &instance2); 244 } 245 246 /** 247 * @tc.name : DrawingTextAdapterImplTest_011 248 * @tc.number: Test GetInstance function to ensure it returns the same instance on multiple calls 249 * @tc.desc : FUNC 250 */ 251 HWTEST_F(DrawingTextAdapterImplTest, DrawingTextAdapterImplTest_011, TestSize.Level1) 252 { 253 std::shared_ptr<OhosDrawingTextTypographyAdapterImpl> drawingTextFontAdapter = 254 std::make_shared<OhosDrawingTextTypographyAdapterImpl>(); 255 // Call GetInstance multiple times and check if the returned instances are the same 256 auto& instance1 = drawingTextFontAdapter->GetInstance(); 257 auto& instance2 = drawingTextFontAdapter->GetInstance(); 258 EXPECT_EQ(&instance1, &instance2); 259 } 260 } // namespace NWeb 261 } // namespace OHOS