1/* 2* Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development 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*/ 15const { Farther, Cat, Bob, Juliya, Tom, TestMember } = require("./out/build/Release/napitest") 16const test = require("./out/build/Release/napitest") 17var assert = require("assert"); 18const { consumers } = require("stream"); 19 20describe('Basic extends', function () { 21 function getSkinCallback (skin) { 22 assert.strictEqual(skin, ''); 23 } 24 function getSkinAsyncCallback (err, skin) { 25 assert.strictEqual(err.code, 0); 26 assert.strictEqual(skin, ''); 27 } 28 function getShoesCallback (shoes) { 29 assert.strictEqual(shoes, ''); 30 } 31 function getShoesAsyncCallback (err, shoes) { 32 assert.strictEqual(err.code, 0); 33 assert.strictEqual(shoes, ''); 34 } 35 it('test interface extends', function () { 36 let farther = new Farther(); 37 assert.strictEqual(farther.name, ''); 38 assert.strictEqual(farther.age, 0); 39 assert.strictEqual(farther.getSkin(1), ''); 40 farther.getSkinSync(1, getSkinCallback); 41 farther.getSkinAsync(1, getSkinAsyncCallback); 42 assert.strictEqual(farther.getShoes(), ''); 43 farther.getShoesSync(getShoesCallback); 44 farther.getShoesAsync(getShoesAsyncCallback); 45 }); 46 47 it('test class extends', function () { 48 let cat = new Cat(); 49 assert.strictEqual(cat.aniName, ''); 50 assert.strictEqual(cat.size, 0); 51 assert.strictEqual(cat.catName, ''); 52 assert.strictEqual(cat.getAnimalType(1), ''); 53 assert.strictEqual(cat.setAnimalId(1), undefined); 54 assert.strictEqual(cat.getCatType(1), ''); 55 }); 56}); 57 58describe('Multi extends', function () { 59 it('test interface extends', function () { 60 let bob = new Bob(); 61 assert.strictEqual(bob.name, ''); 62 assert.strictEqual(bob.aniName, ''); 63 assert.strictEqual(bob.bobSkill, ''); 64 assert.strictEqual(bob.getAnimalType(1), ''); 65 assert.strictEqual(bob.getBobCardId(), 0); 66 }); 67 68 it('test extends and implements', function () { 69 let juliya = new Juliya(); 70 assert.strictEqual(juliya.name, ''); 71 assert.strictEqual(juliya.aniName, ''); 72 assert.strictEqual(juliya.juliyaSkill, ''); 73 assert.strictEqual(juliya.getAnimalType(1), ''); 74 assert.strictEqual(juliya.getJuliyaCardId(), 0); 75 }); 76}); 77 78describe('Function test1', function () { 79 it('test parameter and return', function () { 80 let juliya = new Juliya(); 81 let ret = test.findJuliya(juliya); 82 // parent properties 83 assert.strictEqual(ret.name, ''); 84 assert.strictEqual(ret.age, 0); 85 // own properties 86 assert.strictEqual(ret.aniName, ''); 87 assert.strictEqual(ret.size, 0); 88 assert.strictEqual(ret.juliyaSkill, ''); 89 }); 90}); 91 92describe('Function test2', function () { 93 it('test sync callback', function () { 94 function getSyncCallback (juliya) { 95 // parent properties 96 assert.strictEqual(juliya.name, ''); 97 assert.strictEqual(juliya.age, 0); 98 // own properties 99 assert.strictEqual(juliya.aniName, ''); 100 assert.strictEqual(juliya.size, 0); 101 assert.strictEqual(juliya.juliyaSkill, ''); 102 } 103 104 test.findJuliyaSync("juli", getSyncCallback); 105 }); 106 107 it('test async callback', function () { 108 function getAsyncCallback (err, juliya) { 109 assert.strictEqual(err.code, 0); 110 // parent properties 111 assert.strictEqual(juliya.name, ''); 112 assert.strictEqual(juliya.age, 0); 113 // own properties 114 assert.strictEqual(juliya.aniName, ''); 115 assert.strictEqual(juliya.size, 0); 116 assert.strictEqual(juliya.juliyaSkill, ''); 117 } 118 119 test.findJuliyaAsync("juli", getAsyncCallback); 120 }); 121 122}); 123 124describe('Interface member test', function () { 125 it('test member', function () { 126 let tomObj1 = { 127 name: 'tom1', 128 friends: { // Cat object 129 catName: 'tomcat1', 130 aniName: 'ani1', 131 size: 101 132 } 133 }; 134 let tomObj2 = { 135 name: 'tom2', 136 friends: { // Cat object 137 catName: 'tomcat1', 138 aniName: 'ani2', 139 size: 102 140 } 141 }; 142 let tomArray = [tomObj1, tomObj2]; 143 let test = new TestMember(); 144 let retTom = test.getTomcat('my tom', tomArray); 145 assert.strictEqual(retTom.name, ''); 146 // class member 147 assert.strictEqual(retTom.friends.catName, ''); 148 assert.strictEqual(retTom.friends.aniName, ''); 149 assert.strictEqual(retTom.friends.size, 0); 150 }); 151 152}); 153 154 155 156