forked from livecode/livecode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobjc.lcb
More file actions
152 lines (113 loc) · 4.13 KB
/
objc.lcb
File metadata and controls
152 lines (113 loc) · 4.13 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
/*
Copyright (C) 2018 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.objc.tests
use com.livecode.objc
use com.livecode.foreign
use com.livecode.__INTERNAL._testlib
handler RoundTripString(in pString as String) returns String
variable tNSString as ObjcObject
put StringToNSString(pString) into tNSString
return StringFromNSString(tNSString)
end handler
public handler TestRoundTripNSString()
if not the operating system is in ["mac", "ios"] then
skip test "string round trips through objc" because "not implemented on" && the operating system
return
end if
variable tString as String
put "lcb string" into tString
test "string round trips through objc" when \
RoundTripString(tString) is tString
test "empty string round trips through objc" when \
RoundTripString("") is ""
end handler
handler RoundTripData(in pData as Data) returns Data
variable tNSData as ObjcObject
put DataToNSData(pData) into tNSData
return DataFromNSData(tNSData)
end handler
public handler TestRoundTripNSData()
if not the operating system is in ["mac", "ios"] then
skip test "data round trips through objc" because "not implemented on" && the operating system
return
end if
variable tData as Data
put 20 random bytes into tData
test "data round trips through objc" when \
RoundTripData(tData) is tData
test "empty data round trips through objc" when \
RoundTripData(the empty data) is the empty data
end handler
public handler TestRoundTripNSNumber()
if not the operating system is in ["mac", "ios"] then
skip test "number round trips through objc" because "not implemented on" && the operating system
return
end if
variable tNumber as Number
put any number into tNumber
variable tNSNumber as ObjcObject
put NumberToNSNumber(tNumber) into tNSNumber
variable tNewNumber as Number
put NumberFromNSNumber(tNSNumber) into tNewNumber
test "number round trips through objc" when tNewNumber is tNumber
end handler
handler RoundTripList(in pList as List) returns List
variable tNSArray as ObjcObject
put ListToNSArray(pList) into tNSArray
return ListFromNSArray(tNSArray)
end handler
public handler TestRoundTripNSArray()
if not the operating system is in ["mac", "ios"] then
skip test "list round trips through objc" because "not implemented on" && the operating system
return
end if
variable tList as List
put [1,2,3,4,5] into tList
test "list round trips through objc" when \
RoundTripList(tList) is tList
test "empty list round trips through objc" when \
RoundTripList([]) is []
end handler
handler RoundTripArray(in pArray as Array) returns Array
variable tNSDictionary as ObjcObject
put ArrayToNSDictionary(pArray) into tNSDictionary
return ArrayFromNSDictionary(tNSDictionary)
end handler
handler ArrayIsEqual(in pLeft as Array, in pRight as Array) returns Boolean
variable tKey as String
repeat for each key tKey in pLeft
if tKey is not among the keys of pRight or \
pLeft[tKey] is not pRight[tKey] then
return false
end if
end repeat
repeat for each key tKey in pRight
if tKey is not among the keys of pLeft then
return false
end if
end repeat
return true
end handler
public handler TestRoundTripNSDictionary()
if not the operating system is in ["mac", "ios"] then
skip test "array round trips through objc" because "not implemented on" && the operating system
return
end if
variable tArray as Array
put {"key":"value"} into tArray
test "array round trips through objc" when \
ArrayIsEqual(RoundTripArray(tArray), tArray)
test "empty array round trips through objc" when \
ArrayIsEqual(RoundTripArray({}), {})
end handler
end module