Continue the work on the wrap
[scilab.git] / scilab / modules / external_objects_java / tests / unit_tests / jwrap.tst
1 // =============================================================================
2 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 // Copyright (C) 2013 - Scilab Enterprises - Sylvestre Ledru
4 //
5 //  This file is distributed under the same license as the Scilab package.
6 // =============================================================================
7
8
9 myString=jwrap("foo");
10 assert_checkequal(jgetclassname(myString),"java.lang.String");
11
12 a=jwrap(2);
13 assert_checkequal(typeof(a),"_EObj");
14 assert_checkequal(jgetclassname(a),"double");
15 b=junwrap(a);
16 assert_checkequal(typeof(b),"constant");
17
18
19 c = jcompile("Test", ["public class Test {";
20     "public int[] returnArrayInt() {";
21     "    return new int[]{1,2,3,4};";
22     "}";
23     "}";]);
24 t = c.new();
25 assert_checkequal(jgetclassname(c),"Test");
26 assert_checkequal(int32([1,2,3,4]), t.returnArrayInt());
27
28 c = jcompile("Test", ["public class Test {";
29     "public int returnInt() {";
30     "    return 32;";
31     "}";
32     "}";]);
33 t = c.new();
34 assert_checkequal(jgetclassname(c),"Test");
35 assert_checkequal(int32(32), t.returnInt());
36
37 //////////////////////////////////////////////
38
39 c = jcompile("Test", ["public class Test {";
40     "public double[] returnDouble() {";
41     "    return new double[]{1,2,3,4};";
42     "}";
43     "}";]);
44 t = c.new();
45 assert_checkequal(jgetclassname(c),"Test");
46 assert_checkequal([1,2,3,4], t.returnDouble());
47
48 c = jcompile("Test", ["public class Test {";
49     "public double returnDouble() {";
50     "    return 32;";
51     "}";
52     "}";]);
53 t = c.new();
54 assert_checkequal(jgetclassname(c),"Test");
55 assert_checkequal(32, t.returnDouble());
56
57 //////////////////////////////////////////////
58
59 c = jcompile("Test", ["public class Test {";
60     "public byte[] returnByte() {";
61     "    return new byte[]{1,2,3,4};";
62     "}";
63     "}";]);
64 t = c.new();
65 assert_checkequal(jgetclassname(c),"Test");
66 assert_checkequal(int8([1,2,3,4]), t.returnByte());
67
68 c = jcompile("Test", ["public class Test {";
69     "public byte returnByte() {";
70     "    return 32;";
71     "}";
72     "}";]);
73 t = c.new();
74 assert_checkequal(jgetclassname(c),"Test");
75 assert_checkequal(int8(32), t.returnByte());
76
77 //////////////////////////////////////////////
78
79 c = jcompile("Test", ["public class Test {";
80     "public short[] returnShort() {";
81     "    return new short[]{1,2,3,4};";
82     "}";
83     "}";]);
84 t = c.new();
85 assert_checkequal(jgetclassname(c),"Test");
86 assert_checkequal(int16([1,2,3,4]), t.returnShort());
87
88 c = jcompile("Test", ["public class Test {";
89     "public short returnShort() {";
90     "    return 32;";
91     "}";
92     "}";]);
93 t = c.new();
94 assert_checkequal(jgetclassname(c),"Test");
95 assert_checkequal(int16(32), t.returnShort());
96
97
98 //////////////////////////////////////////////
99
100 // c = jcompile("Test", ["public class Test {";
101 //     "public long[] returnLong() {";
102 //     "    return new long[]{1L,2L,3L,4L};";
103 //     "}";
104 //     "}";]);
105 // t = c.new();
106 // assert_checkequal(jgetclassname(c),"Test");
107 // assert_checkequal(int16([1,2,3,4]), t.returnLong());
108
109 // c = jcompile("Test", ["public class Test {";
110 //     "public long returnLong() {";
111 //     "    return 32L;";
112 //     "}";
113 //     "}";]);
114 // t = c.new();
115 // assert_checkequal(jgetclassname(c),"Test");
116 // assert_checkequal(int16(32), t.returnLong());
117
118 //////////////////////////////////////////////
119
120 // c = jcompile("Test", ["public class Test {";
121 //     "public float[] returnFloat() {";
122 //     "    return new float[]{1f,2f,3f,4f};";
123 //     "}";
124 //     "}";]);
125 // t = c.new();
126 // assert_checkequal(jgetclassname(c),"Test");
127 // assert_checkequal(int16([1,2,3,4]), t.returnFloat());
128
129 // c = jcompile("Test", ["public class Test {";
130 //     "public float returnFloat() {";
131 //     "    return 32f;";
132 //     "}";
133 //     "}";]);
134 // t = c.new();
135 // assert_checkequal(jgetclassname(c),"Test");
136 // assert_checkequal(int16(32), t.returnFloat());
137
138
139 //////////////////////////////////////////////
140
141 // c = jcompile("Test", ["public class Test {";
142 //     "public char[] returnChar() {";
143 //     "    return new char[]{''a'',''b'',''c'',''d''};";
144 //     "}";
145 //     "}";]);
146 // t = c.new();
147 // assert_checkequal(jgetclassname(c),"Test");
148 // assert_checkequal(['a','b','c','d'], t.returnChar());
149
150 // c = jcompile("Test", ["public class Test {";
151 //     "public char returnChar() {";
152 //     "    return ''a'';";
153 //     "}";
154 //     "}";]);
155 // t = c.new();
156 // assert_checkequal(jgetclassname(c),"Test");
157 // assert_checkequal(int16(32), t.returnChar());
158 //
159
160
161 //////////////////////////////////////////////
162
163 c = jcompile("Test", ["public class Test {";
164     "public boolean[] returnBoolean() {";
165     "    return new boolean[]{true,true,false,false};";
166     "}";
167     "}";]);
168 t = c.new();
169 assert_checkequal(jgetclassname(c),"Test");
170 assert_checkequal([%t,%t,%f,%f], t.returnBoolean());
171
172 c = jcompile("Test", ["public class Test {";
173     "public boolean returnBoolean() {";
174     "    return true;";
175     "}";
176     "}";]);
177 t = c.new();
178 assert_checkequal(jgetclassname(c),"Test");
179 assert_checkequal(%t, t.returnBoolean());
180