1 /** 2 * Copyright (c) 2021-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 #ifndef PANDA_PLUGINS_ETS_TESTS_MOCK_MOCK_TEST_HELPER_H 17 #define PANDA_PLUGINS_ETS_TESTS_MOCK_MOCK_TEST_HELPER_H 18 19 #include <gtest/gtest.h> 20 #include <gmock/gmock.h> 21 22 #include "plugins/ets/runtime/napi/ets_scoped_objects_fix.h" 23 24 namespace ark::ets::test { 25 26 class MockEtsNapiTestBaseClass : public testing::Test { 27 protected: 28 MockEtsNapiTestBaseClass() = default; MockEtsNapiTestBaseClass(const char * fileName)29 explicit MockEtsNapiTestBaseClass(const char *fileName) : testBinFileName_(fileName) {}; 30 SetUpTestCase()31 static void SetUpTestCase() 32 { 33 if (std::getenv("PANDA_STD_LIB") == nullptr) { 34 std::cerr << "PANDA_STD_LIB not set" << std::endl; 35 std::abort(); 36 } 37 } 38 SetUp()39 void SetUp() override 40 { 41 std::vector<EtsVMOption> optionsVector; 42 43 optionsVector = {{EtsOptionType::ETS_GC_TYPE, "epsilon"}, 44 {EtsOptionType::ETS_NO_JIT, nullptr}, 45 {EtsOptionType::ETS_BOOT_FILE, std::getenv("PANDA_STD_LIB")}}; 46 47 if (testBinFileName_ != nullptr) { 48 optionsVector.push_back({EtsOptionType::ETS_BOOT_FILE, testBinFileName_}); 49 } 50 51 EtsVMInitArgs vmArgs; 52 vmArgs.version = ETS_NAPI_VERSION_1_0; 53 vmArgs.options = optionsVector.data(); 54 vmArgs.nOptions = static_cast<ets_int>(optionsVector.size()); 55 56 ASSERT_TRUE(ETS_CreateVM(&vm_, &env_, &vmArgs) == ETS_OK) << "Cannot create ETS VM"; 57 } 58 TearDown()59 void TearDown() override 60 { 61 ASSERT_TRUE(vm_->DestroyEtsVM() == ETS_OK) << "Cannot destroy ETS VM"; 62 } 63 64 // NOLINTBEGIN(misc-non-private-member-variables-in-classes) 65 const char *testBinFileName_ {nullptr}; 66 EtsEnv *env_ {nullptr}; 67 EtsVM *vm_ {nullptr}; 68 // NOLINTEND(misc-non-private-member-variables-in-classes) 69 }; 70 71 } // namespace ark::ets::test 72 73 #endif // PANDA_PLUGINS_ETS_TESTS_MOCK_MOCK_TEST_HELPER_H 74