• 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 
TearDownTestCase()40 void WindowGamutTest::TearDownTestCase() {}
41 
SetUp()42 void WindowGamutTest::SetUp()
43 {
44     fullScreenAppInfo_ = {
45         .name = "FullWindow",
46         .rect = Utils::customAppRect_,
47         .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
48         .mode = WindowMode::WINDOW_MODE_FULLSCREEN,
49         .needAvoid = false,
50         .parentLimit = false,
51         .parentId = INVALID_WINDOW_ID,
52     };
53 }
54 
TearDown()55 void WindowGamutTest::TearDown() {}
56 
57 namespace {
58 /**
59  * @tc.name: IsSupportWideGamut01
60  * @tc.desc: IsSupportWideGamut
61  * @tc.type: FUNC
62  */
63 HWTEST_F(WindowGamutTest, IsSupportWideGamut01, TestSize.Level1)
64 {
65     fullScreenAppInfo_.name = "window_isSupportWideGamut01";
66     sptr<Window> window = Utils::CreateTestWindow(fullScreenAppInfo_);
67     ASSERT_NE(window, nullptr);
68 
69     ASSERT_EQ(true, window->IsSupportWideGamut());
70 
71     window->Destroy();
72 }
73 
74 /**
75  * @tc.name: GetColorSpace01
76  * @tc.desc: Get ColorSpace
77  * @tc.type: FUNC
78  */
79 HWTEST_F(WindowGamutTest, GetColorSpace01, TestSize.Level1)
80 {
81     fullScreenAppInfo_.name = "window_getColorSpace01";
82     sptr<Window> window = Utils::CreateTestWindow(fullScreenAppInfo_);
83     ASSERT_NE(window, nullptr);
84 
85     ASSERT_EQ(ColorSpace::COLOR_SPACE_DEFAULT, window->GetColorSpace());
86 
87     window->Destroy();
88 }
89 
90 /**
91  * @tc.name: SetColorSpace01
92  * @tc.desc: Set ColorSpace, valid param
93  * @tc.type: FUNC
94  */
95 HWTEST_F(WindowGamutTest, SetColorSpace01, TestSize.Level1)
96 {
97     uint32_t i, j;
98     const ColorSpace colorSpacesToTest[] = { ColorSpace::COLOR_SPACE_DEFAULT, ColorSpace::COLOR_SPACE_WIDE_GAMUT };
99     ColorSpace colorSpace;
100     fullScreenAppInfo_.name = "window_setColorSpace01";
101     sptr<Window> window = Utils::CreateTestWindow(fullScreenAppInfo_);
102     ASSERT_NE(window, nullptr);
103 
104     ColorSpace colorSpaceBackup = window->GetColorSpace(); // backup origin
105 
106     for (j = 0; j < sizeof(colorSpacesToTest) / sizeof(ColorSpace); j++) {
107         window->SetColorSpace(colorSpacesToTest[j]); // async func
108         for (i = 0; i < MAX_WAIT_COUNT; i++) {       // wait some time for async set ok
109             colorSpace = window->GetColorSpace();
110             if (colorSpace != colorSpacesToTest[j]) {
111                 usleep(WAIT_DUR);
112             } else {
113                 break;
114             }
115         }
116         ASSERT_EQ(colorSpacesToTest[j], window->GetColorSpace());
117     }
118 
119     window->SetColorSpace(colorSpaceBackup); // restore
120 
121     window->Destroy();
122 }
123 
124 /**
125  * @tc.name: SetColorSpace02
126  * @tc.desc: Set ColorSpace, invalid param
127  * @tc.type: FUNC
128  */
129 HWTEST_F(WindowGamutTest, SetColorSpace02, TestSize.Level1)
130 {
131     fullScreenAppInfo_.name = "window_setColorSpace02";
132     sptr<Window> window = Utils::CreateTestWindow(fullScreenAppInfo_);
133     ASSERT_NE(window, nullptr);
134     ColorSpace colorSpaceBackup = window->GetColorSpace();
135 
136     ColorSpace invalidColorSpace =
137         static_cast<ColorSpace>(static_cast<uint32_t>(ColorSpace::COLOR_SPACE_WIDE_GAMUT) + 1);
138     window->SetColorSpace(invalidColorSpace); // invalid param
139 
140     ASSERT_EQ(colorSpaceBackup, window->GetColorSpace());
141 
142     window->Destroy();
143 }
144 } // namespace
145 } // namespace Rosen
146 } // namespace OHOS
147