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