This repository was archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathjava.lcb
More file actions
371 lines (280 loc) · 11.4 KB
/
java.lcb
File metadata and controls
371 lines (280 loc) · 11.4 KB
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
/*
Copyright (C) 2015-2016 LiveCode Ltd.
This file is part of LiveCode.
LiveCode is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License v3 as published by the Free
Software Foundation.
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
module com.livecode.java.tests
use com.livecode.java
use com.livecode.foreign
use com.livecode.__INTERNAL._testlib
foreign handler CreateJavaObject() returns JObject binds to "java:java.lang.Object>new()"
public handler TestCreateJObject()
if not the operating system is in ["mac", "linux"] then
skip test "java object creation succeeds" because "not implemented on" && the operating system
return
end if
if the operating system is "linux" then
skip test "java object creation succeeds" because "bug 19934"
return
end if
variable tObj as JObject
unsafe
put CreateJavaObject() into tObj
end unsafe
test "java object creation succeeds" when \
GetJavaClassName(tObj) is "java.lang.Object"
end handler
foreign handler CreateJavaString(in pBytes as JByteArray) returns JString binds to "java:java.lang.String>new([B)"
foreign handler MCDataCreateWithBytes(in pBytes as ZStringNative, in pCount as LCUIndex, out rData as Data) returns CBool binds to "<builtin>"
public handler TestCreateJString()
if not the operating system is in ["mac", "linux"] then
skip test "java string creation succeeds" because "not implemented on" && the operating system
return
end if
if the operating system is "linux" then
skip test "java string creation succeeds" because "bug 19934"
return
end if
plan 1 tests
unsafe
variable tData as Data
if not MCDataCreateWithBytes("lcbstring", 9, tData) then
test diagnostic "failed to create data"
return
end if
variable tByteArray as JByteArray
put DataToJByteArray(tData) into tByteArray
variable tJString as JString
put CreateJavaString(tByteArray) into tJString
variable tString as String
put StringFromJString(tJString) into tString
test "create java string and convert to lcb string" \
when tString is "lcbstring"
end unsafe
end handler
public handler TestRoundTripJString()
if not the operating system is in ["mac", "linux"] then
skip test "string round trips through java" because "not implemented on" && the operating system
return
end if
if the operating system is "linux" then
skip test "string round trips through java" because "bug 19934"
return
end if
variable tString as String
put "lcb string" into tString
variable tJString as JObject
put StringToJString(tString) into tJString
variable tNewString as String
put StringFromJString(tJString) into tNewString
test "string round trips through java" when tNewString is tString
end handler
public handler TestRoundTripJByteArray()
if not the operating system is in ["mac", "linux"] then
skip test "data round trips through java" because "not implemented on" && the operating system
return
end if
if the operating system is "linux" then
skip test "data round trips through java" because "bug 19934"
return
end if
variable tData as Data
put 20 random bytes into tData
variable tJavaBytes as JByteArray
put DataToJByteArray(tData) into tJavaBytes
variable tNewData as Data
put DataFromJByteArray(tJavaBytes) into tNewData
test "data round trips through java" when tNewData is tData
end handler
foreign handler GetJavaPi() returns CDouble binds to "java:java.lang.Math>get.PI()D!static"
public handler TestGetConstant()
if not the operating system is in ["mac", "linux"] then
skip test "get java class constant" because "not implemented on" && the operating system
return
end if
if the operating system is "linux" then
skip test "get java class constant" because "bug 19934"
return
end if
variable tPiTrunc as Number
unsafe
put the trunc of GetJavaPi() into tPiTrunc
end unsafe
test "get java class constant" \
when tPiTrunc is 3
end handler
foreign handler CallJavaAdd(in pLeft as JLong, in pRight as JLong) returns JLong binds to "java:java.lang.Math>addExact(JJ)J!static"
public handler TestCallStaticMethod()
if not the operating system is in ["mac", "linux"] then
skip test "call java class static method" because "not implemented on" && the operating system
return
end if
if the operating system is "linux" then
skip test "call java class static method" because "bug 19934"
return
end if
variable tLeft as Number
variable tRight as Number
put 1 into tLeft
put 1 into tRight
variable tResult as Number
unsafe
put CallJavaAdd(tLeft, tRight) into tResult
end unsafe
test "call java class static method" when tResult is 2
end handler
foreign handler JavaStringIsEmpty(in pString as JString) returns JBoolean binds to "java:java.lang.String>isEmpty()Z"
public handler TestCallInstanceMethod()
if not the operating system is in ["mac", "linux"] then
skip test "call java class instance method" because "not implemented on" && the operating system
return
end if
if the operating system is "linux" then
skip test "call java class instance method" because "bug 19934"
return
end if
variable tJavaString as JString
put StringToJString("nonempty") into tJavaString
variable tResult as Boolean
unsafe
put JavaStringIsEmpty(tJavaString) into tResult
end unsafe
test "call java class instance method" when tResult is false
end handler
foreign handler JavaGetDefaultLocale() returns JObject binds to "java:java.util.Locale>getDefault()Ljava/util/Locale;!static"
foreign handler JavaLocaleDisplayName(in pLocale as JObject) returns JObject binds to "java:java.util.Locale>getDisplayName()Ljava/lang/String;"
public handler TestDefaultLocaleDisplayName()
if not the operating system is in ["mac", "linux"] then
skip test "get locale display name" because "not implemented on" && the operating system
return
end if
if the operating system is "linux" then
skip test "get locale display name" because "bug 19934"
return
end if
variable tDisplay as JString
unsafe
variable tLocale as JObject
put JavaGetDefaultLocale() into tLocale
put JavaLocaleDisplayName(tLocale) into tDisplay
end unsafe
test "get locale display name" when StringFromJString(tDisplay) is not empty
end handler
foreign handler CreateJavaCurrencyWithCode(in pString as JString) returns JObject binds to "java:java.util.Currency>getInstance(Ljava/lang/String;)Ljava/util/Currency;!static"
public handler TestCreateCurrencyWithCode()
if not the operating system is in ["mac", "linux"] then
skip test "currency created" because "not implemented on" && the operating system
return
end if
if the operating system is "linux" then
skip test "currency created" because "bug 19934"
return
end if
-- Create a new Currency object
variable tCurrency as JObject
unsafe
variable tCode as JString
put StringToJString("AMD") into tCode
put CreateJavaCurrencyWithCode(tCode) into tCurrency
end unsafe
test "currency created" when GetJavaClassName(tCurrency) is "java.util.Currency"
end handler
foreign handler JavaCreateEmptyList() returns JObject binds to "java:java.util.LinkedList>new()"
foreign handler JavaPeekList(in pList as JObject) returns JObject binds to "java:java.util.LinkedList>peek()Ljava/lang/Object;"
foreign handler JavaAddList(in pList as JObject, in pToAdd as JObject) returns JBoolean binds to "java:java.util.LinkedList>add(Ljava/lang/Object;)Z"
foreign handler JavaAddListOptional(in pList as JObject, in pToAdd as optional JObject) returns JBoolean binds to "java:java.util.LinkedList>add(Ljava/lang/Object;)Z"
public handler NullIntoOptionalJObject()
unsafe
variable tList as JObject
put JavaCreateEmptyList() into tList
variable tElt as optional JObject
put JavaPeekList(tList) into tElt
end unsafe
end handler
public handler NullIntoJObject()
unsafe
variable tList as JObject
put JavaCreateEmptyList() into tList
variable tElt as JObject
put JavaPeekList(tList) into tElt
end unsafe
end handler
public handler TestNullJObjectReturn()
if not the operating system is in ["mac", "linux"] then
skip test "NULL into optional JObject" because "not implemented on" && the operating system
return
end if
if the operating system is "linux" then
skip test "NULL into optional JObject" because "bug 19934"
return
end if
MCUnitTestHandlerDoesntThrow(NullIntoOptionalJObject, "no error when putting NULL into optional JObject")
MCUnitTestHandlerThrows(NullIntoJObject, "type mismatch when putting NULL into non-optional JObject")
end handler
public handler NullParamOptionalJObject()
unsafe
variable tList as JObject
put JavaCreateEmptyList() into tList
JavaAddListOptional(tList, nothing)
end unsafe
end handler
public handler NullParamJObject()
unsafe
variable tList as JObject
put JavaCreateEmptyList() into tList
JavaAddList(tList, nothing)
end unsafe
end handler
public handler TestNullJObjectParam()
if not the operating system is in ["mac", "linux"] then
skip test "NULL passed as optional JObject" because "not implemented on" && the operating system
return
end if
if the operating system is "linux" then
skip test "NULL passed as optional JObject" because "bug 19934"
return
end if
MCUnitTestHandlerDoesntThrow(NullParamOptionalJObject, "no error when passing NULL as optional JObject")
MCUnitTestHandlerThrows(NullParamJObject, "type mismatch when passing NULL as non-optional JObject")
end handler
foreign handler StringCodepointAt(in pSequence as JObject, in pIndex as JInt) returns JInt binds to "java:java.lang.Character>codePointAt(Ljava/lang/CharSequence;I)I!static"
public handler TestNativeTypeAfterObjectType()
if not the operating system is in ["mac", "linux"] then
skip test "called foreign handler with signature Ljava/lang/CharSequence;I" because "not implemented on" && the operating system
return
end if
if the operating system is "linux" then
skip test "called foreign handler with signature Ljava/lang/CharSequence;I" because "bug 19934"
return
end if
unsafe
variable tCodepoint as Integer
put StringCodepointAt(StringToJString("a"), 0) into tCodepoint
test "called foreign handler with signature Ljava/lang/CharSequence;I" when tCodepoint is 97
end unsafe
end handler
__safe foreign handler RegionMatches(in pString as JString, in pCaseless as JBoolean, in pOffset as JInt, in pOther as JString, in pOtherOffset as JInt, in pLength as JInt) returns JBoolean binds to "java:java.lang.String>regionMatches(ZILjava/lang/String;II)Z"
public handler TestBindingStringObjectTypeInMiddle()
if not the operating system is in ["mac", "linux"] then
skip test "called foreign handler with signature Ljava/lang/CharSequence;I" because "not implemented on" && the operating system
return
end if
if the operating system is "linux" then
skip test "called foreign handler with signature Ljava/lang/CharSequence;I" because "bug 19934"
return
end if
variable tString as JString
put StringToJString("something") into tString
variable tOther as JString
put StringToJString("NOTHING") into tOther
test "called foreign handler with signature (ZILjava/lang/String;II)Z" when \
RegionMatches(tString, true, 4, tOther, 2, 5)
end handler
end module