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 <fstream> 197c804472Sopenharmony_ci#include <iostream> 207c804472Sopenharmony_ci#include <gtest/gtest.h> 217c804472Sopenharmony_ci#include <filesystem> 227c804472Sopenharmony_ci#include "cJSON.h" 237c804472Sopenharmony_ci#include "secodeFuzz.h" 247c804472Sopenharmony_ci#include "common.h" 257c804472Sopenharmony_ci#include "ChangeJsonUtil.h" 267c804472Sopenharmony_ci#include "StageContext.h" 277c804472Sopenharmony_ci#include "MockFile.h" 287c804472Sopenharmony_ciusing namespace testmock; 297c804472Sopenharmony_ciusing namespace fuzztest; 307c804472Sopenharmony_ci 317c804472Sopenharmony_cinamespace { 327c804472Sopenharmony_ciTEST(GetModuleBufferFromHspFuzzTest, test_json) 337c804472Sopenharmony_ci{ 347c804472Sopenharmony_ci std::cout << "--> GetModuleBufferFromHspFuzzTest for common start <--" << std::endl; 357c804472Sopenharmony_ci DT_FUZZ_START(0, TEST_TIMES, (char*)"GetModuleBufferFromHspFuzzTest", 0) 367c804472Sopenharmony_ci { 377c804472Sopenharmony_ci // 变化数据 387c804472Sopenharmony_ci const int defaultLength = 1000; 397c804472Sopenharmony_ci const std::string defaultString = "aaaa"; 407c804472Sopenharmony_ci std::string strVal = DT_SetGetString(&g_Element[0], defaultString.size() + 1, defaultLength, 417c804472Sopenharmony_ci (char*)defaultString.c_str()); 427c804472Sopenharmony_ci std::string newFileName = MockFile::CreateHspFile("testHspFile", strVal); 437c804472Sopenharmony_ci // 执行接口 447c804472Sopenharmony_ci OHOS::Ide::StageContext::GetInstance().GetModuleBufferFromHsp("aaa", "bbb"); 457c804472Sopenharmony_ci OHOS::Ide::StageContext::GetInstance().GetModuleBufferFromHsp(newFileName, "bbb.txt"); 467c804472Sopenharmony_ci std::vector<uint8_t>* buf = 477c804472Sopenharmony_ci OHOS::Ide::StageContext::GetInstance().GetModuleBufferFromHsp(newFileName, "ets/modules.abc"); 487c804472Sopenharmony_ci if (buf) { 497c804472Sopenharmony_ci delete buf; 507c804472Sopenharmony_ci } 517c804472Sopenharmony_ci } 527c804472Sopenharmony_ci DT_FUZZ_END() 537c804472Sopenharmony_ci printf("end ---- GetModuleBufferFromHspFuzzTest\r\n"); 547c804472Sopenharmony_ci if (DT_GetIsPass() == 0) { 557c804472Sopenharmony_ci printf("test GetModuleBufferFromHspFuzzTest is not ok\r\n"); 567c804472Sopenharmony_ci } else { 577c804472Sopenharmony_ci printf("test GetModuleBufferFromHspFuzzTest is ok\r\n"); 587c804472Sopenharmony_ci } 597c804472Sopenharmony_ci std::cout << "--> GetModuleBufferFromHspFuzzTest for common end <--" << std::endl; 607c804472Sopenharmony_ci} 617c804472Sopenharmony_ci}