7
(test-start "objc-wrapper")
10
(test-module 'objc-wrapper)
12
(c-load-framework "Foundation")
13
(c-load-library "./objc-test")
14
(c-include "./objc-test.h")
16
[[NSAutoreleasePool 'alloc] 'init]
17
(define obj [[OBJCTest 'alloc] 'init])
22
[OBJCTest 'staticMethod]))
24
(test "incrementUnsignedChar:"
27
[obj :incrementUnsignedChar 2]))
29
(test "incrementSignedChar:"
32
[obj :incrementSignedChar -4]))
34
(test "incrementUnsignedShort:"
37
[obj :incrementUnsignedShort 3]))
39
(test "incrementSignedShort:"
42
[obj :incrementSignedShort -5]))
44
(test "incrementUnsignedInt:"
47
[obj :incrementUnsignedInt 4]))
49
(test "incrementSignedInt:"
52
[obj :incrementSignedInt -6]))
54
(test "incrementUnsignedLong:"
57
[obj :incrementUnsignedLong 5]))
59
(test "incrementSignedLong:"
62
[obj :incrementSignedLong -7]))
64
(test "incrementUnsignedLongLong:"
67
[obj :incrementUnsignedLongLong 6]))
69
(test "incrementSignedLongLong:"
72
[obj :incrementSignedLongLong -8]))
77
[obj :addFloat 1.0 :and 0.5]))
79
(test "addDouble:and:"
82
[obj :addDouble -1.0 :and -0.5]))
84
(test "appendString:and:"
87
(let ((str [obj :appendString (@ "foo") :and (@ "bar")]))
88
[str :isEqualToString (@ "foobar")])))
90
(test "addLargeStruct:valA:valB:"
93
(let ((data (make <TestLarge>)))
94
(set! (ref data 'a) 3)
95
(set! (ref data 'b) 2)
96
(let ((ret [obj :addLargeStruct data :valA -1 :valB 1]))
97
(list (ref ret 'a) (ref ret 'b))))))
99
(test "addSmallStruct:valA:valB:"
102
(let ((data (make <TestSmall>)))
103
(set! (ref data 'a) 3)
104
(set! (ref data 'b) 2)
105
(let ((ret [obj :addSmallStruct data :valA -1 :valB 1]))
106
(list (ref ret 'a) (ref ret 'b))))))
108
(test "addLargeUnion:valA:"
111
(let ((data (make <TestLargeUnion>)))
112
(set! (ref data 'a) 3)
113
(let ((ret [obj :addLargeUnion data :valA -1]))
116
(test "addSmallUnion:valA:"
119
(let ((data (make <TestSmallUnion>)))
120
(set! (ref data 'a) 3)
121
(let ((ret [obj :addSmallUnion data :valA -1]))
124
(test "overwriteData:"
127
(let ((data (make <TestLarge>)))
128
(set! (ref data 'a) 3)
129
(set! (ref data 'b) 2)
130
[obj :overwriteData (ptr data)]
131
(list (ref data 'a) (ref data 'b)))))
133
(test "inline function (return NSString)"
136
[(returnString) :isEqualToString (@ "foo")]))
138
(test "inline function (invoke method)"
141
[(inlineAppendString (@ "foo") (@ "bar")) :isEqualToString (@ "foobar")]))
143
(test "inline function (selector)"
146
(equal? (@selector "init") (inlineSelector))))
149
(define-objc-class MyTest NSObject)
151
(define-objc-method MyTest <c-int> (:addA (v1 <c-int>) :addB (v2 <c-int>))
156
(define-objc-class MyTest2 NSObject)
158
(define-objc-method MyTest2 <id> (:init)
160
(set! *cnt* (+ *cnt* 2))
163
(define-objc-method MyTest2 <id> (:myString)
166
(define-objc-class MyTest3 MyTest2)
168
(define-objc-method MyTest3 <id> (:init)
170
(set! *cnt* (* *cnt* 3))
173
(define-objc-method MyTest3 <id> (:myString)
174
[[super :myString] :stringByAppendingString (@ "bar")])
177
(test "define objc-class and method(1)"
180
(let ((obj [[MyTest :alloc] :init]))
181
[obj :addA 2 :addB 3])))
183
(test "define objc-class and method(2)"
186
(let ((obj [[MyTest3 :alloc] :init]))
188
[[obj :myString] :isEqualToString (@ "foobar")]))))