1 /*
2 * Copyright (c) 2021-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 "utils/psue_manager.h"
18
19 using namespace OHOS::Global::Resource;
20 using namespace testing::ext;
21
22 namespace {
23 class PsueManagerTest : public testing::Test {
24 public:
25 void SetUp();
26
27 private:
28 std::shared_ptr<PsueManager> psueManager;
29 };
30
SetUp()31 void PsueManagerTest::SetUp()
32 {
33 psueManager = std::make_shared<PsueManager>();
34 }
35
36 HWTEST_F(PsueManagerTest, TestBidirectionConvertFunc001, TestSize.Level1)
37 {
38 std::string noAsciiStr = "Hello, 世界!";
39 std::string asciiStr = "123qwe 0.*/";
40 EXPECT_EQ(psueManager->BidirectionConvert(asciiStr), "\u200F\u202E123qwe\u202C\u200F \u200F\u202E0.*/\u202C\u200F");
41 EXPECT_EQ(psueManager->BidirectionConvert(noAsciiStr), noAsciiStr);
42 }
43
44 HWTEST_F(PsueManagerTest, TestConvertFunc001, TestSize.Level1)
45 {
46 std::string noAsciiStr = "Hello, 世界!";
47 std::string longStr = "abcdefghijklmnopqrstuvwxyz0123456789 abcdefghijklmnopqrstuvwxyz0123456789";
48 std::string outValue = "";
49 psueManager->Convert("123", outValue);
50 EXPECT_EQ(outValue, "");
51 psueManager->Convert("abc", outValue);
52 EXPECT_EQ(outValue, "[àbćReÇÉÄß]");
53 outValue = "";
54 psueManager->Convert("", outValue);
55 EXPECT_EQ(outValue, "");
56 psueManager->Convert(noAsciiStr, outValue);
57 EXPECT_EQ(outValue, "[Helló, 世界!ReÇÉÄßÑ¿ÃóèìжД]");
58 psueManager->SetFakeLocaleLevel(3);
59 psueManager->Convert("abc {test} %dabc", outValue);
60 EXPECT_EQ(psueManager->Convert("abc {test} %dabc", outValue), "");
61 }
62
63 /*
64 * @tc.name: TestGetExtendRatio001
65 * @tc.desc: Test GetExtendRatio function
66 * @tc.type: FUNC
67 */
68 HWTEST_F(PsueManagerTest, TestGetExtendRatio001, TestSize.Level1)
69 {
70 int32_t len = 1000;
71 float result = psueManager->GetExtendRatio(len);
72 EXPECT_EQ(0.3f, result);
73 }
74 } // namespace
75