1/** 2 * Copyright (c) 2021-2025 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 16function assertEq(a, b) { 17 if (a !== b) { 18 throw Error(`assertEq failed: '${a}' == '${b}'`); 19 } 20} 21 22const helper = requireNapiPreview('libinterop_test_helper.so', false); 23const gtestAbcPath = helper.getEnvironmentVar('ARK_ETS_INTEROP_JS_GTEST_ABC_PATH'); 24const stdlibPath = helper.getEnvironmentVar('ARK_ETS_STDLIB_PATH'); 25 26globalThis.etsVm = requireNapiPreview('ets_interop_js_napi.so', false); 27 28function runTest() { 29 const etsOpts = { 30 'log-level': 'error', 31 'log-components': 'ets_interop_js', 32 'boot-panda-files': stdlibPath + ':' + gtestAbcPath, 33 'panda-files': gtestAbcPath, 34 'gc-trigger-type': 'heap-trigger', 35 'compiler-enable-jit': 'false', 36 'run-gc-in-place': 'true', 37 }; 38 const createRes = etsVm.createRuntime(etsOpts); 39 if (!createRes) { 40 throw Error('Failed to create ETS runtime'); 41 } 42 43 const Color = etsVm.getClass('Lstatic_enum_test/Color;'); 44 let red = Color.RED; 45 assertEq(Color.RED.valueOf(), 1); 46 assertEq(Color.GREEN.valueOf(), 2); 47 assertEq(Color.YELLOW.valueOf(), 3); 48 assertEq(Color.BLACK.valueOf(), 4); 49 assertEq(Color.BLUE.valueOf(), 5); 50 51 const Level = etsVm.getClass('Lstatic_enum_test/Level;'); 52 assertEq(Level.DEBUG.valueOf(), 'Debug'); 53 assertEq(Level.RELEASE.valueOf(), 'Release'); 54} 55 56runTest(); 57