• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 // gtest
17 #include <gtest/gtest.h>
18 #include "window_test_utils.h"
19 #include "wm_common.h"
20 using namespace testing;
21 using namespace testing::ext;
22 
23 namespace OHOS {
24 namespace Rosen {
25 using Utils = WindowTestUtils;
26 constexpr uint32_t MAX_WAIT_COUNT = 100;
27 constexpr uint32_t WAIT_DUR = 10 * 1000;
28 
29 class WindowGamutTest : public testing::Test {
30 public:
31     static void SetUpTestCase();
32     static void TearDownTestCase();
33     virtual void SetUp() override;
34     virtual void TearDown() override;
35     Utils::TestWindowInfo fullScreenAppInfo_;
36 };
37 
SetUpTestCase()38 void WindowGamutTest::SetUpTestCase()
39 {
40 }
41 
TearDownTestCase()42 void WindowGamutTest::TearDownTestCase()
43 {
44 }
45 
SetUp()46 void WindowGamutTest::SetUp()
47 {
48     fullScreenAppInfo_ = {
49             .name = "FullWindow",
50             .rect = Utils::customAppRect_,
51             .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
52             .mode = WindowMode::WINDOW_MODE_FULLSCREEN,
53             .needAvoid = false,
54             .parentLimit = false,
55             .parentId = INVALID_WINDOW_ID,
56     };
57 }
58 
TearDown()59 void WindowGamutTest::TearDown()
60 {
61 }
62 
63 namespace {
64 /**
65  * @tc.name: IsSupportWideGamut01
66  * @tc.desc: IsSupportWideGamut
67  * @tc.type: FUNC
68  */
69 HWTEST_F(WindowGamutTest, IsSupportWideGamut01, Function | MediumTest | Level3)
70 {
71     const sptr<Window>& window = Utils::CreateTestWindow(fullScreenAppInfo_);
72 
73     ASSERT_EQ(true, window->IsSupportWideGamut());
74 
75     window->Destroy();
76 }
77 
78 /**
79  * @tc.name: GetColorSpace01
80  * @tc.desc: Get ColorSpace
81  * @tc.type: FUNC
82  */
83 HWTEST_F(WindowGamutTest, GetColorSpace01, Function | MediumTest | Level3)
84 {
85     const sptr<Window>& window = Utils::CreateTestWindow(fullScreenAppInfo_);
86 
87     ASSERT_EQ(ColorSpace::COLOR_SPACE_DEFAULT, window->GetColorSpace());
88 
89     window->Destroy();
90 }
91 
92 /**
93  * @tc.name: SetColorSpace01
94  * @tc.desc: Set ColorSpace, valid param
95  * @tc.type: FUNC
96  */
97 HWTEST_F(WindowGamutTest, SetColorSpace01, Function | MediumTest | Level3)
98 {
99     uint32_t i, j;
100     const ColorSpace colorSpacesToTest[] = {
101         ColorSpace::COLOR_SPACE_DEFAULT,
102         ColorSpace::COLOR_SPACE_WIDE_GAMUT
103     };
104     ColorSpace colorSpace;
105     const sptr<Window>& window = Utils::CreateTestWindow(fullScreenAppInfo_);
106 
107     ColorSpace colorSpaceBackup = window->GetColorSpace(); // backup origin
108 
109     for (j = 0; j < sizeof(colorSpacesToTest) / sizeof(ColorSpace); j++) {
110         window->SetColorSpace(colorSpacesToTest[j]); // async func
111         for (i = 0; i < MAX_WAIT_COUNT; i++) { // wait some time for async set ok
112             colorSpace = window->GetColorSpace();
113             if (colorSpace != colorSpacesToTest[j]) {
114                 usleep(WAIT_DUR);
115             } else {
116                 break;
117             }
118         }
119         ASSERT_EQ(colorSpacesToTest[j], window->GetColorSpace());
120     }
121 
122     window->SetColorSpace(colorSpaceBackup); // restore
123 
124     window->Destroy();
125 }
126 
127 /**
128  * @tc.name: SetColorSpace02
129  * @tc.desc: Set ColorSpace, invalid param
130  * @tc.type: FUNC
131  */
132 HWTEST_F(WindowGamutTest, SetColorSpace02, Function | MediumTest | Level3)
133 {
134     const sptr<Window>& window = Utils::CreateTestWindow(fullScreenAppInfo_);
135 
136     ColorSpace colorSpaceBackup = window->GetColorSpace();
137 
138     ColorSpace invalidColorSpace =
139         static_cast<ColorSpace>(static_cast<uint32_t>(ColorSpace::COLOR_SPACE_WIDE_GAMUT) + 1);
140     window->SetColorSpace(invalidColorSpace);  // invalid param
141 
142     ASSERT_EQ(colorSpaceBackup, window->GetColorSpace());
143 
144     window->Destroy();
145 }
146 } // namespace
147 } // namespace Rosen
148 } // namespace OHOS
149