1 /* 2 * Copyright (c) 2023 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 18 #include "measurer.h" 19 #include "texgine/font_providers.h" 20 #include "text_converter.h" 21 22 using namespace testing; 23 using namespace testing::ext; 24 25 #ifdef DEBUG_MEASURER_TEST 26 #define DEBUG_LOG() GTEST_LOG_(INFO) 27 #else 28 #define DEBUG_LOG() std::stringstream() 29 #endif 30 31 namespace OHOS { 32 namespace Rosen { 33 namespace TextEngine { 34 namespace { 35 class MeasurerTest : public testing::Test { 36 }; 37 38 /** 39 * @tc.name: Measure 40 * @tc.desc: Verify the Measure 41 * @tc.type FUNC 42 */ 43 HWTEST_F(MeasurerTest, Measure, TestSize.Level1) 44 { 45 auto providers = FontProviders::Create(); 46 auto fc = providers->GenerateFontCollection({}); 47 GTEST_ASSERT_NE(fc, nullptr); 48 49 auto text = TextConverter::ToUTF16("啊123\u261d\U0001f3ff \u261d321"); 50 auto measurer = Measurer::Create(text, *fc); 51 measurer->SetFontStyle({}); 52 measurer->SetLocale("zh_CN.utf-8"); 53 measurer->SetRTL(false); 54 measurer->SetRange(0, text.size()); 55 CharGroups cgs; 56 GTEST_ASSERT_EQ(measurer->Measure(cgs), 0); 57 GTEST_ASSERT_EQ(cgs.GetNumberOfCharGroup(), 11u); 58 59 for (const auto &cg : cgs) { 60 std::stringstream ss; 61 ss << "cg: " << "width=" << cg.GetWidth() << ", "; 62 for (const auto &c : cg.chars) { 63 ss << "[0x" << std::hex << c << "]"; 64 GTEST_ASSERT_GT(c, 0); 65 } 66 DEBUG_LOG() << ss.str(); 67 68 GTEST_ASSERT_GT(cg.chars.size(), 0u); 69 GTEST_ASSERT_GT(cg.GetWidth(), 0); 70 } 71 } 72 } // namespace 73 } // namespace TextEngine 74 } // namespace Rosen 75 } // namespace OHOS 76