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

« back to all changes in this revision

Viewing changes to testsuite/inline-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
;;; inline function test
 
3
;;;
 
4
 
 
5
(use gauche.test)
 
6
 
 
7
(test-start "c-wrapper (inline)")
 
8
(use c-wrapper)
 
9
 
 
10
(c-load-library "libc")
 
11
(c-load-library "./ffitest")
 
12
(c-include '("stdio.h" "stdlib.h" "./ffitest.h"))
 
13
 
 
14
(test "constant"
 
15
      1
 
16
      (lambda ()
 
17
        (return_const)))
 
18
 
 
19
(test "string"
 
20
      "foo"
 
21
      (lambda ()
 
22
        (x->string (return_string))))
 
23
 
 
24
(test "ref array"
 
25
      10
 
26
      (lambda ()
 
27
        (let ((a (make (c-array <c-int> 3))))
 
28
          (set! (ref a 0) 0)
 
29
          (set! (ref a 1) 10)
 
30
          (set! (ref a 2) 20)
 
31
          (ref_array a))))
 
32
 
 
33
(test "func call without argument"
 
34
      '(-2 -1 0 1 2)
 
35
      (lambda ()
 
36
        (funccall1)
 
37
        (list (ref test_array 0)
 
38
              (ref test_array 1)
 
39
              (ref test_array 2)
 
40
              (ref test_array 3)
 
41
              (ref test_array 4))))
 
42
 
 
43
(test "func call with arguments"
 
44
      3
 
45
      (lambda ()
 
46
        (funcall2 1 2)))
 
47
 
 
48
(test "ref struct (. operator)"
 
49
      1
 
50
      (lambda ()
 
51
        (ref_struct1)))
 
52
 
 
53
(test "ref struct (-> operator)"
 
54
      1
 
55
      (lambda ()
 
56
        (let ((a (make (c-struct 'test_sint))))
 
57
          (set! (ref a 'value) 1)
 
58
          (ref_struct2 (ptr a)))))
 
59
 
 
60
 
 
61
(test "post increment"
 
62
      2
 
63
      (lambda ()
 
64
        (post_inc)))
 
65
 
 
66
(test "post decrement"
 
67
      1
 
68
      (lambda ()
 
69
        (post_dec)))
 
70
 
 
71
(test "pre increment"
 
72
      2
 
73
      (lambda ()
 
74
        (pre_inc)))
 
75
 
 
76
(test "pre decrement"
 
77
      1
 
78
      (lambda ()
 
79
        (pre_dec)))
 
80
 
 
81
(test "unary plus"
 
82
      1
 
83
      (lambda ()
 
84
        (unary_plus)))
 
85
 
 
86
(test "unary minus"
 
87
      -1
 
88
      (lambda ()
 
89
        (unary_minus)))
 
90
 
 
91
(test "unary logical negation"
 
92
      '(0 1)
 
93
      (lambda ()
 
94
        (list (unary_logneg 1) (unary_logneg 0))))
 
95
 
 
96
(test "unary bitwise negation"
 
97
      -2
 
98
      (lambda ()
 
99
        (unary_bitneg 1)))
 
100
 
 
101
(test "unary reference"
 
102
      123
 
103
      (lambda ()
 
104
        (unary_ref)))
 
105
 
 
106
(test "unary dereference"
 
107
      456
 
108
      (lambda ()
 
109
        (ref (deref (unary_deref)))))
 
110
 
 
111
(test "sizeof"
 
112
      #t
 
113
      (lambda ()
 
114
        (eq? (c-sizeof <c-int>) (op_sizeof))))
 
115
 
 
116
(test "mul"
 
117
      6
 
118
      (lambda ()
 
119
        (mul 2 3)))
 
120
 
 
121
(test "divi"
 
122
      3
 
123
      (lambda ()
 
124
        (divi 18 6)))
 
125
 
 
126
(test "mod"
 
127
      1
 
128
      (lambda ()
 
129
        (mod 5 2)))
 
130
 
 
131
(test "add"
 
132
      3
 
133
      (lambda ()
 
134
        (add 1 2)))
 
135
 
 
136
(test "sub"
 
137
      -1
 
138
      (lambda ()
 
139
        (sub 1 2)))
 
140
 
 
141
(test "left shift"
 
142
      4
 
143
      (lambda ()
 
144
        (left_shift 1 2)))
 
145
 
 
146
(test "right shift"
 
147
      2
 
148
      (lambda ()
 
149
        (right_shift 8 2)))
 
150
 
 
151
(test "lesser than"
 
152
      '(1 0 0)
 
153
      (lambda  ()
 
154
        (list (op_lt 1 2) (op_lt 2 2) (op_lt 2 1))))
 
155
 
 
156
(test "greater than"
 
157
      '(0 0 1)
 
158
      (lambda  ()
 
159
        (list (op_gt 1 2) (op_gt 2 2) (op_gt 2 1))))
 
160
 
 
161
(test "lesser than or equal" 
 
162
      '(1 1 0)
 
163
      (lambda  ()
 
164
        (list (op_lteq 1 2) (op_lteq 2 2) (op_lteq 2 1))))
 
165
 
 
166
(test "greater than or equal"
 
167
      '(0 1 1)
 
168
      (lambda  ()
 
169
        (list (op_gteq 1 2) (op_gteq 2 2) (op_gteq 2 1))))
 
170
 
 
171
(test "equal"
 
172
      '(0 1 0)
 
173
      (lambda  ()
 
174
        (list (op_eq 1 2) (op_eq 2 2) (op_eq 2 1))))
 
175
 
 
176
(test "not equal"
 
177
      '(1 0 1)
 
178
      (lambda  ()
 
179
        (list (op_noteq 1 2) (op_noteq 2 2) (op_noteq 2 1))))
 
180
 
 
181
(test "bitwise and"
 
182
      1
 
183
      (lambda ()
 
184
        (bitand 11 5)))
 
185
 
 
186
(test "bitwise or"
 
187
      15
 
188
      (lambda ()
 
189
        (bitor 11 5)))
 
190
 
 
191
(test "bitwise xor"
 
192
      14
 
193
      (lambda ()
 
194
        (bitxor 11 5)))
 
195
 
 
196
(test "logical and"
 
197
      '(1 0 0 0)
 
198
      (lambda ()
 
199
        (list (op_logand 1 1 1)
 
200
              (op_logand 1 1 0)
 
201
              (op_logand 0 1 1)
 
202
              (op_logand 0 1 0))))
 
203
 
 
204
(test "logical or"
 
205
      '(1 1 1 0)
 
206
      (lambda ()
 
207
        (list (op_logor 1 1 1)
 
208
              (op_logor 1 1 0)
 
209
              (op_logor 0 1 1)
 
210
              (op_logor 0 1 0))))
 
211
 
 
212
(test "assign mul"
 
213
      6
 
214
      (lambda ()
 
215
        (assign_mul 2 3)))
 
216
 
 
217
(test "assign div"
 
218
      3
 
219
      (lambda ()
 
220
        (assign_div 18 6)))
 
221
 
 
222
(test "assign mod"
 
223
      1
 
224
      (lambda ()
 
225
        (assign_mod 5 2)))
 
226
 
 
227
(test "assign_add"
 
228
      3
 
229
      (lambda ()
 
230
        (assign_add 1 2)))
 
231
 
 
232
(test "assign_sub"
 
233
      -1
 
234
      (lambda ()
 
235
        (assign_sub 1 2)))
 
236
 
 
237
(test "assign left shift"
 
238
      4
 
239
      (lambda ()
 
240
        (assign_left_shift 1 2)))
 
241
 
 
242
(test "assign right shift"
 
243
      2
 
244
      (lambda ()
 
245
        (assign_right_shift 8 2)))
 
246
 
 
247
(test "assign bitwise and"
 
248
      1
 
249
      (lambda ()
 
250
        (assign_bitand 11 5)))
 
251
 
 
252
(test "assign bitwise or"
 
253
      15
 
254
      (lambda ()
 
255
        (assign_bitor 11 5)))
 
256
 
 
257
(test "assign bitwise xor"
 
258
      14
 
259
      (lambda ()
 
260
        (assign_bitxor 11 5)))
 
261
 
 
262
(test "multi expr"
 
263
      10
 
264
      (lambda ()
 
265
        (multi_expr 2 5)))
 
266
 
 
267
(test "while"
 
268
      55
 
269
      (lambda ()
 
270
        (test_while)))
 
271
               
 
272
(test "while break"
 
273
      55
 
274
      (lambda ()
 
275
        (test_while_break)))
 
276
               
 
277
(test "while continue"
 
278
      55
 
279
      (lambda ()
 
280
        (test_while_continue)))
 
281
               
 
282
(test "do while"
 
283
      55
 
284
      (lambda ()
 
285
        (test_dowhile)))
 
286
               
 
287
(test "do while break"
 
288
      55
 
289
      (lambda ()
 
290
        (test_dowhile_break)))
 
291
               
 
292
(test "do while continue"
 
293
      0
 
294
      (lambda ()
 
295
        (test_dowhile_continue)))
 
296
               
 
297
(test "for"
 
298
      55
 
299
      (lambda ()
 
300
        (test_for)))
 
301
               
 
302
(test "for noinit, notest, noupdate"
 
303
      55
 
304
      (lambda ()
 
305
        (test_for_noinit_notest_noupdate)))
 
306
               
 
307
(test "for noinit, notest"
 
308
      55
 
309
      (lambda ()
 
310
        (test_for_noinit_notest)))
 
311
               
 
312
(test "for noinit, noupdate"
 
313
      55
 
314
      (lambda ()
 
315
        (test_for_noinit_noupdate)))
 
316
               
 
317
(test "for noinit"
 
318
      55
 
319
      (lambda ()
 
320
        (test_for_noinit_noupdate)))
 
321
 
 
322
(test "for notest, noupdate"
 
323
      55
 
324
      (lambda ()
 
325
        (test_for_notest_noupdate)))
 
326
               
 
327
(test "for notest"
 
328
      55
 
329
      (lambda ()
 
330
        (test_for_notest)))
 
331
               
 
332
(test "for noupdate"
 
333
      55
 
334
      (lambda ()
 
335
        (test_for_noupdate)))
 
336
 
 
337
(test "offset"
 
338
      #t
 
339
      (lambda ()
 
340
        (eq? (offset_calc) (c-offsetof (c-struct 'test_uchar) 'value))))
 
341
 
 
342
(test "not_supported"
 
343
      #t
 
344
      (lambda ()
 
345
        (procedure? not_supported)))
 
346
 
 
347
;; epilogue
 
348
(test-end)
 
349