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 <string>
17 #include <map>
18 #include <iostream>
19 #include <fstream>
20 #include <filesystem>
21 #include <gtest/gtest.h>
22 #include "secodeFuzz.h"
23 #include "cJSON.h"
24 #include "common.h"
25 #include "StageContext.h"
26 #include "ChangeJsonUtil.h"
27 using namespace fuzztest;
28
29 namespace {
30 std::string g_buildConfigJson1 = R"({
31 "deviceType": "phone,tablet,2in1",
32 "aceModuleBuild": "C:\\MyApp\\entry\\.preview\\default\\intermediates\\assets\\default\\ets"
33 })";
34
35 std::string g_buildConfigJson2 = R"({
36 "deviceType": "phone,tablet,2in1",
37 "checkEntry": "true"
38 })";
39
TEST(GetHspAceModuleBuildFuzzTest,test_json)40 TEST(GetHspAceModuleBuildFuzzTest, test_json)
41 {
42 std::cout << "--> GetHspAceModuleBuildFuzzTest for common start <--" << std::endl;
43 DT_FUZZ_START(0, TEST_TIMES, (char*)"GetHspAceModuleBuildFuzzTest", 0)
44 {
45 std::string filePath = "buildConfig.json";
46 OHOS::Ide::StageContext::GetInstance().GetHspAceModuleBuild("aaa");
47 ChangeJsonUtil::WriteFile(filePath, "aaa");
48 OHOS::Ide::StageContext::GetInstance().GetHspAceModuleBuild(filePath);
49 ChangeJsonUtil::WriteFile(filePath, g_buildConfigJson2);
50 OHOS::Ide::StageContext::GetInstance().GetHspAceModuleBuild(filePath);
51 uint64_t index = 0;
52 // 变化数据
53 cJSON* jsonArgs = cJSON_Parse(g_buildConfigJson1.c_str());
54 ChangeJsonUtil::ModifyObject(jsonArgs, index);
55 // 保存到文件
56 ChangeJsonUtil::WriteFile(filePath, jsonArgs);
57 cJSON_Delete(jsonArgs);
58 // 执行接口
59 OHOS::Ide::StageContext::GetInstance().GetHspAceModuleBuild(filePath);
60 }
61 DT_FUZZ_END()
62 printf("end ---- GetHspAceModuleBuildFuzzTest\r\n");
63 if (DT_GetIsPass() == 0) {
64 printf("test GetHspAceModuleBuildFuzzTest is not ok\r\n");
65 } else {
66 printf("test GetHspAceModuleBuildFuzzTest is ok\r\n");
67 }
68 std::cout << "--> GetHspAceModuleBuildFuzzTest for common end <--" << std::endl;
69 }
70 }