~ubuntu-branches/ubuntu/lucid/gauche-c-wrapper/lucid

« back to all changes in this revision

Viewing changes to testsuite/objc-test.scm

  • Committer: Bazaar Package Importer
  • Author(s): NIIBE Yutaka
  • Date: 2008-04-07 09:15:03 UTC
  • Revision ID: james.westby@ubuntu.com-20080407091503-wu0h414koe95kj4i
Tags: upstream-0.5.2
ImportĀ upstreamĀ versionĀ 0.5.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
;;;
 
2
;;; Test objc-wrapper
 
3
;;;
 
4
 
 
5
(use gauche.test)
 
6
 
 
7
(test-start "objc-wrapper")
 
8
(use objc-wrapper)
 
9
(use gauche.sequence)
 
10
(test-module 'objc-wrapper)
 
11
 
 
12
(c-load-framework "Foundation")
 
13
(c-load-library "./objc-test")
 
14
(c-include "./objc-test.h")
 
15
 
 
16
[[NSAutoreleasePool 'alloc] 'init]
 
17
(define obj [[OBJCTest 'alloc] 'init])
 
18
 
 
19
(test "staticMethod"
 
20
      5
 
21
      (lambda ()
 
22
        [OBJCTest 'staticMethod]))
 
23
 
 
24
(test "incrementUnsignedChar:"
 
25
      3
 
26
      (lambda ()
 
27
        [obj :incrementUnsignedChar 2]))
 
28
 
 
29
(test "incrementSignedChar:"
 
30
      -3
 
31
      (lambda ()
 
32
        [obj :incrementSignedChar -4]))
 
33
 
 
34
(test "incrementUnsignedShort:"
 
35
      4
 
36
      (lambda ()
 
37
        [obj :incrementUnsignedShort 3]))
 
38
 
 
39
(test "incrementSignedShort:"
 
40
      -4
 
41
      (lambda ()
 
42
        [obj :incrementSignedShort -5]))
 
43
 
 
44
(test "incrementUnsignedInt:"
 
45
      5
 
46
      (lambda ()
 
47
        [obj :incrementUnsignedInt 4]))
 
48
 
 
49
(test "incrementSignedInt:"
 
50
      -5
 
51
      (lambda ()
 
52
        [obj :incrementSignedInt -6]))
 
53
 
 
54
(test "incrementUnsignedLong:"
 
55
      6
 
56
      (lambda ()
 
57
        [obj :incrementUnsignedLong 5]))
 
58
 
 
59
(test "incrementSignedLong:"
 
60
      -6
 
61
      (lambda ()
 
62
        [obj :incrementSignedLong -7]))
 
63
 
 
64
(test "incrementUnsignedLongLong:"
 
65
      7
 
66
      (lambda ()
 
67
        [obj :incrementUnsignedLongLong 6]))
 
68
 
 
69
(test "incrementSignedLongLong:"
 
70
      -7
 
71
      (lambda ()
 
72
        [obj :incrementSignedLongLong -8]))
 
73
 
 
74
(test "addFloat:and:"
 
75
      1.5
 
76
      (lambda ()
 
77
        [obj :addFloat 1.0 :and 0.5]))
 
78
 
 
79
(test "addDouble:and:"
 
80
      -1.5
 
81
      (lambda ()
 
82
        [obj :addDouble -1.0 :and -0.5]))
 
83
 
 
84
(test "appendString:and:"
 
85
      YES
 
86
      (lambda ()
 
87
        (let ((str [obj :appendString (@ "foo") :and (@ "bar")]))
 
88
          [str :isEqualToString (@ "foobar")])))
 
89
 
 
90
(test "addLargeStruct:valA:valB:"
 
91
      '(2 3)
 
92
      (lambda ()
 
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))))))
 
98
 
 
99
(test "addSmallStruct:valA:valB:"
 
100
      '(2 3)
 
101
      (lambda ()
 
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))))))
 
107
 
 
108
(test "addLargeUnion:valA:"
 
109
      2
 
110
      (lambda ()
 
111
        (let ((data (make <TestLargeUnion>)))
 
112
          (set! (ref data 'a) 3)
 
113
          (let ((ret [obj :addLargeUnion data :valA -1]))
 
114
            (ref ret 'a)))))
 
115
 
 
116
(test "addSmallUnion:valA:"
 
117
      2
 
118
      (lambda ()
 
119
        (let ((data (make <TestSmallUnion>)))
 
120
          (set! (ref data 'a) 3)
 
121
          (let ((ret [obj :addSmallUnion data :valA -1]))
 
122
            (ref ret 'a)))))
 
123
 
 
124
(test "overwriteData:"
 
125
      '(1 2)
 
126
      (lambda ()
 
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)))))
 
132
 
 
133
(test "inline function (return NSString)"
 
134
      YES
 
135
      (lambda ()
 
136
        [(returnString) :isEqualToString (@ "foo")]))
 
137
 
 
138
(test "inline function (invoke method)"
 
139
      YES
 
140
      (lambda ()
 
141
        [(inlineAppendString (@ "foo") (@ "bar")) :isEqualToString (@ "foobar")]))
 
142
 
 
143
(test "inline function (selector)"
 
144
      #t
 
145
      (lambda ()
 
146
        (equal? (@selector "init") (inlineSelector))))
 
147
 
 
148
 
 
149
(define-objc-class MyTest NSObject)
 
150
 
 
151
(define-objc-method MyTest <c-int> (:addA (v1 <c-int>) :addB (v2 <c-int>))
 
152
  (+ v1 v2))
 
153
 
 
154
(define *cnt* 0)
 
155
 
 
156
(define-objc-class MyTest2 NSObject)
 
157
 
 
158
(define-objc-method MyTest2 <id> (:init)
 
159
  [super :init]
 
160
  (set! *cnt* (+ *cnt* 2))
 
161
  self)
 
162
 
 
163
(define-objc-method MyTest2 <id> (:myString)
 
164
  (@ "foo"))
 
165
 
 
166
(define-objc-class MyTest3 MyTest2)
 
167
 
 
168
(define-objc-method MyTest3 <id> (:init)
 
169
  [super :init]
 
170
  (set! *cnt* (* *cnt* 3))
 
171
  self)
 
172
 
 
173
(define-objc-method MyTest3 <id> (:myString)
 
174
  [[super :myString] :stringByAppendingString (@ "bar")])
 
175
          
 
176
 
 
177
(test "define objc-class and method(1)"
 
178
      5
 
179
      (lambda ()
 
180
        (let ((obj [[MyTest :alloc] :init]))
 
181
          [obj :addA 2 :addB 3])))
 
182
 
 
183
(test "define objc-class and method(2)"
 
184
      (list 6 YES)
 
185
      (lambda ()
 
186
        (let ((obj [[MyTest3 :alloc] :init]))
 
187
          (list *cnt*
 
188
                [[obj :myString] :isEqualToString (@ "foobar")]))))
 
189
 
 
190
;; epilogue
 
191
(test-end)
 
192