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 <fstream> 19#include <iostream> 20#include <gtest/gtest.h> 21#include <filesystem> 22#include "cJSON.h" 23#include "secodeFuzz.h" 24#include "common.h" 25#include "ChangeJsonUtil.h" 26#include "StageContext.h" 27#include "MockFile.h" 28using namespace testmock; 29using namespace fuzztest; 30 31namespace { 32TEST(GetModuleBufferFromHspFuzzTest, test_json) 33{ 34 std::cout << "--> GetModuleBufferFromHspFuzzTest for common start <--" << std::endl; 35 DT_FUZZ_START(0, TEST_TIMES, (char*)"GetModuleBufferFromHspFuzzTest", 0) 36 { 37 // 变化数据 38 const int defaultLength = 1000; 39 const std::string defaultString = "aaaa"; 40 std::string strVal = DT_SetGetString(&g_Element[0], defaultString.size() + 1, defaultLength, 41 (char*)defaultString.c_str()); 42 std::string newFileName = MockFile::CreateHspFile("testHspFile", strVal); 43 // 执行接口 44 OHOS::Ide::StageContext::GetInstance().GetModuleBufferFromHsp("aaa", "bbb"); 45 OHOS::Ide::StageContext::GetInstance().GetModuleBufferFromHsp(newFileName, "bbb.txt"); 46 std::vector<uint8_t>* buf = 47 OHOS::Ide::StageContext::GetInstance().GetModuleBufferFromHsp(newFileName, "ets/modules.abc"); 48 if (buf) { 49 delete buf; 50 } 51 } 52 DT_FUZZ_END() 53 printf("end ---- GetModuleBufferFromHspFuzzTest\r\n"); 54 if (DT_GetIsPass() == 0) { 55 printf("test GetModuleBufferFromHspFuzzTest is not ok\r\n"); 56 } else { 57 printf("test GetModuleBufferFromHspFuzzTest is ok\r\n"); 58 } 59 std::cout << "--> GetModuleBufferFromHspFuzzTest for common end <--" << std::endl; 60} 61}