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