1 /*
2  * Copyright (c) 2023 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 #include <cinttypes>
17 #include <gtest/gtest.h>
18 
19 #include "display_manager.h"
20 #include "display_change_info.h"
21 #include "window_manager_hilog.h"
22 #include "window.h"
23 
24 using namespace testing;
25 using namespace testing::ext;
26 
27 namespace OHOS {
28 namespace Rosen {
29 namespace {
30 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "displayUpdateTest"};
31 }
32 class DisplayUpdateListener : public DisplayManager::IDisplayUpdateListener {
33 public:
OnDisplayUpdate(const sptr<DisplayChangeInfo>& info)34     virtual void OnDisplayUpdate(const sptr<DisplayChangeInfo>& info)
35     {
36         WLOGFI("Display Update");
37     };
38 };
39 
40 class DisplayUpdateTest : public testing::Test {
41 public:
42     static void SetUpTestCase();
43     static void TearDownTestCase();
44     void SetUp() override;
45     void TearDown() override;
46 };
47 
SetUpTestCase()48 void DisplayUpdateTest::SetUpTestCase()
49 {
50 }
51 
TearDownTestCase()52 void DisplayUpdateTest::TearDownTestCase()
53 {
54 }
55 
SetUp()56 void DisplayUpdateTest::SetUp()
57 {
58 }
59 
TearDown()60 void DisplayUpdateTest::TearDown()
61 {
62 }
63 
64 namespace {
65 /**
66  * @tc.name: RegisterPrivateWindowListener
67  * @tc.desc: Register private window listener test
68  * @tc.type: FUNC
69  */
HWTEST_F(DisplayUpdateTest, RegisterDisplayUpdateListener, Function | MediumTest | Level2)70 HWTEST_F(DisplayUpdateTest, RegisterDisplayUpdateListener, Function | MediumTest | Level2)
71 {
72     auto& dm = DisplayManager::GetInstance();
73     sptr<DisplayUpdateListener> listener_ = new DisplayUpdateListener();
74     dm.RegisterDisplayUpdateListener(listener_);
75     sptr<WindowOption> option = new WindowOption();
76     auto window = Window::Create("private", option);
77     if (window == nullptr) {
78         WLOGFE("window is null");
79         return;
80     }
81     window->Show();
82     dm.UnregisterDisplayUpdateListener(listener_);
83     window->Destroy();
84 }
85 } // namespace
86 } // namespace Rosen
87 } // namespace OHOS