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 225
Expand file tree
/
Copy pathforeign.lcb
More file actions
173 lines (144 loc) · 4.78 KB
/
foreign.lcb
File metadata and controls
173 lines (144 loc) · 4.78 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
/*
Copyright (C) 2015 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.foreign.tests
use com.livecode.foreign
use com.livecode.__INTERNAL._testlib
----------
handler TestZStringNative_Null()
variable tList as ZStringNative
put "\u{0}" into tList
end handler
public handler TestZStringNative()
-- bug 14826
-- Check that strings containing embedded nuls can't be
-- bridged.
MCUnitTestHandlerThrows(TestZStringNative_Null, "ZStringNative (nulls)")
end handler
handler TestZStringUTF16_Null()
variable tList as ZStringUTF16
put "\u{0}" into tList
end handler
public handler TestZStringUTF16()
variable tUTF16 as ZStringUTF16
variable tInternal as String
-- Test round-trip bridging
put "\u{fffd}" into tUTF16
test "ZStringUTF16 (round-trip)" when tUTF16 is "\u{fffd}"
-- bug 14826
-- Check that strings containing embedded nuls can't be
-- bridged.
MCUnitTestHandlerThrows(TestZStringUTF16_Null, "ZStringUTF16 (nulls)")
end handler
----------
private foreign handler printf_int(in pFormat as ZStringNative, in pValue as LCInt) returns nothing binds to "printf"
private foreign handler printf_uint(in pFormat as ZStringNative, in pValue as LCUInt) returns nothing binds to "printf"
private foreign handler printf_intsize(in pFormat as ZStringNative, in pValue as IntSize) returns nothing binds to "printf"
private foreign handler printf_uintsize(in pFormat as ZStringNative, in pValue as UIntSize) returns nothing binds to "printf"
foreign handler MCHandlerTryToInvokeWithList(in Handler as any, inout Arguments as optional List, out Result as optional any) returns optional any binds to "<builtin>"
private handler __Is64Bit() returns nothing
variable tSize as UIntSize
put 4294967296.0 into tSize
unsafe
printf_uintsize("", tSize)
end unsafe
end handler
private handler Is64Bit()
variable tResult as optional any
variable tArguments as optional List
variable tError as optional any
put [] into tArguments
unsafe
put MCHandlerTryToInvokeWithList(__Is64Bit, tArguments, tResult) into tError
end unsafe
return tError is nothing
end handler
handler TestIntRange_Min()
variable tInt as LCInt
put -2147483649.0 into tInt
unsafe
printf_int("", tInt)
end unsafe
end handler
handler TestIntRange_Max()
variable tInt as LCInt
put 2147483648.0 into tInt
unsafe
printf_int("", tInt)
end unsafe
end handler
handler TestUIntRange_Min()
variable tUInt as LCUInt
put -1.0 into tUInt
unsafe
printf_uint("", tUInt)
end unsafe
end handler
handler TestUIntRange_Max()
variable tUInt as LCUInt
put 4294967296.0 into tUInt
unsafe
printf_uint("", tUInt)
end unsafe
end handler
handler TestIntSizeRange_Min()
variable tInt as IntSize
if Is64Bit() then
put -9007199254740994.0 into tInt
else
put -2147483649.0 into tInt
end if
unsafe
printf_intsize("", tInt)
end unsafe
end handler
handler TestIntSizeRange_Max()
variable tInt as IntSize
if Is64Bit() then
put 9007199254740994.0 into tInt
else
put 2147483648.0 into tInt
end if
unsafe
printf_intsize("", tInt)
end unsafe
end handler
handler TestUIntSizeRange_Min()
variable tUInt as UIntSize
put -1.0 into tUInt
unsafe
printf_uintsize("", tUInt)
end unsafe
end handler
handler TestUIntSizeRange_Max()
variable tUInt as UIntSize
if Is64Bit() then
test diagnostic "64-bit"
put 9007199254740994.0 into tUInt
else
put 4294967296.0 into tUInt
end if
unsafe
printf_uintsize("", tUInt)
end unsafe
end handler
public handler TestForeignIntRanges()
MCUnitTestHandlerThrows(TestIntRange_Min, "LCInt minimum value")
MCUnitTestHandlerThrows(TestIntRange_Max, "LCInt maximum value")
MCUnitTestHandlerThrows(TestUIntRange_Min, "LCUInt minimum value")
MCUnitTestHandlerThrows(TestUIntRange_Max, "LCUInt maximum value")
MCUnitTestHandlerThrows(TestIntSizeRange_Min, "IntSize minimum value")
MCUnitTestHandlerThrows(TestIntSizeRange_Max, "IntSize maximum value")
MCUnitTestHandlerThrows(TestUIntSizeRange_Min, "UIntSize minimum value")
MCUnitTestHandlerThrows(TestUIntSizeRange_Max, "UIntSize maximum value")
end handler
end module