1 /* 2 * Copyright (c) 2022 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 #include "js_util.h" 16 #include "securec.h" 17 18 #define OHOS_ABILITY_RUNTIME_ABILITY_H 19 #define ABILITY_RUNTIME_NAPI_BASE_CONTEXT_H 20 #define DISTRIBUTEDDATAMGR_ENDIAN_CONVERTER_H 21 #define FOUNDATION_APPEXECFWK_INTERFACES_INNERKITS_APPEXECFWK_BASE_INCLUDE_HAP_MODULE_INFO_H 22 23 #ifdef LOG_TAG 24 #undef LOG_TAG 25 #endif 26 27 #define be32toh(data) data 28 #define be64toh(data) data 29 #define htobe32(data) data 30 #define htobe64(data) data 31 32 #define GetCurrentAbility(env) GetAbility() 33 34 #ifdef _WIN32 35 #define mkdir(dir, mode) mkdir(dir) 36 #endif 37 38 #ifdef _MACOS 39 #define memcpy_s(t, tLen, s, sLen) memcpy(t, s, std::min(tLen, sLen)) 40 #endif 41 42 constexpr mode_t MODE = 0755; 43 44 class AbilityMock { 45 public: 46 47 AbilityMock() = default; 48 49 ~AbilityMock() = default; 50 51 struct ModuleInfo { 52 std::string moduleName = "com.example.myapplication"; 53 }; 54 55 struct ApplicationInfo { 56 bool isSystemApp = true; 57 }; 58 59 class ContextMock { 60 public: GetArea()61 int GetArea() 62 { 63 return OHOS::DistributedKv::Area::EL1; 64 }; 65 GetDatabaseDir()66 std::string GetDatabaseDir() 67 { 68 #ifdef _WIN32 69 std::string baseDir = getenv("TEMP"); 70 #else 71 std::string baseDir = getenv("LOGNAME"); 72 baseDir = "/Users/" + baseDir + "/Library/Caches"; 73 #endif 74 baseDir = baseDir + "/HuaweiDevEcoStudioDatabases"; 75 mkdir(baseDir.c_str(), MODE); 76 return baseDir; 77 } 78 GetHapModuleInfo()79 std::shared_ptr<ModuleInfo> GetHapModuleInfo() 80 { 81 return std::make_shared<ModuleInfo>(); 82 } 83 GetApplicationInfo()84 std::shared_ptr<ApplicationInfo> GetApplicationInfo() 85 { 86 return std::make_shared<ApplicationInfo>(); 87 } 88 }; 89 GetAbilityContext()90 std::shared_ptr<ContextMock> GetAbilityContext() 91 { 92 return std::make_shared<ContextMock>(); 93 } 94 }; 95 96 namespace AbilityRuntime { GetAbility()97 std::shared_ptr<AbilityMock> GetAbility() 98 { 99 return std::make_shared<AbilityMock>(); 100 } 101 } 102 103 #include "frameworks/jskitsimpl/distributedkvstore/src/js_util.cpp" 104