1 /*
2 * Copyright (c) 2022-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 <map>
17 #include <set>
18 #include <string>
19 #include <utility>
20
21 #include <fcntl.h>
22 #include <sys/stat.h>
23
24 #include <file_ex.h>
25 #include <gtest/gtest.h>
26 #include <json/value.h>
27
28 #include "b_json/b_json_cached_entity.h"
29 #include "b_json/b_json_entity_ext_manage.h"
30 #include "test_manager.h"
31
32 namespace OHOS::FileManagement::Backup {
33 using namespace std;
34 using namespace testing::ext;
35
36 class BJsonEntityExtManageTest : public testing::Test {
37 public:
SetUpTestCase(void)38 static void SetUpTestCase(void) {};
TearDownTestCase()39 static void TearDownTestCase() {};
SetUp()40 void SetUp() {};
TearDown()41 void TearDown() {};
42 };
43
IsEqual(const struct stat & lf,const struct stat & rh)44 bool IsEqual(const struct stat &lf, const struct stat &rh)
45 {
46 if (lf.st_size != rh.st_size) {
47 return false;
48 }
49 if (lf.st_atim.tv_sec != rh.st_atim.tv_sec) {
50 return false;
51 }
52 if (lf.st_atim.tv_nsec != rh.st_atim.tv_nsec) {
53 return false;
54 }
55 if (lf.st_mtim.tv_sec != rh.st_mtim.tv_sec) {
56 return false;
57 }
58 if (lf.st_mtim.tv_nsec != rh.st_mtim.tv_nsec) {
59 return false;
60 }
61 return true;
62 }
63
IsEqual(const map<string,pair<string,struct stat>> & lf,const map<string,pair<string,struct stat>> & rh)64 bool IsEqual(const map<string, pair<string, struct stat>> &lf, const map<string, pair<string, struct stat>> &rh)
65 {
66 if (lf.size() != rh.size()) {
67 return false;
68 }
69
70 auto itemLF = lf.begin();
71 auto itemRH = rh.begin();
72 for (; itemLF != lf.end(); ++itemLF, ++itemRH) {
73 if (itemLF->first != itemRH->first) {
74 return false;
75 }
76 if (itemLF->second.first != itemRH->second.first) {
77 return false;
78 }
79 if (!IsEqual(itemLF->second.second, itemRH->second.second)) {
80 return false;
81 }
82 }
83
84 return true;
85 }
86
GetFileStat(const string & pathTestFile)87 struct stat GetFileStat(const string &pathTestFile)
88 {
89 struct stat sta = {};
90 if (stat(pathTestFile.data(), &sta) == -1) {
91 GTEST_LOG_(INFO) << pathTestFile << " invoked stat failure, errno :" << errno;
92 throw BError(errno);
93 }
94 return sta;
95 }
96
97 /**
98 * @tc.number: SUB_backup_b_json_entity_ext_manage_0100
99 * @tc.name: b_json_entity_ext_manage_0100
100 * @tc.desc: 通过向接口SetExtManage传入不包含任何信息的空map参数,测试对索引文件的操作是否正确。
101 * 0:通过向索引文件写入0条数据模拟对索引文件的(空)内容的测试覆盖
102 * 1:调用接口SetExtManage,向索引文件写入数据
103 * 2:调用接口GetExtManage,从索引文件读出文件名数据
104 * 3:调用接口GetExtManageInfo,从索引文件读出文件详细数据(含文件名和对应文件的stat数据)
105 * 4:判断读出的文件名集合/文件详细数据记录个数是否为0
106 * @tc.size: MEDIUM
107 * @tc.type: FUNC
108 * @tc.level Level 0
109 * @tc.require: I6F3GV
110 */
111 HWTEST_F(BJsonEntityExtManageTest, b_json_entity_ext_manage_0100, testing::ext::TestSize.Level0)
112 {
113 GTEST_LOG_(INFO) << "BJsonEntityExtManageTest-begin b_json_entity_ext_manage_0100";
114 try {
115 // 预置文件数据
116 // 索引文件pathManageFile
117 TestManager tm("b_json_entity_ext_manage_0100");
118 string root = tm.GetRootDirCurTest();
119 string pathManageFile = root + "manage.json";
120 BJsonCachedEntity<BJsonEntityExtManage> cachedEntity(UniqueFd(open(pathManageFile.data(), O_RDONLY, 0)));
121 auto cache = cachedEntity.Structuralize();
122
123 // 写入空数据
124 map<string, pair<string, struct stat>> info;
125 cache.SetExtManage(info);
126
127 // 读取索引文件信息并做结果判断
128 auto fileNames = cache.GetExtManage();
129 EXPECT_EQ(fileNames.size(), 0ul);
130 auto fileInfo = cache.GetExtManageInfo();
131 EXPECT_EQ(fileInfo.size(), 0ul);
132 } catch (...) {
133 EXPECT_TRUE(false);
134 GTEST_LOG_(INFO) << "BJsonEntityExtManageTest-an exception occurred.";
135 }
136 GTEST_LOG_(INFO) << "BJsonEntityExtManageTest-end b_json_entity_ext_manage_0100";
137 }
138
139 /**
140 * @tc.number: SUB_backup_b_json_entity_ext_manage_0200
141 * @tc.name: b_json_entity_ext_manage_0200
142 * @tc.desc: 通过向接口SetExtManage传入包含一条信息的map参数,测试对索引文件的操作是否正确。
143 * 0:通过向索引文件写入1条有效数据模拟对索引文件的(有)内容的测试覆盖
144 * 1:调用接口SetExtManage,向索引文件写入数据
145 * 2:调用接口GetExtManage,从索引文件读出文件名数据
146 * 3:调用接口GetExtManageInfo,从索引文件读出文件详细数据(含文件名和对应文件的stat数据)
147 * 4:判断读出的文件名集合/文件详细数据记录个数是否和写入时相等
148 * 5:判断读出的文件名集合/文件详细数据记录内容是否和写入时相等
149 * @tc.size: MEDIUM
150 * @tc.type: FUNC
151 * @tc.level Level 0
152 * @tc.require: I6F3GV
153 */
154 HWTEST_F(BJsonEntityExtManageTest, b_json_entity_ext_manage_0200, testing::ext::TestSize.Level0)
155 {
156 GTEST_LOG_(INFO) << "BJsonEntityExtManageTest-begin b_json_entity_ext_manage_0200";
157 try {
158 TestManager tm("b_json_entity_ext_manage_0200");
159
160 // 预置文件数据
161 // 索引文件pathManageFile, 测试文件路径pathTestFile, 测试文件名testFileHexName
162 string root = tm.GetRootDirCurTest();
163 string pathManageFile = root + "manage.json";
164 string pathTestFile = root + "test.txt";
165 string testFileHexName = "1234567890abcdef";
166 SaveStringToFile(pathTestFile, "hello world");
167 BJsonCachedEntity<BJsonEntityExtManage> cachedEntity(UniqueFd(open(pathManageFile.data(), O_RDONLY, 0)));
168 auto cache = cachedEntity.Structuralize();
169
170 // 生成一条有用数据并写入索引文件
171 map<string, pair<string, struct stat>> info;
172 struct stat sta = {};
173 info.emplace(testFileHexName, make_pair(pathTestFile, sta = GetFileStat(pathTestFile)));
174 cache.SetExtManage(info);
175
176 // 读取索引文件内容并做结果判断
177 auto fileNames = cache.GetExtManage();
178 ASSERT_EQ(fileNames.size(), 1ul);
179 EXPECT_EQ(*fileNames.begin(), testFileHexName);
180 auto fileInfo = cache.GetExtManageInfo();
181 ASSERT_EQ(fileInfo.size(), 1ul);
182 EXPECT_EQ(fileInfo.begin()->first, testFileHexName);
183 EXPECT_EQ(fileInfo.begin()->second.first, pathTestFile);
184 EXPECT_TRUE(IsEqual(fileInfo.begin()->second.second, sta));
185 } catch (...) {
186 EXPECT_TRUE(false);
187 GTEST_LOG_(INFO) << "BJsonEntityExtManageTest-an exception occurred.";
188 }
189 GTEST_LOG_(INFO) << "BJsonEntityExtManageTest-end b_json_entity_ext_manage_0200";
190 }
191
192 /**
193 * @tc.number: SUB_backup_b_json_entity_ext_manage_0300
194 * @tc.name: b_json_entity_ext_manage_0300
195 * @tc.desc: 通过向接口SetExtManage传入包含三条信息的map参数,测试对索引文件的操作是否正确。
196 * 0:通过向索引文件写入3条有效数据模拟对索引文件的(无穷)内容的测试覆盖
197 * 1:调用接口SetExtManage,向索引文件写入数据
198 * 2:调用接口GetExtManage,从索引文件读出文件名数据
199 * 3:调用接口GetExtManageInfo,从索引文件读出文件详细数据(含文件名和对应文件的stat数据)
200 * 4:判断读出的文件名集合/文件详细数据记录个数是否和写入时相等
201 * 5:判断读出的文件名集合/文件详细数据记录内容是否和写入时相等
202 * @tc.size: MEDIUM
203 * @tc.type: FUNC
204 * @tc.level Level 0
205 * @tc.require: I6F3GV
206 */
207 HWTEST_F(BJsonEntityExtManageTest, b_json_entity_ext_manage_0300, testing::ext::TestSize.Level0)
208 {
209 GTEST_LOG_(INFO) << "BJsonEntityExtManageTest-begin b_json_entity_ext_manage_0300";
210 try {
211 TestManager tm("b_json_entity_ext_manage_0300");
212
213 // 预置文件数据
214 // 索引文件pathManageFile1/2/3, 测试文件路径pathTestFile1/2/3, 测试文件名testFile1/2/3HexName
215 string root = tm.GetRootDirCurTest();
216 string pathManageFile = root + "manage.json";
217 string pathTestFile1 = root + "test1.txt";
218 string pathTestFile2 = root + "test2.txt";
219 string pathTestFile3 = root + "test3.txt";
220 string testFile1HexName = "1234567890abcde1";
221 string testFile2HexName = "1234567890abcde2";
222 string testFile3HexName = "1234567890abcde3";
223 SaveStringToFile(pathTestFile1, "h");
224 SaveStringToFile(pathTestFile2, "hello");
225 SaveStringToFile(pathTestFile3, "hello world");
226 BJsonCachedEntity<BJsonEntityExtManage> cachedEntity(UniqueFd(open(pathManageFile.data(), O_RDONLY, 0)));
227 auto cache = cachedEntity.Structuralize();
228
229 // 生成三条有用数据并写入索引文件
230 map<string, pair<string, struct stat>> info;
231 info.emplace(testFile1HexName, make_pair(pathTestFile1, GetFileStat(pathTestFile1)));
232 info.emplace(testFile2HexName, make_pair(pathTestFile2, GetFileStat(pathTestFile2)));
233 info.emplace(testFile3HexName, make_pair(pathTestFile3, GetFileStat(pathTestFile3)));
234 cache.SetExtManage(info);
235
236 // 预置结果集,用以在读取索引文件后做结果判断
237 set<string> resultFileName {testFile1HexName, testFile2HexName, testFile3HexName};
238
239 // 读取索引文件内容并做结果判断
240 auto fileNames = cache.GetExtManage();
241 EXPECT_EQ(fileNames.size(), info.size());
242 EXPECT_EQ(fileNames, resultFileName);
243 auto fileInfo = cache.GetExtManageInfo();
244 EXPECT_EQ(fileInfo.size(), info.size());
245 EXPECT_TRUE(IsEqual(fileInfo, info));
246 } catch (...) {
247 EXPECT_TRUE(false);
248 GTEST_LOG_(INFO) << "BJsonEntityExtManageTest-an exception occurred.";
249 }
250 GTEST_LOG_(INFO) << "BJsonEntityExtManageTest-end b_json_entity_ext_manage_0300";
251 }
252
253 /**
254 * @tc.number: SUB_backup_b_json_entity_ext_manage_0400
255 * @tc.name: b_json_entity_ext_manage_0400
256 * @tc.desc: 通过向接口SetExtManage传入包含三条信息的map参数,测试对索引文件的操作是否正确。
257 * 0:通过向索引文件写入3条有效数据模拟覆盖对索引文件的(无穷)内容的测试覆盖
258 * 0:通过向索引文件的记录一写入0条、记录二写入1条、记录三写入2条有效硬链接数据模拟对索引文件含
259 * 有硬链接(空、有、无穷)个的测试覆盖
260 * 0:通过调用接口SetHardLinkInfo向索引文件中对应记录添加硬链接
261 * 1:调用接口SetExtManage,向索引文件写入数据
262 * 2:调用接口GetExtManage,从索引文件读出文件名数据
263 * 3:调用接口GetExtManageInfo,从索引文件读出文件详细数据(含文件名和对应文件的stat数据)
264 * 4:判断读出的文件名集合/文件详细数据记录个数是否和写入时相等
265 * 5:判断读出的文件名集合/文件详细数据记录内容是否和写入时相等
266 * @tc.size: MEDIUM
267 * @tc.type: FUNC
268 * @tc.level Level 0
269 * @tc.require: I6F3GV
270 */
271 HWTEST_F(BJsonEntityExtManageTest, b_json_entity_ext_manage_0400, testing::ext::TestSize.Level0)
272 {
273 GTEST_LOG_(INFO) << "BJsonEntityExtManageTest-begin b_json_entity_ext_manage_0400";
274 try {
275 TestManager tm("b_json_entity_ext_manage_0400");
276
277 // 预置文件数据
278 // 索引文件pathManageFile1/2/3, 测试文件路径pathTestFile1/2/3, 测试文件名testFile1/2/3HexName
279 string root = tm.GetRootDirCurTest();
280 string pathManageFile = root + "manage.json";
281 string pathTestFile1 = root + "test1.txt";
282 string pathTestFile2 = root + "test2.txt";
283 string pathTestFile3 = root + "test3.txt";
284 string testFile1HexName = "1234567890abcde1";
285 string testFile2HexName = "1234567890abcde2";
286 string testFile3HexName = "1234567890abcde3";
287 SaveStringToFile(pathTestFile1, "h");
288 SaveStringToFile(pathTestFile2, "hello");
289 SaveStringToFile(pathTestFile3, "hello world");
290 BJsonCachedEntity<BJsonEntityExtManage> cachedEntity(UniqueFd(open(pathManageFile.data(), O_RDONLY, 0)));
291 auto cache = cachedEntity.Structuralize();
292
293 // 生成三条有用数据并写入索引文件
294 map<string, pair<string, struct stat>> info;
295 info.emplace(testFile1HexName, make_pair(pathTestFile1, GetFileStat(pathTestFile1)));
296 info.emplace(testFile2HexName, make_pair(pathTestFile2, GetFileStat(pathTestFile2)));
297 info.emplace(testFile3HexName, make_pair(pathTestFile3, GetFileStat(pathTestFile3)));
298 cache.SetExtManage(info);
299
300 // 向索引文件中的三条记录分别追加0、1、2条硬链接信息
301 set<string> hardLinks1, hardLinks2, hardLinks3;
302 cache.SetHardLinkInfo(testFile1HexName, hardLinks1);
303 hardLinks2.emplace(root + "testFile2hardlink1");
304 cache.SetHardLinkInfo(testFile2HexName, hardLinks2);
305 hardLinks3.emplace(root + "testFile3hardlink1");
306 hardLinks3.emplace(root + "testFile3hardlink2");
307 cache.SetHardLinkInfo(testFile3HexName, hardLinks3);
308
309 // 预置结果集,用以在读取索引文件后做结果判断
310 set<string> resultFileName {testFile1HexName, testFile2HexName, testFile3HexName};
311
312 // 读取索引文件内容并做结果判断
313 auto fileNames = cache.GetExtManage();
314 EXPECT_EQ(fileNames.size(), info.size());
315 EXPECT_EQ(fileNames, resultFileName);
316 auto fileInfo = cache.GetExtManageInfo();
317 EXPECT_EQ(fileInfo.size(), info.size());
318 EXPECT_TRUE(IsEqual(fileInfo, info));
319 // 传入无效文件名"00000000",测试读取文件硬链接接口是否正确返回
320 auto testFile0HardLinks = cache.GetHardLinkInfo("00000000");
321 EXPECT_TRUE(testFile0HardLinks.empty());
322 auto testFile1HardLinks = cache.GetHardLinkInfo(testFile1HexName);
323 EXPECT_TRUE(testFile1HardLinks.empty());
324 auto testFile2HardLinks = cache.GetHardLinkInfo(testFile2HexName);
325 EXPECT_EQ(testFile2HardLinks, hardLinks2);
326 auto testFile3HardLinks = cache.GetHardLinkInfo(testFile3HexName);
327 EXPECT_EQ(testFile3HardLinks, hardLinks3);
328 } catch (...) {
329 EXPECT_TRUE(false);
330 GTEST_LOG_(INFO) << "BJsonEntityExtManageTest-an exception occurred.";
331 }
332 GTEST_LOG_(INFO) << "BJsonEntityExtManageTest-end b_json_entity_ext_manage_0400";
333 }
334
335 /**
336 * @tc.number: SUB_backup_b_json_entity_ext_manage_0500
337 * @tc.name: b_json_entity_ext_manage_0500
338 * @tc.desc: 通过向接口SetExtManage传入包含三条信息的map参数,测试对索引文件的操作是否正确。
339 * 0:通过向索引文件写入3条有效数据模拟覆盖对索引文件的(无穷)内容的测试覆盖
340 * 0:通过向索引文件的记录一写入0条、记录二写入1条、记录三写入2条有效硬链接数据模拟对索引文件含
341 * 有硬链接(空、有、无穷)个的测试覆盖
342 * 0:通过传入和源文件相同stat信息向索引文件中对应记录添加硬链接
343 * 1:调用接口SetExtManage,向索引文件写入数据
344 * 2:调用接口GetExtManage,从索引文件读出文件名数据
345 * 3:调用接口GetExtManageInfo,从索引文件读出文件详细数据(含文件名和对应文件的stat数据)
346 * 4:判断读出的文件名集合/文件详细数据记录个数是否和写入时相等
347 * 5:判断读出的文件名集合/文件详细数据记录内容是否和写入时相等
348 * @tc.size: MEDIUM
349 * @tc.type: FUNC
350 * @tc.level Level 0
351 * @tc.require: I6F3GV
352 */
353 HWTEST_F(BJsonEntityExtManageTest, b_json_entity_ext_manage_0500, testing::ext::TestSize.Level0)
354 {
355 GTEST_LOG_(INFO) << "BJsonEntityExtManageTest-begin b_json_entity_ext_manage_0500";
356 try {
357 // 预置文件数据
358 // 索引文件pathManageFile1/2/3, 测试文件路径pathTestFile1/2/3, 测试文件名testFile1/2/3HexName
359 TestManager tm("b_json_entity_ext_manage_0500");
360 string root = tm.GetRootDirCurTest();
361 string pathManageFile = root + "manage.json";
362 string pathTestFile1 = root + "test1.txt";
363 string pathTestFile2 = root + "test2.txt";
364 string pathTestFile3 = root + "test3.txt";
365 string testFile1HexName = "1234567890abcde1";
366 string testFile2HexName = "1234567890abcde2";
367 string testFile3HexName = "1234567890abcde3";
368 SaveStringToFile(pathTestFile1, "h");
369 SaveStringToFile(pathTestFile2, "hello");
370 SaveStringToFile(pathTestFile3, "hello world");
371 BJsonCachedEntity<BJsonEntityExtManage> cachedEntity(UniqueFd(open(pathManageFile.data(), O_RDONLY, 0)));
372 auto cache = cachedEntity.Structuralize();
373
374 // 生成三条有用数据并写入索引文件
375 // 通过重用原始文件的stat向该记录追加(0/1/2)条硬链接文件信息
376 map<string, pair<string, struct stat>> info;
377 struct stat sta = {};
378 info.emplace(testFile1HexName, make_pair(pathTestFile1, GetFileStat(pathTestFile1)));
379 info.emplace(testFile2HexName, make_pair(pathTestFile2, sta = GetFileStat(pathTestFile2)));
380 info.emplace("testFile2hardlink1", make_pair(root + "testFile2hardlink1", sta));
381 info.emplace(testFile3HexName, make_pair(pathTestFile3, sta = GetFileStat(pathTestFile3)));
382 info.emplace("testFile3hardlink1", make_pair(root + "testFile3hardlink1", sta));
383 info.emplace("testFile3hardlink2", make_pair(root + "testFile3hardlink2", sta));
384 cache.SetExtManage(info);
385
386 // 预置结果集,用以在读取索引文件后做结果判断
387 // 将info中的硬链接信息删除,保留原始文件信息,作为后续结果值判断的比较对象
388 info.erase("testFile2hardlink1");
389 info.erase("testFile3hardlink1");
390 info.erase("testFile3hardlink2");
391 set<string> hardLinks2 {root + "testFile2hardlink1"};
392 set<string> hardLinks3 {root + "testFile3hardlink1", root + "testFile3hardlink2"};
393 set<string> resultFileName {testFile1HexName, testFile2HexName, testFile3HexName};
394
395 // 读取索引文件内容并做结果判断
396 auto fileNames = cache.GetExtManage();
397 EXPECT_EQ(fileNames.size(), 3ul);
398 EXPECT_EQ(fileNames, resultFileName);
399 auto fileInfo = cache.GetExtManageInfo();
400 EXPECT_EQ(fileInfo.size(), info.size());
401 EXPECT_TRUE(IsEqual(fileInfo, info));
402 auto testFile1HardLinks = cache.GetHardLinkInfo(testFile1HexName);
403 EXPECT_TRUE(testFile1HardLinks.empty());
404 auto testFile2HardLinks = cache.GetHardLinkInfo(testFile2HexName);
405 EXPECT_EQ(testFile2HardLinks, hardLinks2);
406 auto testFile3HardLinks = cache.GetHardLinkInfo(testFile3HexName);
407 EXPECT_EQ(testFile3HardLinks, hardLinks3);
408 } catch (...) {
409 EXPECT_TRUE(false);
410 GTEST_LOG_(INFO) << "BJsonEntityExtManageTest-an exception occurred.";
411 }
412 GTEST_LOG_(INFO) << "BJsonEntityExtManageTest-end b_json_entity_ext_manage_0500";
413 }
414
415 /**
416 * @tc.number: SUB_backup_b_json_entity_ext_manage_0600
417 * @tc.name: b_json_entity_ext_manage_0600
418 * @tc.desc: 测试SetExtManage接口中的FindLinks在设备号或INode数目为0时能否成功通过GetExtManage获取相关信息
419 * @tc.size: MEDIUM
420 * @tc.type: FUNC
421 * @tc.level Level 0
422 * @tc.require: I6F3GV
423 */
424 HWTEST_F(BJsonEntityExtManageTest, b_json_entity_ext_manage_0600, testing::ext::TestSize.Level0)
425 {
426 GTEST_LOG_(INFO) << "BJsonEntityExtManageTest-begin b_json_entity_ext_manage_0600";
427 try {
428 map<string, pair<string, struct stat>> mp = {{"key", {"first", {}}}};
429 Json::Value jv;
430 BJsonEntityExtManage extMg(jv);
431
432 extMg.SetExtManage(mp);
433 set<string> ss = extMg.GetExtManage();
434 EXPECT_EQ(ss.size(), 1);
435
436 mp.at("key").second.st_dev = 1;
437 extMg.SetExtManage(mp);
438 ss = extMg.GetExtManage();
439 EXPECT_EQ(ss.size(), 1);
440 } catch (...) {
441 EXPECT_TRUE(false);
442 GTEST_LOG_(INFO) << "BJsonEntityExtManageTest-an exception occurred.";
443 }
444 GTEST_LOG_(INFO) << "BJsonEntityExtManageTest-end b_json_entity_ext_manage_0600";
445 }
446
447 /**
448 * @tc.number: SUB_backup_b_json_entity_ext_manage_0700
449 * @tc.name: b_json_entity_ext_manage_0700
450 * @tc.desc: 测试GetExtManageInfo在Json数据不为数组时能否成功返回空map
451 * @tc.size: MEDIUM
452 * @tc.type: FUNC
453 * @tc.level Level 0
454 * @tc.require: I6F3GV
455 */
456 HWTEST_F(BJsonEntityExtManageTest, b_json_entity_ext_manage_0700, testing::ext::TestSize.Level0)
457 {
458 GTEST_LOG_(INFO) << "BJsonEntityExtManageTest-begin b_json_entity_ext_manage_0700";
459 try {
460 string_view sv = R"({"key":1})";
461 BJsonCachedEntity<BJsonEntityExtManage> cachedEntity(sv);
462 auto cache = cachedEntity.Structuralize();
463 auto mp = cache.GetExtManageInfo();
464 EXPECT_TRUE(mp.empty());
465 } catch (...) {
466 EXPECT_TRUE(false);
467 GTEST_LOG_(INFO) << "BJsonEntityExtManageTest-an exception occurred.";
468 }
469 GTEST_LOG_(INFO) << "BJsonEntityExtManageTest-end b_json_entity_ext_manage_0700";
470 }
471
472 /**
473 * @tc.number: SUB_backup_b_json_entity_ext_manage_0800
474 * @tc.name: b_json_entity_ext_manage_0800
475 * @tc.desc: 测试GetExtManageInfo在Json数据为数组且仅有一个键不为information的对象时能否成功返回空map
476 * @tc.size: MEDIUM
477 * @tc.type: FUNC
478 * @tc.level Level 0
479 * @tc.require: I6F3GV
480 */
481 HWTEST_F(BJsonEntityExtManageTest, b_json_entity_ext_manage_0800, testing::ext::TestSize.Level0)
482 {
483 GTEST_LOG_(INFO) << "BJsonEntityExtManageTest-begin b_json_entity_ext_manage_0800";
484 try {
485 string_view sv = R"([{"key":1}])";
486 BJsonCachedEntity<BJsonEntityExtManage> cachedEntity(sv);
487 auto cache = cachedEntity.Structuralize();
488 auto mp = cache.GetExtManageInfo();
489 EXPECT_TRUE(mp.empty());
490 } catch (...) {
491 EXPECT_TRUE(false);
492 GTEST_LOG_(INFO) << "BJsonEntityExtManageTest-an exception occurred.";
493 }
494 GTEST_LOG_(INFO) << "BJsonEntityExtManageTest-end b_json_entity_ext_manage_0800";
495 }
496
497 /**
498 * @tc.number: SUB_backup_b_json_entity_ext_manage_0900
499 * @tc.name: b_json_entity_ext_manage_0900
500 * @tc.desc: 测试SetHardLinkInfo接口和GetHardLinkInfo接口在不符合相关条件时能否成功返回false和空set
501 * @tc.size: MEDIUM
502 * @tc.type: FUNC
503 * @tc.level Level 0
504 * @tc.require: I6F3GV
505 */
506 HWTEST_F(BJsonEntityExtManageTest, b_json_entity_ext_manage_0900, testing::ext::TestSize.Level0)
507 {
508 GTEST_LOG_(INFO) << "BJsonEntityExtManageTest-begin b_json_entity_ext_manage_0900";
509 try {
510 string_view sv = R"({"key":1})";
511 BJsonCachedEntity<BJsonEntityExtManage> cachedEntity(sv);
512 auto cache = cachedEntity.Structuralize();
513 EXPECT_FALSE(cache.SetHardLinkInfo("", {}));
514
515 Json::Value jv;
516 BJsonEntityExtManage extMg(jv);
517 EXPECT_FALSE(extMg.SetHardLinkInfo("1", {}));
518
519 EXPECT_FALSE(cache.SetHardLinkInfo("1", {}));
520
521 EXPECT_EQ(cache.GetHardLinkInfo(""), set<string>());
522
523 EXPECT_EQ(extMg.GetHardLinkInfo("1"), set<string>());
524
525 EXPECT_EQ(cache.GetHardLinkInfo("1"), set<string>());
526 } catch (...) {
527 EXPECT_TRUE(false);
528 GTEST_LOG_(INFO) << "BJsonEntityExtManageTest-an exception occurred.";
529 }
530 GTEST_LOG_(INFO) << "BJsonEntityExtManageTest-end b_json_entity_ext_manage_0900";
531 }
532 } // namespace OHOS::FileManagement::Backup