1 /*
2 * Copyright (c) 2022 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 #define private public
17 #include "dscreen_maprelation_test.h"
18 #undef private
19
20 using json = nlohmann::json;
21
22 using namespace testing::ext;
23
24 namespace OHOS {
25 namespace DistributedHardware {
SetUpTestCase(void)26 void DScreenMapRelationTest::SetUpTestCase(void) {}
27
TearDownTestCase(void)28 void DScreenMapRelationTest::TearDownTestCase(void) {}
29
SetUp()30 void DScreenMapRelationTest::SetUp()
31 {
32 dscreenMapRelation = std::make_shared<DScreenMapRelation>();
33 }
34
TearDown()35 void DScreenMapRelationTest::TearDown() {}
36
37 /**
38 * @tc.name: GetDisplayId_001
39 * @tc.desc: Verify the GetDisplayId function.
40 * @tc.type: FUNC
41 * @tc.require: Issue Number
42 */
43 HWTEST_F(DScreenMapRelationTest, GetDisplayId_001, TestSize.Level1)
44 {
45 uint64_t displayId = 0;
46 dscreenMapRelation->SetDisplayId(displayId);
47 uint64_t actual = dscreenMapRelation->GetDisplayId();
48 EXPECT_EQ(displayId, actual);
49 }
50
51 /**
52 * @tc.name: GetScreenId_001
53 * @tc.desc: Verify the GetScreenId function.
54 * @tc.type: FUNC
55 * @tc.require: Issue Number
56 */
57 HWTEST_F(DScreenMapRelationTest, GetScreenId_001, TestSize.Level1)
58 {
59 uint64_t screenId = 0;
60 dscreenMapRelation->SetScreenId(screenId);
61 uint64_t actual = dscreenMapRelation->GetScreenId();
62 EXPECT_EQ(screenId, actual);
63 }
64
65 /**
66 * @tc.name: GetDisplayRect_001
67 * @tc.desc: Verify the GetDisplayRect function.
68 * @tc.type: FUNC
69 * @tc.require: Issue Number
70 */
71 HWTEST_F(DScreenMapRelationTest, GetDisplayRect_001, TestSize.Level1)
72 {
73 DisplayRect res;
74 int32_t startX = 10;
75 res.startX = startX;
76 dscreenMapRelation->SetDisplayRect(res);
77 DisplayRect actual = dscreenMapRelation->GetDisplayRect();
78 EXPECT_EQ(startX, actual.startX);
79 }
80
81 /**
82 * @tc.name: GetScreenRect_001
83 * @tc.desc: Verify the GetScreenRect function.
84 * @tc.type: FUNC
85 * @tc.require: Issue Number
86 */
87 HWTEST_F(DScreenMapRelationTest, GetScreenRect_001, TestSize.Level1)
88 {
89 ScreenRect res;
90 int32_t startX = 10;
91 res.startX = startX;
92 dscreenMapRelation->SetScreenRect(res);
93 ScreenRect actual = dscreenMapRelation->GetScreenRect();
94 EXPECT_EQ(startX, actual.startX);
95 }
96
97 /**
98 * @tc.name: to_json_001
99 * @tc.desc: Verify the to_json function.
100 * @tc.type: FUNC
101 * @tc.require: Issue Number
102 */
103 HWTEST_F(DScreenMapRelationTest, to_json_001, TestSize.Level1)
104 {
105 json j;
106 uint64_t displayId = 1;
107 uint64_t screenId = 2;
108 DisplayRect displayRect = {0, 0, 100, 100};
109 ScreenRect screenRect = {0, 0, 200, 200};
110 DScreenMapRelation dScreenMapRelation;
111 dScreenMapRelation.SetDisplayId(displayId);
112 dScreenMapRelation.SetScreenId(screenId);
113 dScreenMapRelation.SetDisplayRect(displayRect);
114 dScreenMapRelation.SetScreenRect(screenRect);
115 to_json(j, dScreenMapRelation);
116
117 uint64_t jsonDisplayId = 0;
118 j.at(KEY_DISPLAY_ID).get_to(jsonDisplayId);
119 EXPECT_EQ(displayId, jsonDisplayId);
120 }
121
122 /**
123 * @tc.name: from_json_001
124 * @tc.desc: Verify the from_json function.
125 * @tc.type: FUNC
126 * @tc.require: Issue Number
127 */
128 HWTEST_F(DScreenMapRelationTest, from_json_001, TestSize.Level1)
129 {
130 json j;
131 uint64_t displayId = 1;
132 uint64_t screenId = 2;
133 DisplayRect displayRect = {0, 0, 100, 100};
134 ScreenRect screenRect = {0, 0, 200, 200};
135 DScreenMapRelation dScreenMapRelation;
136 dScreenMapRelation.SetDisplayId(displayId);
137 dScreenMapRelation.SetScreenId(screenId);
138 dScreenMapRelation.SetDisplayRect(displayRect);
139 dScreenMapRelation.SetScreenRect(screenRect);
140 to_json(j, dScreenMapRelation);
141
142 DScreenMapRelation jsonDScreenMapRelation;
143 from_json(j, jsonDScreenMapRelation);
144 EXPECT_EQ(displayId, jsonDScreenMapRelation.GetDisplayId());
145 }
146 } // namespace DistributedHardware
147 } // namespace OHOS