17c804472Sopenharmony_ci/*
27c804472Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
37c804472Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
47c804472Sopenharmony_ci * you may not use this file except in compliance with the License.
57c804472Sopenharmony_ci * You may obtain a copy of the License at
67c804472Sopenharmony_ci *
77c804472Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
87c804472Sopenharmony_ci *
97c804472Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
107c804472Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
117c804472Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
127c804472Sopenharmony_ci * See the License for the specific language governing permissions and
137c804472Sopenharmony_ci * limitations under the License.
147c804472Sopenharmony_ci */
157c804472Sopenharmony_ci
167c804472Sopenharmony_ci#include <string>
177c804472Sopenharmony_ci#include <map>
187c804472Sopenharmony_ci#include <iostream>
197c804472Sopenharmony_ci#include <fstream>
207c804472Sopenharmony_ci#include <filesystem>
217c804472Sopenharmony_ci#include <gtest/gtest.h>
227c804472Sopenharmony_ci#include "secodeFuzz.h"
237c804472Sopenharmony_ci#include "cJSON.h"
247c804472Sopenharmony_ci#include "common.h"
257c804472Sopenharmony_ci#include "StageContext.h"
267c804472Sopenharmony_ci#include "ChangeJsonUtil.h"
277c804472Sopenharmony_ciusing namespace fuzztest;
287c804472Sopenharmony_ci
297c804472Sopenharmony_cinamespace {
307c804472Sopenharmony_cistd::string g_buildConfigJson1 = R"({
317c804472Sopenharmony_ci    "deviceType": "phone,tablet,2in1",
327c804472Sopenharmony_ci    "aceModuleBuild": "C:\\MyApp\\entry\\.preview\\default\\intermediates\\assets\\default\\ets"
337c804472Sopenharmony_ci})";
347c804472Sopenharmony_ci
357c804472Sopenharmony_cistd::string g_buildConfigJson2 = R"({
367c804472Sopenharmony_ci    "deviceType": "phone,tablet,2in1",
377c804472Sopenharmony_ci    "checkEntry": "true"
387c804472Sopenharmony_ci})";
397c804472Sopenharmony_ci
407c804472Sopenharmony_ciTEST(GetHspAceModuleBuildFuzzTest, test_json)
417c804472Sopenharmony_ci{
427c804472Sopenharmony_ci    std::cout << "--> GetHspAceModuleBuildFuzzTest for common start <--" << std::endl;
437c804472Sopenharmony_ci    DT_FUZZ_START(0, TEST_TIMES, (char*)"GetHspAceModuleBuildFuzzTest", 0)
447c804472Sopenharmony_ci    {
457c804472Sopenharmony_ci        std::string filePath = "buildConfig.json";
467c804472Sopenharmony_ci        OHOS::Ide::StageContext::GetInstance().GetHspAceModuleBuild("aaa");
477c804472Sopenharmony_ci        ChangeJsonUtil::WriteFile(filePath, "aaa");
487c804472Sopenharmony_ci        OHOS::Ide::StageContext::GetInstance().GetHspAceModuleBuild(filePath);
497c804472Sopenharmony_ci        ChangeJsonUtil::WriteFile(filePath, g_buildConfigJson2);
507c804472Sopenharmony_ci        OHOS::Ide::StageContext::GetInstance().GetHspAceModuleBuild(filePath);
517c804472Sopenharmony_ci        uint64_t index = 0;
527c804472Sopenharmony_ci        // 变化数据
537c804472Sopenharmony_ci        cJSON* jsonArgs = cJSON_Parse(g_buildConfigJson1.c_str());
547c804472Sopenharmony_ci        ChangeJsonUtil::ModifyObject(jsonArgs, index);
557c804472Sopenharmony_ci        // 保存到文件
567c804472Sopenharmony_ci        ChangeJsonUtil::WriteFile(filePath, jsonArgs);
577c804472Sopenharmony_ci        cJSON_Delete(jsonArgs);
587c804472Sopenharmony_ci        // 执行接口
597c804472Sopenharmony_ci        OHOS::Ide::StageContext::GetInstance().GetHspAceModuleBuild(filePath);
607c804472Sopenharmony_ci    }
617c804472Sopenharmony_ci    DT_FUZZ_END()
627c804472Sopenharmony_ci    printf("end ---- GetHspAceModuleBuildFuzzTest\r\n");
637c804472Sopenharmony_ci    if (DT_GetIsPass() == 0) {
647c804472Sopenharmony_ci        printf("test GetHspAceModuleBuildFuzzTest is not ok\r\n");
657c804472Sopenharmony_ci    } else {
667c804472Sopenharmony_ci        printf("test GetHspAceModuleBuildFuzzTest is ok\r\n");
677c804472Sopenharmony_ci    }
687c804472Sopenharmony_ci    std::cout << "--> GetHspAceModuleBuildFuzzTest for common end <--" << std::endl;
697c804472Sopenharmony_ci}
707c804472Sopenharmony_ci}