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 fullScreenAppInfo_.name = "window_isSupportWideGamut01";
72 sptr<Window> window = Utils::CreateTestWindow(fullScreenAppInfo_);
73 if (window == nullptr) {
74 return;
75 }
76 ASSERT_NE(window, nullptr);
77
78 ASSERT_EQ(true, window->IsSupportWideGamut());
79
80 window->Destroy();
81 }
82
83 /**
84 * @tc.name: GetColorSpace01
85 * @tc.desc: Get ColorSpace
86 * @tc.type: FUNC
87 */
88 HWTEST_F(WindowGamutTest, GetColorSpace01, Function | MediumTest | Level3)
89 {
90 fullScreenAppInfo_.name = "window_getColorSpace01";
91 sptr<Window> window = Utils::CreateTestWindow(fullScreenAppInfo_);
92 if (window == nullptr) {
93 return;
94 }
95 ASSERT_NE(window, nullptr);
96
97 ASSERT_EQ(ColorSpace::COLOR_SPACE_DEFAULT, window->GetColorSpace());
98
99 window->Destroy();
100 }
101
102 /**
103 * @tc.name: SetColorSpace01
104 * @tc.desc: Set ColorSpace, valid param
105 * @tc.type: FUNC
106 */
107 HWTEST_F(WindowGamutTest, SetColorSpace01, Function | MediumTest | Level3)
108 {
109 uint32_t i, j;
110 const ColorSpace colorSpacesToTest[] = {
111 ColorSpace::COLOR_SPACE_DEFAULT,
112 ColorSpace::COLOR_SPACE_WIDE_GAMUT
113 };
114 ColorSpace colorSpace;
115 fullScreenAppInfo_.name = "window_setColorSpace01";
116 sptr<Window> window = Utils::CreateTestWindow(fullScreenAppInfo_);
117 if (window == nullptr) {
118 return;
119 }
120 ASSERT_NE(window, nullptr);
121
122 ColorSpace colorSpaceBackup = window->GetColorSpace(); // backup origin
123
124 for (j = 0; j < sizeof(colorSpacesToTest) / sizeof(ColorSpace); j++) {
125 window->SetColorSpace(colorSpacesToTest[j]); // async func
126 for (i = 0; i < MAX_WAIT_COUNT; i++) { // wait some time for async set ok
127 colorSpace = window->GetColorSpace();
128 if (colorSpace != colorSpacesToTest[j]) {
129 usleep(WAIT_DUR);
130 } else {
131 break;
132 }
133 }
134 ASSERT_EQ(colorSpacesToTest[j], window->GetColorSpace());
135 }
136
137 window->SetColorSpace(colorSpaceBackup); // restore
138
139 window->Destroy();
140 }
141
142 /**
143 * @tc.name: SetColorSpace02
144 * @tc.desc: Set ColorSpace, invalid param
145 * @tc.type: FUNC
146 */
147 HWTEST_F(WindowGamutTest, SetColorSpace02, Function | MediumTest | Level3)
148 {
149 fullScreenAppInfo_.name = "window_setColorSpace02";
150 sptr<Window> window = Utils::CreateTestWindow(fullScreenAppInfo_);
151 if (window == nullptr) {
152 return;
153 }
154 ASSERT_NE(window, nullptr);
155 ColorSpace colorSpaceBackup = window->GetColorSpace();
156
157 ColorSpace invalidColorSpace =
158 static_cast<ColorSpace>(static_cast<uint32_t>(ColorSpace::COLOR_SPACE_WIDE_GAMUT) + 1);
159 window->SetColorSpace(invalidColorSpace); // invalid param
160
161 ASSERT_EQ(colorSpaceBackup, window->GetColorSpace());
162
163 window->Destroy();
164 }
165 } // namespace
166 } // namespace Rosen
167 } // namespace OHOS
168