summaryrefslogtreecommitdiff
path: root/js/test/Ice/defaultValue/Client.js
blob: 400a5bc3b43312e7b2ffefa4b3ec8ff2d4e6b687 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
// **********************************************************************
//
// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************

(function(module, require, exports)
{
    var Ice = require("icejs").Ice;
    var Test = require("Test").Test;
    var Promise = Ice.Promise;

    var run = function(out, id)
    {
        var p = new Ice.Promise();
        var test = function(b)
        {
            if(!b)
            {
                try
                {
                    throw new Error("test failed");
                }
                catch(err)
                {
                    p.fail(err);
                    throw err;
                }
            }
        };
        
        Promise.try(
            function()
            {
                out.write("testing default values... ");
                var v = new Test.Struct1();
                test(!v.boolFalse);
                test(v.boolTrue);
                test(v.b === 254);
                test(v.s === 16000);
                test(v.i === 3);
                test(v.l.equals(new Ice.Long(0, 4)));
                test(v.f === 5.1);
                test(v.d === 6.2);
                test(v.str === "foo \\ \"bar\n \r\n\t\u000b\f\u0007\b?");
                test(v.c1 === Test.Color.red);
                test(v.c2 === Test.Color.green);
                test(v.c3 === Test.Color.blue);
                test(v.nc1 === Test.Nested.Color.red);
                test(v.nc2 === Test.Nested.Color.green);
                test(v.nc3 === Test.Nested.Color.blue);
                test(v.noDefault === null);
                test(v.zeroI === 0);
                test(v.zeroL.equals(new Ice.Long(0, 0)));
                test(v.zeroF === 0);
                test(v.zeroDotF === 0);
                test(v.zeroD === 0);
                test(v.zeroDotD === 0);
                
                v = new Test.Struct2();
                test(v.boolTrue === Test.ConstBool);
                test(v.b === Test.ConstByte);
                test(v.s === Test.ConstShort);
                test(v.i === Test.ConstInt);
                test(v.l.equals(Test.ConstLong));
                test(v.f === Test.ConstFloat);
                test(v.d === Test.ConstDouble);
                test(v.str ==  Test.ConstString);
                test(v.c1 === Test.ConstColor1);
                test(v.c2 === Test.ConstColor2);
                test(v.c3 === Test.ConstColor3);
                test(v.nc1 === Test.ConstNestedColor1);
                test(v.nc2 === Test.ConstNestedColor2);
                test(v.nc3 === Test.ConstNestedColor3);
                
                v = new Test.Base();
                test(!v.boolFalse);
                test(v.boolTrue);
                test(v.b === 1);
                test(v.s === 2);
                test(v.i === 3);
                test(v.l.equals(new Ice.Long(0, 4)));
                test(v.f === 5.1);
                test(v.d === 6.2);
                test(v.str == "foo \\ \"bar\n \r\n\t\u000b\f\u0007\b?");
                test(v.noDefault === null);
                test(v.zeroI === 0);
                test(v.zeroL.equals(new Ice.Long(0, 0)));
                test(v.zeroF === 0);
                test(v.zeroDotF === 0);
                test(v.zeroD === 0);
                test(v.zeroDotD === 0);
                
                v = new Test.Derived();
                test(!v.boolFalse);
                test(v.boolTrue);
                test(v.b === 1);
                test(v.s === 2);
                test(v.i === 3);
                test(v.l.equals(new Ice.Long(0, 4)));
                test(v.f === 5.1);
                test(v.d === 6.2);
                test(v.str == "foo \\ \"bar\n \r\n\t\u000b\f\u0007\b?");
                test(v.c1 === Test.Color.red);
                test(v.c2 === Test.Color.green);
                test(v.c3 === Test.Color.blue);
                test(v.nc1 === Test.Nested.Color.red);
                test(v.nc2 === Test.Nested.Color.green);
                test(v.nc3 === Test.Nested.Color.blue);
                test(v.noDefault === null);
                test(v.zeroI === 0);
                test(v.zeroL.equals(new Ice.Long(0, 0)));
                test(v.zeroF === 0);
                test(v.zeroDotF === 0);
                test(v.zeroD === 0);
                test(v.zeroDotD === 0);
                
                v = new Test.BaseEx();
                test(!v.boolFalse);
                test(v.boolTrue);
                test(v.b === 1);
                test(v.s === 2);
                test(v.i === 3);
                test(v.l.equals(new Ice.Long(0, 4)));
                test(v.f === 5.1);
                test(v.d === 6.2);
                test(v.str == "foo \\ \"bar\n \r\n\t\u000b\f\u0007\b?");
                test(v.noDefault === null);
                test(v.zeroI === 0);
                test(v.zeroL.equals(new Ice.Long(0, 0)));
                test(v.zeroF === 0);
                test(v.zeroDotF === 0);
                test(v.zeroD === 0);
                test(v.zeroDotD === 0);
                
                v = new Test.DerivedEx();
                test(!v.boolFalse);
                test(v.boolTrue);
                test(v.b === 1);
                test(v.s === 2);
                test(v.i === 3);
                test(v.l.equals(new Ice.Long(0, 4)));
                test(v.f === 5.1);
                test(v.d === 6.2);
                test(v.str == "foo \\ \"bar\n \r\n\t\u000b\f\u0007\b?");
                test(v.noDefault === null);
                test(v.c1 === Test.Color.red);
                test(v.c2 === Test.Color.green);
                test(v.c3 === Test.Color.blue);
                test(v.nc1 === Test.Nested.Color.red);
                test(v.nc2 === Test.Nested.Color.green);
                test(v.nc3 === Test.Nested.Color.blue);
                test(v.zeroI === 0);
                test(v.zeroL.equals(new Ice.Long(0, 0)));
                test(v.zeroF === 0);
                test(v.zeroDotF === 0);
                test(v.zeroD === 0);
                test(v.zeroDotD === 0);
                
                out.writeLine("ok");
            }
        ).then(
            function()
            {
                p.succeed();
            },
            function(ex)
            {
                p.fail(ex);
            }
        );
        return p;
    };
    exports.__test__ = run;
}
(typeof(global) !== "undefined" && typeof(global.process) !== "undefined" ? module : undefined,
 typeof(global) !== "undefined" && typeof(global.process) !== "undefined" ? require : window.Ice.__require,
 typeof(global) !== "undefined" && typeof(global.process) !== "undefined" ? exports : window));