• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "mock/mock_any_span.h"
19 #include "text_reverser.h"
20 
21 using namespace testing;
22 using namespace testing::ext;
23 
24 namespace OHOS {
25 namespace Rosen {
26 namespace TextEngine {
27 class ControllerForTest {
28 public:
GenerateTestSpan(bool rtl)29     static std::shared_ptr<TextSpan> GenerateTestSpan(bool rtl)
30     {
31         auto ts = std::make_shared<TextSpan>();
32         ts->rtl_ = rtl;
33         ts->cgs_ = CharGroups::CreateEmpty();
34         return ts;
35     }
36 };
37 
38 class TextReverserTest : public testing::Test {
39 };
40 
41 /**
42  * @tc.name: ReverseRTLText
43  * @tc.desc: Verify the ReverseRTLText
44  * @tc.type:FUNC
45  */
46 HWTEST_F(TextReverserTest, ReverseRTLText, TestSize.Level1)
47 {
48     std::shared_ptr<AnySpan> a1 = std::make_shared<MockAnySpan>();
49     std::shared_ptr<AnySpan> a2 = std::make_shared<MockAnySpan>();
50     std::shared_ptr<TextSpan> l1 = ControllerForTest::GenerateTestSpan(false);
51     std::shared_ptr<TextSpan> l2 = ControllerForTest::GenerateTestSpan(false);
52     std::shared_ptr<TextSpan> l3 = ControllerForTest::GenerateTestSpan(false);
53     std::shared_ptr<TextSpan> l4 = ControllerForTest::GenerateTestSpan(false);
54     std::shared_ptr<TextSpan> r1 = ControllerForTest::GenerateTestSpan(true);
55     std::shared_ptr<TextSpan> r2 = ControllerForTest::GenerateTestSpan(true);
56     std::shared_ptr<TextSpan> r3 = ControllerForTest::GenerateTestSpan(true);
57     std::shared_ptr<TextSpan> r4 = ControllerForTest::GenerateTestSpan(true);
58     TextReverser tr;
59 
60     // 参数设置:全部都是RTL的span
61     std::vector<VariantSpan> spans1 = {r1, r2, r3, r4};
62     tr.ReverseRTLText(spans1);
63     ASSERT_EQ(spans1, (std::vector<VariantSpan>{r4, r3, r2, r1}));
64 
65     // 参数设置:全部都是LTR的span
66     std::vector<VariantSpan> spans2 = {l1, l2, l3, l4};
67     tr.ReverseRTLText(spans2);
68     ASSERT_EQ(spans2, (std::vector<VariantSpan>{l1, l2, l3, l4}));
69 
70     // 参数设置:既包含LTR也包含RTL
71     std::vector<VariantSpan> spans3 = {l1, a1, l2, r1, l3, a2, r2, r3, r4, l4};
72     tr.ReverseRTLText(spans3);
73     ASSERT_EQ(spans3, (std::vector<VariantSpan>{l1, a1, l2, r1, l3, a2, r4, r3, r2, l4}));
74 }
75 } // namespace TextEngine
76 } // namespace Rosen
77 } // namespace OHOS
78