1 /*
2 * Copyright (c) 2024 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 <gtest/gtest.h>
17
18 #include "iremote_object_mocker.h"
19 #include "window_display_change_adapter.h"
20 #include "window_manager_hilog.h"
21
22 #include "window_display_change_adapter.cpp"
23
24 using namespace testing;
25 using namespace testing::ext;
26
27 namespace OHOS {
28 namespace Rosen {
29 class TestDisplayInfoChangedListener : public IDisplayInfoChangedListener {
30 public:
31 DisplayId displayId_{ 0 };
32 float density_{ 0.0f };
33 DisplayOrientation orientation_{ DisplayOrientation::UNKNOWN };
34
OnDisplayInfoChange(const sptr<IRemoteObject> & token,DisplayId displayId,float density,DisplayOrientation orientation)35 void OnDisplayInfoChange(const sptr<IRemoteObject>& token,
36 DisplayId displayId,
37 float density,
38 DisplayOrientation orientation) override
39 {
40 displayId_ = displayId;
41 density_ = density;
42 orientation_ = orientation;
43 }
44 };
45
46 class WindowDisplayChangeAdapterTest : public testing::Test {
47 public:
48 static void SetUpTestCase();
49 static void TearDownTestCase();
50 void SetUp() override;
51 void TearDown() override;
52 };
SetUpTestCase()53 void WindowDisplayChangeAdapterTest::SetUpTestCase() {}
54
TearDownTestCase()55 void WindowDisplayChangeAdapterTest::TearDownTestCase() {}
56
SetUp()57 void WindowDisplayChangeAdapterTest::SetUp() {}
58
TearDown()59 void WindowDisplayChangeAdapterTest::TearDown() {}
60
61 namespace {
62 /**
63 * @tc.name: OnChange
64 * @tc.desc: Window Display Information Change
65 * @tc.type: FUNC
66 */
67 HWTEST_F(WindowDisplayChangeAdapterTest, OnChange, Function | SmallTest | Level2)
68 {
69 sptr<IRemoteObject> targetToken = new (std::nothrow) IRemoteObjectMocker();
70 ASSERT_NE(nullptr, targetToken);
71 sptr<TestDisplayInfoChangedListener> listener = new (std::nothrow) TestDisplayInfoChangedListener();
72 ASSERT_NE(nullptr, listener);
73 sptr<WindowDisplayChangeAdapter> window = new WindowDisplayChangeAdapter(targetToken, listener);
74 ASSERT_NE(nullptr, window);
75 DisplayId displayId = 0;
76 window->OnChange(displayId);
77 }
78
79 /**
80 * @tc.name: OnDisplayInfoChange
81 * @tc.desc: notify Display Information Change
82 * @tc.type: FUNC
83 */
84 HWTEST_F(WindowDisplayChangeAdapterTest, OnDisplayInfoChange, Function | SmallTest | Level2)
85 {
86 sptr<IRemoteObject> targetToken = new (std::nothrow) IRemoteObjectMocker();
87 ASSERT_NE(nullptr, targetToken);
88 sptr<TestDisplayInfoChangedListener> listener = new (std::nothrow) TestDisplayInfoChangedListener();
89 ASSERT_NE(nullptr, listener);
90 sptr<WindowDisplayChangeAdapter> window = new WindowDisplayChangeAdapter(targetToken, listener);
91 ASSERT_NE(nullptr, window);
92
93 DisplayId displayId = 1;
94 float density = 0.2f;
95 DisplayOrientation orientation = DisplayOrientation::UNKNOWN;
96
97 window->OnDisplayInfoChange(targetToken, displayId, density, orientation);
98 // not need notify display info, data is not changed
99 window->OnDisplayInfoChange(targetToken, displayId, density, orientation);
100
101 ASSERT_EQ(displayId, listener->displayId_);
102 ASSERT_EQ(density, listener->density_);
103 ASSERT_EQ(orientation, listener->orientation_);
104 }
105 } // namespace
106 } // namespace Rosen
107 } // namespace OHOS