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 16function assertEq(a, b) { 17 // console.log(`assertEq: '${a}' === '${b}'`) 18 if (a !== b) { 19 console.log(`assertEq failed: '${a}' === '${b}'`); 20 process.exit(1); 21 } 22} 23 24function runTest() { 25 let etsVm = require(process.env.MODULE_PATH + '/ets_interop_js_napi.node'); 26 const etsOpts = { 27 'panda-files': process.env.ARK_ETS_INTEROP_JS_GTEST_ABC_PATH, 28 'boot-panda-files': `${process.env.ARK_ETS_STDLIB_PATH}:${process.env.ARK_ETS_INTEROP_JS_GTEST_ABC_PATH}`, 29 'gc-trigger-type': 'heap-trigger', 30 'load-runtimes': 'ets', 31 'compiler-enable-jit': 'false', 32 'enable-an': 'false', 33 'run-gc-in-place': 'true', 34 }; 35 const createRes = etsVm.createRuntime(etsOpts); 36 if (!createRes) { 37 console.log('Cannot create ETS runtime'); 38 process.exit(1); 39 } 40 41 testFunction(etsVm); 42 testValues(etsVm); 43} 44 45function testFunction(etsVm) { 46 const sumDouble = etsVm.getFunction('Lstatic_enum_test/ETSGLOBAL;', 'test1'); 47 assertEq(test1(), 0); 48 const sumString = etsVm.getFunction('Lstatic_enum_test/ETSGLOBAL;', 'test2'); 49 assertEq(test2(), true); 50} 51 52function testValues(etsVm) { 53 const Color = etsVm.getClass('Lstatic_enum_test/Color;'); 54 assertEq(Color.RED, 1); 55 assertEq(Color.GREEN, 2); 56 assertEq(Color.YELLOW, 3); 57 assertEq(Color.BLACK, 4); 58 assertEq(Color.BLUE, 5); 59 60 const Direction = etsVm.getClass('Lstatic_enum_test/Direction;'); 61 62 assertEq(Direction.Up, 1); 63 assertEq(Direction.Down, -1); 64} 65 66runTest(); 67