| 1 |
;; Testing C API features that aren't accesible from Scheme by default. |
| 2 |
;; This script nees to be run with the special "test-extra" executable |
| 3 |
;; in ../src directory. |
| 4 |
|
| 5 |
(use gauche.test) |
| 6 |
|
| 7 |
(test-start "some C API features") |
| 8 |
|
| 9 |
(test-section "foreign pointer") |
| 10 |
|
| 11 |
(let* ([obj (cons 'a 'a)] [obj2 (cons 'b 'b)]) |
| 12 |
|
| 13 |
;; See KEEP_IDENTITY |
| 14 |
(test* "identity preservation" '(#f #t #f) |
| 15 |
(list (eq? (make-fptr-simple obj) (make-fptr-simple obj)) |
| 16 |
(eq? (make-fptr-unique obj) (make-fptr-unique obj)) |
| 17 |
(eq? (make-fptr-unique obj) (make-fptr-unique obj2)))) |
| 18 |
|
| 19 |
;; See MAP_NULL flag maps (void*)0 to #f, not #<fptr 0>. |
| 20 |
(test* "map-null" '(#t #f) |
| 21 |
(list (boolean (make-fptr-maybe obj)) |
| 22 |
(boolean (make-fptr-maybe #f)))) |
| 23 |
|
| 24 |
;; Foreign pointer attributes |
| 25 |
(test* "foreign pointer attrs 1" '((a . b)) |
| 26 |
(foreign-pointer-attributes (make-fptr-simple #f '((a . b))))) |
| 27 |
|
| 28 |
(test* "foreign pointer attrs get" 'b |
| 29 |
(let1 x (make-fptr-simple #f '((a . b))) |
| 30 |
(foreign-pointer-attribute-get x 'a))) |
| 31 |
(test* "foreign pointer attrs get (error)" (test-error) |
| 32 |
(let1 x (make-fptr-simple #f '((a . b))) |
| 33 |
(foreign-pointer-attribute-get x 'b))) |
| 34 |
(test* "foreign pointer attrs get (fallback)" 'z |
| 35 |
(let1 x (make-fptr-simple #f '((a . b))) |
| 36 |
(foreign-pointer-attribute-get x 'b 'z))) |
| 37 |
(test* "foreign pointer attrs set" '(d b) |
| 38 |
(let1 x (make-fptr-simple #f '()) |
| 39 |
(foreign-pointer-attribute-set! x 'a 'b) |
| 40 |
(foreign-pointer-attribute-set! x 'c 'd) |
| 41 |
(list (foreign-pointer-attribute-get x 'c) |
| 42 |
(foreign-pointer-attribute-get x 'a)))) |
| 43 |
(test* "foreign pointer attrs replacement" 'c |
| 44 |
(let1 x (make-fptr-simple #f (list (cons 'a 'b))) |
| 45 |
(foreign-pointer-attribute-set! x 'a 'c) |
| 46 |
(foreign-pointer-attribute-get x 'a))) |
| 47 |
|
| 48 |
|
| 49 |
) |
| 50 |
|
| 51 |
(test-section "path substitution") |
| 52 |
|
| 53 |
(test* "substitute_all" "abcXYZdefXYZ@XYZghi" |
| 54 |
(substitute-all "abc@^def@^@@^ghi" |
| 55 |
"@^" |
| 56 |
"XYZ")) |
| 57 |
(test* "substitute_all" "XYZ@@abcXYZ" |
| 58 |
(substitute-all "@@@@@abc@@@" |
| 59 |
"@@@" |
| 60 |
"XYZ")) |
| 61 |
|
| 62 |
(test-end) |