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 #include <gtest/gtest.h>
17
18 #include "device_profile_dumper.h"
19 #include "device_profile_utils.h"
20 #include "sync_options.h"
21 #include "subscribe_info.h"
22 #include "utils.h"
23
24 namespace OHOS {
25 namespace DeviceProfile {
26 using namespace testing;
27 using namespace testing::ext;
28
29 namespace {
30 constexpr uint32_t MAX_EVENT_LEN = 1000001;
31 constexpr int32_t MAX_DEVICE_LEN = 1000001;
32 }
33
34 class DeviceProfileUtilsTest : public testing::Test {
35 public:
36 static void SetUpTestCase();
37 static void TearDownTestCase();
38 void SetUp();
39 void TearDown();
40 };
41
SetUpTestCase()42 void DeviceProfileUtilsTest::SetUpTestCase()
43 {
44 DTEST_LOG << "SetUpTestCase" << std::endl;
45 }
46
TearDownTestCase()47 void DeviceProfileUtilsTest::TearDownTestCase()
48 {
49 DTEST_LOG << "TearDownTestCase" << std::endl;
50 }
51
SetUp()52 void DeviceProfileUtilsTest::SetUp()
53 {
54 DTEST_LOG << "SetUp" << std::endl;
55 }
56
TearDown()57 void DeviceProfileUtilsTest::TearDown()
58 {
59 DTEST_LOG << "TearDown" << std::endl;
60 }
61
62 /**
63 * @tc.name: WriteProfileEvents_001
64 * @tc.desc: WriteProfileEvents
65 * @tc.type: FUNC
66 * @tc.require: I4NY1T
67 */
68 HWTEST_F(DeviceProfileUtilsTest, WriteProfileEvents_001, TestSize.Level3)
69 {
70 std::list<ProfileEvent> failedEvents;
71 Parcel parcel;
72 bool ret = DeviceProfileUtils::WriteProfileEvents(failedEvents, parcel);
73 EXPECT_TRUE(ret);
74 }
75
76 /**
77 * @tc.name: Unmarshalling_002
78 * @tc.desc: unmarshalling
79 * @tc.type: FUNC
80 * @tc.require: I4NY1T
81 */
82 HWTEST_F(DeviceProfileUtilsTest, Unmarshalling_001, TestSize.Level3)
83 {
84 std::list<ProfileEvent> failedEvents;
85 failedEvents.emplace_back(ProfileEvent::EVENT_PROFILE_CHANGED);
86 failedEvents.emplace_back(ProfileEvent::EVENT_SYNC_COMPLETED);
87 Parcel parcel;
88 bool ret = DeviceProfileUtils::WriteProfileEvents(failedEvents, parcel);
89 EXPECT_TRUE(ret);
90 }
91
92 /**
93 * @tc.name: ReadProfileEvents_001
94 * @tc.desc: ReadProfileEvents
95 * @tc.type: FUNC
96 * @tc.require: I4NY1T
97 */
98 HWTEST_F(DeviceProfileUtilsTest, ReadProfileEvents_001, TestSize.Level3)
99 {
100 Parcel parcel;
101 parcel.WriteUint32(MAX_EVENT_LEN);
102 std::list<ProfileEvent> failedEvents;
103 bool ret = DeviceProfileUtils::ReadProfileEvents(parcel, failedEvents);
104 EXPECT_FALSE(ret);
105 }
106
107 /**
108 * @tc.name: ReadProfileEvents_002
109 * @tc.desc: ReadProfileEvents
110 * @tc.type: FUNC
111 * @tc.require: I4NY1T
112 */
113 HWTEST_F(DeviceProfileUtilsTest, ReadProfileEvents_002, TestSize.Level3)
114 {
115 Parcel parcel;
116 parcel.WriteUint32(1);
117 parcel.WriteUint32(1);
118 std::list<ProfileEvent> failedEvents;
119 bool ret = DeviceProfileUtils::ReadProfileEvents(parcel, failedEvents);
120 EXPECT_TRUE(ret);
121 }
122
123 /**
124 * @tc.name: ReadProfileEvents_003
125 * @tc.desc: ReadProfileEvents
126 * @tc.type: FUNC
127 * @tc.require: I4NY1T
128 */
129 HWTEST_F(DeviceProfileUtilsTest, ReadProfileEvents_003, TestSize.Level3)
130 {
131 Parcel parcel;
132 parcel.WriteUint32(1);
133 parcel.WriteUint32(0);
134 std::list<ProfileEvent> failedEvents;
135 bool ret = DeviceProfileUtils::ReadProfileEvents(parcel, failedEvents);
136 EXPECT_FALSE(ret);
137 }
138
139 /**
140 * @tc.name: ReadProfileEvents_003
141 * @tc.desc: ReadProfileEvents
142 * @tc.type: FUNC
143 * @tc.require: I4NY1T
144 */
145 HWTEST_F(DeviceProfileUtilsTest, ReadProfileEvents_004, TestSize.Level3)
146 {
147 Parcel parcel;
148 parcel.WriteUint32(1);
149 parcel.WriteUint32(4);
150 std::list<ProfileEvent> failedEvents;
151 bool ret = DeviceProfileUtils::ReadProfileEvents(parcel, failedEvents);
152 EXPECT_FALSE(ret);
153 }
154
155 /**
156 * @tc.name: Dump_001
157 * @tc.desc: dump
158 * @tc.type: FUNC
159 * @tc.require: I4NY1T
160 */
161 HWTEST_F(DeviceProfileUtilsTest, Dump_001, TestSize.Level3)
162 {
163 std::string result;
164 std::vector<std::string> args;
165 bool ret = DeviceProfileDumper::Dump(args, result);
166 EXPECT_FALSE(ret);
167 }
168
169 /**
170 * @tc.name: Marshalling_001
171 * @tc.desc: dump
172 * @tc.type: FUNC
173 * @tc.require: I4NY1T
174 */
175 HWTEST_F(DeviceProfileUtilsTest, SyncOptionsMarshalling_001, TestSize.Level3)
176 {
177 SyncOptions syncOption;
178 Parcel parcel;
179 bool ret = syncOption.Marshalling(parcel);
180 EXPECT_TRUE(ret);
181 }
182
183 /**
184 * @tc.name: Marshalling_002
185 * @tc.desc: dump
186 * @tc.type: FUNC
187 * @tc.require: I4NY1T
188 */
189 HWTEST_F(DeviceProfileUtilsTest, SyncOptionsMarshalling_002, TestSize.Level3)
190 {
191 SyncOptions syncOption;
192 syncOption.AddDevice("1234");
193 Parcel parcel;
194 bool ret = syncOption.Marshalling(parcel);
195 EXPECT_TRUE(ret);
196 }
197
198 /**
199 * @tc.name: Unmarshalling_001
200 * @tc.desc: Unmarshalling
201 * @tc.type: FUNC
202 * @tc.require: I4NY1T
203 */
204 HWTEST_F(DeviceProfileUtilsTest, SyncOptionsUnmarshalling_001, TestSize.Level3)
205 {
206 Parcel parcel;
207 parcel.WriteInt32(1);
208 parcel.WriteInt32(0);
209 SyncOptions syncOption;
210 bool ret = syncOption.Unmarshalling(parcel);
211 EXPECT_TRUE(ret);
212 }
213
214 /**
215 * @tc.name: Unmarshalling_002
216 * @tc.desc: Unmarshalling
217 * @tc.type: FUNC
218 * @tc.require: I4NY1T
219 */
220 HWTEST_F(DeviceProfileUtilsTest, SyncOptionsUnmarshalling_002, TestSize.Level3)
221 {
222 Parcel parcel;
223 parcel.WriteInt32(1);
224 parcel.WriteInt32(MAX_DEVICE_LEN);
225 SyncOptions syncOption;
226 bool ret = syncOption.Unmarshalling(parcel);
227 EXPECT_FALSE(ret);
228 }
229
230 /**
231 * @tc.name: Unmarshalling_003
232 * @tc.desc: Unmarshalling
233 * @tc.type: FUNC
234 * @tc.require: I4NY1T
235 */
236 HWTEST_F(DeviceProfileUtilsTest, SyncOptionsUnmarshalling_003, TestSize.Level3)
237 {
238 Parcel parcel;
239 parcel.WriteInt32(1);
240 parcel.WriteInt32(1);
241 parcel.WriteString("12345");
242 SyncOptions syncOption;
243 bool ret = syncOption.Unmarshalling(parcel);
244 EXPECT_TRUE(ret);
245 }
246 }
247 }