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