• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "text_global_config.h"
18 #include "text/text_blob.h"
19 
20 using namespace testing;
21 using namespace testing::ext;
22 using namespace OHOS::Rosen::Drawing;
23 namespace OHOS::Rosen::SrvText {
24 class TextGlobalConfigTest : public testing::Test {};
25 
GetTextHighContrast()26 static uint32_t GetTextHighContrast()
27 {
28     auto& instance = ProcessTextConstrast::Instance();
29     return static_cast<uint32_t>(instance.GetTextContrast());
30 }
31 
32 /*
33 * @tc.name: TextHighContrastTest01
34 * @tc.desc: test for text high contrast mode
35 * @tc.type: FUNC
36 */
37 HWTEST_F(TextGlobalConfigTest, TextHighContrastTest01, TestSize.Level0)
38 {
39     auto result = TextGlobalConfig::SetTextHighContrast(TEXT_FOLLOW_SYSTEM_HIGH_CONTRAST);
40     EXPECT_EQ(result, TEXT_SUCCESS);
41     EXPECT_EQ(GetTextHighContrast(), TEXT_FOLLOW_SYSTEM_HIGH_CONTRAST);
42 
43     result = TextGlobalConfig::SetTextHighContrast(TEXT_APP_DISABLE_HIGH_CONTRAST);
44     EXPECT_EQ(result, TEXT_SUCCESS);
45     EXPECT_EQ(GetTextHighContrast(), TEXT_APP_DISABLE_HIGH_CONTRAST);
46 
47     result = TextGlobalConfig::SetTextHighContrast(TEXT_APP_ENABLE_HIGH_CONTRAST);
48     EXPECT_EQ(result, TEXT_SUCCESS);
49     EXPECT_EQ(GetTextHighContrast(), TEXT_APP_ENABLE_HIGH_CONTRAST);
50 }
51 
52 /*
53 * @tc.name: TextHighContrastTest02
54 * @tc.desc: test for text high contrast mode(Invalid)
55 * @tc.type: FUNC
56 */
57 HWTEST_F(TextGlobalConfigTest, TextHighContrastTest02, TestSize.Level0)
58 {
59     uint32_t preValue = GetTextHighContrast();
60     auto result = TextGlobalConfig::SetTextHighContrast(TEXT_HIGH_CONTRAST_BUTT);
61     EXPECT_EQ(result, TEXT_ERR_PARA_INVALID);
62     EXPECT_EQ(GetTextHighContrast(), preValue);
63 }
64 
65 
66 /*
67 * @tc.name: TextUndefinedGlyphDisplayTest01
68 * @tc.desc: test for text high contrast mode(Invalid)
69 * @tc.type: FUNC
70 */
71 HWTEST_F(TextGlobalConfigTest, TextUndefinedGlyphDisplayTest01, TestSize.Level0)
72 {
73     uint32_t result = TextGlobalConfig::SetTextUndefinedGlyphDisplay(UNDEFINED_GLYPH_USE_DEFAULT);
74     EXPECT_EQ(result, 0);
75     result = TextGlobalConfig::SetTextUndefinedGlyphDisplay(UNDEFINED_GLYPH_USE_TOFU);
76     EXPECT_EQ(result, 0);
77     result = TextGlobalConfig::SetTextUndefinedGlyphDisplay(3);
78     EXPECT_EQ(result, TEXT_ERR_PARA_INVALID);
79 }
80 
81 } // namespace OHOS::Rosen::SrvText