aboutsummaryrefslogtreecommitdiff
path: root/Examples/test-suite/javascript/li_std_pair_runme.js
blob: 97bd97049fc6a58ab1091e31c909b2c8306c494b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
var li_std_pair = require("li_std_pair");

function check(flag) {
    if (!flag) {
        throw new Error("Check failed");
    }
}

intPair = li_std_pair.makeIntPair(7, 6);
check(typeof intPair === 'object');
if (Object.keys(intPair).length) {
    // When using raw V8, intPair will be an object with two properties
    check(Object.keys(intPair).length == 2);
} else {
    // When using NAPI, intPair will be an object of class intPair whose
    // prototype will have two properties
    check(Object.keys(Object.getPrototypeOf(intPair)).length == 2);
}
check(intPair.first === 7);
check(intPair.second === 6);

intPairConstRef = li_std_pair.makeIntPairConstRef(7, 6);
check(typeof intPairConstRef === 'object');
check(intPairConstRef.first === 7);
check(intPairConstRef.second === 6);

//
// Each of these should return a reference to a wrapped
// std:: pair < int, int > object(i.e.an intPair instance).
intPairPtr = li_std_pair.makeIntPairPtr(7, 6);
check(typeof intPairPtr === 'object');
check(intPairPtr.first === 7);
check(intPairPtr.second === 6);

intPairRef = li_std_pair.makeIntPairRef(7, 6);
check(typeof intPairRef === 'object');
check(intPairRef.first === 7);
check(intPairRef.second === 6);

// Now test various input typemaps.Each of the wrapped C++ functions
//(product1, product2 and product3) is expecting an argument of a
// different type(see li_std_pair.i).Typemaps should be in place to
// convert this tuple into the expected argument type.
check(li_std_pair.product1(intPair) === 42);
check(li_std_pair.product2(intPair) === 42);
// check(product3(intPair) == 42) # TODO, if (desirable to match Ruby wrappers behaviour.Requires equivalent to typemap(in) std:: pair * in Lib / ruby / std_pair.i and further fixes to stop recursive calls to swig:) {asptr which this testcase shows.Plus further changes for any type of sequence type(including other STL containers) to be accepted by all methods taking an STL container to match Ruby behaviour.

//
// Similarly, each of the input typemaps should know what to do
// with an intPair instance.
check(li_std_pair.product1(intPairPtr) === 42);
check(li_std_pair.product2(intPairPtr) === 42);
check(li_std_pair.product3(intPairPtr) === 42);