• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 { TestClass1 } = require("./out/build/Release/napitest")
16const testObj = require("./out/build/Release/napitest")
17var assert = require("assert");
18
19function onCallback (ret) {
20    assert.strictEqual(ret, 0);
21}
22
23function onVoidCallback (ret) {
24    assert.strictEqual(ret, undefined);
25}
26
27function onAsyncCallback (err, ret) {
28    assert.strictEqual(err.code, 0);
29    assert.strictEqual(ret, 0);
30}
31
32function onVoidAsyncCallback (err, ret) {
33    assert.strictEqual(err.code, 0);
34    assert.strictEqual(ret, undefined);
35}
36
37describe('Test callback', function () {
38    it('test callback in interface', function () {
39        let testClass = new TestClass1();
40        testClass.fun11(onCallback);
41        testClass.fun12(onVoidCallback);
42        testClass.fun13(onAsyncCallback);
43        testClass.fun14(onVoidAsyncCallback);
44    });
45
46    it('test common func callback', function () {
47        let testClass = new TestClass1();
48        testObj.fun1(onCallback);
49        testObj.fun2(onVoidCallback);
50        testObj.fun3(onAsyncCallback);
51        testObj.fun4(onVoidAsyncCallback);
52    });
53});
54
55