1 /*
2 * Copyright (c) 2021 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 #include "display.h"
18 #include "window/window_manager/utils/include/display_info.h"
19
20 namespace OHOS::Rosen {
21 namespace {
22 const int32_t HEIGHT_VALUE = 1000;
23 const int32_t WEIGHT_VALUE = 600;
24 } // namespace
25
26 class Display::Impl : public RefBase {
27 public:
Impl(const std::string & name,sptr<DisplayInfo> displayInfo)28 Impl(const std::string& name, sptr<DisplayInfo> displayInfo)
29 {
30 name_ = name;
31 displayInfo_ = displayInfo;
32 }
33 ~Impl() = default;
34 DEFINE_VAR_FUNC_GET_SET(std::string, Name, name);
35 DEFINE_VAR_FUNC_GET_SET(sptr<DisplayInfo>, DisplayInfo, displayInfo);
36 };
37
Display(const std::string & name,sptr<DisplayInfo> info)38 Display::Display(const std::string& name, sptr<DisplayInfo> info) : pImpl_(new Impl(name, info))
39 {
40 GTEST_LOG_(INFO) << "MOCK Display Display";
41 }
42
~Display()43 Display::~Display()
44 {
45 GTEST_LOG_(INFO) << "MOCK Display ~Display";
46 }
47
GetId() const48 DisplayId Display::GetId() const
49 {
50 GTEST_LOG_(INFO) << "MOCK Display ~Display";
51 DisplayId displayId {0};
52 return displayId;
53 }
54
GetWidth() const55 int32_t Display::GetWidth() const
56 {
57 GTEST_LOG_(INFO) << "MOCK Display GetWidth";
58 return WEIGHT_VALUE;
59 }
60
GetHeight() const61 int32_t Display::GetHeight() const
62 {
63 GTEST_LOG_(INFO) << "MOCK Display GetHeight";
64 return HEIGHT_VALUE;
65 }
66
GetRefreshRate() const67 uint32_t Display::GetRefreshRate() const
68 {
69 GTEST_LOG_(INFO) << "MOCK Display GetRefreshRate";
70 return 0;
71 }
72
GetScreenId() const73 ScreenId Display::GetScreenId() const
74 {
75 GTEST_LOG_(INFO) << "MOCK Display GetScreenId";
76 ScreenId screenId {0};
77 return screenId;
78 }
79
UpdateDisplayInfo(sptr<DisplayInfo> displayInfo) const80 void Display::UpdateDisplayInfo(sptr<DisplayInfo> displayInfo) const
81 {
82 GTEST_LOG_(INFO) << "MOCK Display UpdateDisplayInfo";
83 if (!displayInfo) {
84 return;
85 }
86 pImpl_->SetDisplayInfo(displayInfo);
87 }
88
GetVirtualPixelRatio() const89 float Display::GetVirtualPixelRatio() const
90 {
91 #ifdef PRODUCT_RK
92 return 1.0f;
93 #else
94 return 2.0f;
95 #endif
96 }
97 } // namespace OHOS::Rosen