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: RegisterDisplayUpdateListener
67 * @tc.desc: Register display update listener test
68 * @tc.type: FUNC
69 */
70 HWTEST_F(DisplayUpdateTest, RegisterDisplayUpdateListener, Function | MediumTest | Level2)
71 {
72 auto& dm = DisplayManager::GetInstance();
73 sptr<DisplayUpdateListener> listener_ = new DisplayUpdateListener();
74 auto ret = dm.RegisterDisplayUpdateListener(listener_);
75 ASSERT_EQ(DMError::DM_OK, ret);
76 sptr<WindowOption> option = new WindowOption();
77 option->SetWindowType(WindowType::WINDOW_TYPE_FLOAT);
78 auto window = Window::Create("private", option);
79 if (window == nullptr) {
80 WLOGFE("window is null");
81 return;
82 }
83 window->Show();
84 auto ret1 = dm.UnregisterDisplayUpdateListener(listener_);
85 ASSERT_EQ(DMError::DM_OK, ret1);
86 window->Destroy();
87 }
88 } // namespace
89 } // namespace Rosen
90 } // namespace OHOS