| 1 |
;;; foreign.test --- FFI. -*- mode: scheme; coding: utf-8; -*- |
| 2 |
;;; |
| 3 |
;;; Copyright (C) 2010-2013,2017,2021,2024 Free Software Foundation, Inc. |
| 4 |
;;; |
| 5 |
;;; This library is free software: you can redistribute it and/or modify |
| 6 |
;;; it under the terms of the GNU Lesser General Public License as |
| 7 |
;;; published by the Free Software Foundation, either version 3 of the |
| 8 |
;;; License, or (at your option) any later version. |
| 9 |
;;; |
| 10 |
;;; This library is distributed in the hope that it will be useful, but |
| 11 |
;;; WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
;;; Lesser General Public License for more details. |
| 14 |
;;; |
| 15 |
;;; You should have received a copy of the GNU Lesser General Public |
| 16 |
;;; License along with this program. If not, see |
| 17 |
;;; <http://www.gnu.org/licenses/>. |
| 18 |
|
| 19 |
;;; |
| 20 |
;;; See also ../standalone/test-ffi for FFI tests. |
| 21 |
;;; |
| 22 |
|
| 23 |
(define-module (test-foreign) |
| 24 |
#:use-module (system foreign-library) |
| 25 |
#:use-module (system foreign) |
| 26 |
#:use-module (rnrs bytevectors) |
| 27 |
#:use-module (srfi srfi-1) |
| 28 |
#:use-module (srfi srfi-26) |
| 29 |
#:use-module (ice-9 format) |
| 30 |
#:use-module (test-suite lib)) |
| 31 |
|
| 32 |
|
| 33 |
(with-test-prefix "foreign-library-pointer" |
| 34 |
|
| 35 |
(pass-if-exception |
| 36 |
"error message" |
| 37 |
;; The error comes from dlsym, which is system-dependent. |
| 38 |
'(misc-error . "") |
| 39 |
(foreign-library-pointer #f "does_not_exist___"))) |
| 40 |
|
| 41 |
|
| 42 |
(with-test-prefix "null pointer" |
| 43 |
|
| 44 |
(pass-if "pointer?" |
| 45 |
(pointer? %null-pointer)) |
| 46 |
|
| 47 |
(pass-if "zero" |
| 48 |
(= 0 (pointer-address %null-pointer))) |
| 49 |
|
| 50 |
(pass-if "null pointer identity" |
| 51 |
(eq? %null-pointer (make-pointer 0))) |
| 52 |
|
| 53 |
(pass-if "null-pointer? %null-pointer" |
| 54 |
(null-pointer? %null-pointer)) |
| 55 |
|
| 56 |
(pass-if-exception "dereference-pointer %null-pointer" |
| 57 |
exception:null-pointer-error |
| 58 |
(dereference-pointer %null-pointer)) |
| 59 |
|
| 60 |
(pass-if-exception "pointer->bytevector %null-pointer" |
| 61 |
exception:null-pointer-error |
| 62 |
(pointer->bytevector %null-pointer 7))) |
| 63 |
|
| 64 |
|
| 65 |
(with-test-prefix "make-pointer" |
| 66 |
|
| 67 |
(pass-if "pointer?" |
| 68 |
(pointer? (make-pointer 123))) |
| 69 |
|
| 70 |
(pass-if "address preserved" |
| 71 |
(= 123 (pointer-address (make-pointer 123)))) |
| 72 |
|
| 73 |
(pass-if "equal?" |
| 74 |
(equal? (make-pointer 123) (make-pointer 123))) |
| 75 |
|
| 76 |
(pass-if "equal? modulo finalizer" |
| 77 |
(let ((finalizer (false-if-exception |
| 78 |
(foreign-library-pointer #f "scm_is_pair")))) |
| 79 |
(if (not finalizer) |
| 80 |
(throw 'unresolved) ; Windows or a static build |
| 81 |
(equal? (make-pointer 123) |
| 82 |
(make-pointer 123 finalizer))))) |
| 83 |
|
| 84 |
(pass-if "equal? modulo finalizer (set-pointer-finalizer!)" |
| 85 |
(let ((finalizer (false-if-exception |
| 86 |
(foreign-library-pointer #f "scm_is_pair"))) |
| 87 |
(ptr (make-pointer 123))) |
| 88 |
(if (not finalizer) |
| 89 |
(throw 'unresolved) ; Windows or a static build |
| 90 |
(begin |
| 91 |
(set-pointer-finalizer! ptr finalizer) |
| 92 |
(equal? (make-pointer 123) ptr))))) |
| 93 |
|
| 94 |
(pass-if "not equal?" |
| 95 |
(not (equal? (make-pointer 123) (make-pointer 456))))) |
| 96 |
|
| 97 |
|
| 98 |
(with-test-prefix "pointer<->scm" |
| 99 |
|
| 100 |
(pass-if "immediates" |
| 101 |
(equal? (pointer->scm (scm->pointer #\newline)) |
| 102 |
#\newline)) |
| 103 |
|
| 104 |
(pass-if "non-immediates" |
| 105 |
(equal? (pointer->scm (scm->pointer "Hello, world!")) |
| 106 |
"Hello, world!"))) |
| 107 |
|
| 108 |
|
| 109 |
(define-wrapped-pointer-type foo |
| 110 |
foo? |
| 111 |
wrap-foo unwrap-foo |
| 112 |
(lambda (x p) |
| 113 |
(format p "#<foo! ~a>" (pointer-address (unwrap-foo x))))) |
| 114 |
|
| 115 |
(with-test-prefix "define-wrapped-pointer-type" |
| 116 |
|
| 117 |
(pass-if "foo?" |
| 118 |
(foo? (wrap-foo %null-pointer))) |
| 119 |
|
| 120 |
(pass-if "unwrap-foo" |
| 121 |
(let ((p (make-pointer 123))) |
| 122 |
(eq? p (unwrap-foo (wrap-foo p))))) |
| 123 |
|
| 124 |
(pass-if "identity" |
| 125 |
(let ((p1 (make-pointer 123)) |
| 126 |
(p2 (make-pointer 123))) |
| 127 |
(eq? (wrap-foo p1) |
| 128 |
(wrap-foo p2)))) |
| 129 |
|
| 130 |
(pass-if "printer" |
| 131 |
(string=? "#<foo! 123>" |
| 132 |
(with-output-to-string |
| 133 |
(lambda () |
| 134 |
(write (wrap-foo (make-pointer 123)))))))) |
| 135 |
|
| 136 |
|
| 137 |
(with-test-prefix "pointer<->bytevector" |
| 138 |
|
| 139 |
(pass-if "bijection" |
| 140 |
(let ((bv #vu8(0 1 2 3 4 5 6 7))) |
| 141 |
(equal? (pointer->bytevector (bytevector->pointer bv) |
| 142 |
(bytevector-length bv)) |
| 143 |
bv))) |
| 144 |
|
| 145 |
(pass-if "pointer from bits" |
| 146 |
(let* ((bytes (iota (sizeof '*))) |
| 147 |
(bv (u8-list->bytevector bytes)) |
| 148 |
(fold (case (native-endianness) |
| 149 |
((little) fold-right) |
| 150 |
((big) fold) |
| 151 |
(else (error "unsupported endianness"))))) |
| 152 |
(= (pointer-address |
| 153 |
(make-pointer (bytevector-uint-ref bv 0 (native-endianness) |
| 154 |
(sizeof '*)))) |
| 155 |
(fold (lambda (byte address) |
| 156 |
(+ byte (* 256 address))) |
| 157 |
0 |
| 158 |
bytes)))) |
| 159 |
|
| 160 |
(pass-if "dereference-pointer" |
| 161 |
(let* ((bytes (iota (sizeof '*))) |
| 162 |
(bv (u8-list->bytevector bytes)) |
| 163 |
(fold (case (native-endianness) |
| 164 |
((little) fold-right) |
| 165 |
((big) fold) |
| 166 |
(else (error "unsupported endianness"))))) |
| 167 |
(= (pointer-address |
| 168 |
(dereference-pointer (bytevector->pointer bv))) |
| 169 |
(fold (lambda (byte address) |
| 170 |
(+ byte (* 256 address))) |
| 171 |
0 |
| 172 |
bytes))))) |
| 173 |
|
| 174 |
|
| 175 |
(with-test-prefix "pointer<->string" |
| 176 |
|
| 177 |
(pass-if-exception "%default-port-conversion-strategy is error" |
| 178 |
exception:encoding-error |
| 179 |
(let ((s "χαοσ")) |
| 180 |
(with-fluids ((%default-port-conversion-strategy 'error)) |
| 181 |
(string->pointer s "ISO-8859-1")))) |
| 182 |
|
| 183 |
(pass-if "%default-port-conversion-strategy is escape" |
| 184 |
(let ((s "teĥniko")) |
| 185 |
(equal? (with-fluids ((%default-port-conversion-strategy 'escape)) |
| 186 |
(pointer->string (string->pointer s "ISO-8859-1"))) |
| 187 |
(format #f "te\\u~4,'0xniko" |
| 188 |
(char->integer #\ĥ))))) |
| 189 |
|
| 190 |
(pass-if "%default-port-conversion-strategy is substitute" |
| 191 |
(let ((s "teĥniko") |
| 192 |
(member (negate (negate member)))) |
| 193 |
(member (with-fluids ((%default-port-conversion-strategy 'substitute)) |
| 194 |
(pointer->string (string->pointer s "ISO-8859-1"))) |
| 195 |
'("te?niko" |
| 196 |
|
| 197 |
;; This form is found on FreeBSD 8.2 and Darwin 10.8.0. |
| 198 |
"te^hniko")))) |
| 199 |
|
| 200 |
(pass-if "bijection" |
| 201 |
(let ((s "hello, world")) |
| 202 |
(string=? s (pointer->string (string->pointer s))))) |
| 203 |
|
| 204 |
(pass-if "bijection [latin1]" |
| 205 |
(with-latin1-locale |
| 206 |
(let ((s "Szép jó napot!")) |
| 207 |
(string=? s (pointer->string (string->pointer s)))))) |
| 208 |
|
| 209 |
(pass-if "bijection, utf-8" |
| 210 |
(let ((s "hello, world")) |
| 211 |
(string=? s (pointer->string (string->pointer s "utf-8") |
| 212 |
-1 "utf-8")))) |
| 213 |
|
| 214 |
(pass-if "bijection, utf-8 [latin1]" |
| 215 |
(let ((s "Szép jó napot!")) |
| 216 |
(string=? s (pointer->string (string->pointer s "utf-8") |
| 217 |
-1 "utf-8"))))) |
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
(with-test-prefix "pointer->procedure" |
| 222 |
|
| 223 |
(pass-if-exception "object instead of pointer" |
| 224 |
exception:wrong-type-arg |
| 225 |
(let ((p (pointer->procedure '* %null-pointer '(*)))) |
| 226 |
(p #t)))) |
| 227 |
|
| 228 |
|
| 229 |
(with-test-prefix "procedure->pointer" |
| 230 |
|
| 231 |
(define qsort |
| 232 |
;; Bindings for libc's `qsort' function. |
| 233 |
;; On some platforms, such as MinGW, `qsort' is visible only if |
| 234 |
;; linking with `-export-dynamic'. Just skip these tests when it's |
| 235 |
;; not visible. |
| 236 |
(false-if-exception |
| 237 |
(foreign-library-function |
| 238 |
(cond |
| 239 |
((string-contains %host-type "cygwin") |
| 240 |
;; On Cygwin, load-foreign-library does not search recursively |
| 241 |
;; into linked DLLs. Thus, one needs to link to the core C |
| 242 |
;; library DLL explicitly. |
| 243 |
"cygwin1") |
| 244 |
(else #f)) |
| 245 |
"qsort" #:arg-types (list '* size_t size_t '*)))) |
| 246 |
|
| 247 |
(define (dereference-pointer-to-byte ptr) |
| 248 |
(let ((b (pointer->bytevector ptr 1))) |
| 249 |
(bytevector-u8-ref b 0))) |
| 250 |
|
| 251 |
(define input |
| 252 |
'(7 1 127 3 5 4 77 2 9 0)) |
| 253 |
|
| 254 |
(pass-if "qsort" |
| 255 |
(if (and qsort (defined? 'procedure->pointer)) |
| 256 |
(let* ((called? #f) |
| 257 |
(cmp (lambda (x y) |
| 258 |
(set! called? #t) |
| 259 |
(- (dereference-pointer-to-byte x) |
| 260 |
(dereference-pointer-to-byte y)))) |
| 261 |
(ptr (procedure->pointer int cmp (list '* '*))) |
| 262 |
(bv (u8-list->bytevector input))) |
| 263 |
(qsort (bytevector->pointer bv) (bytevector-length bv) 1 |
| 264 |
(procedure->pointer int cmp (list '* '*))) |
| 265 |
(and called? |
| 266 |
(equal? (bytevector->u8-list bv) |
| 267 |
(sort input <)))) |
| 268 |
(throw 'unresolved))) |
| 269 |
|
| 270 |
(pass-if-exception "qsort, wrong return type" |
| 271 |
exception:wrong-type-arg |
| 272 |
|
| 273 |
(if (and qsort (defined? 'procedure->pointer)) |
| 274 |
(let* ((cmp (lambda (x y) #f)) ; wrong return type |
| 275 |
(ptr (procedure->pointer int cmp (list '* '*))) |
| 276 |
(bv (u8-list->bytevector input))) |
| 277 |
(qsort (bytevector->pointer bv) (bytevector-length bv) 1 |
| 278 |
(procedure->pointer int cmp (list '* '*))) |
| 279 |
#f) |
| 280 |
(throw 'unresolved))) |
| 281 |
|
| 282 |
(pass-if-exception "qsort, wrong arity" |
| 283 |
exception:wrong-num-args |
| 284 |
|
| 285 |
(if (and qsort (defined? 'procedure->pointer)) |
| 286 |
(let* ((cmp (lambda (x y z) #f)) ; wrong arity |
| 287 |
(ptr (procedure->pointer int cmp (list '* '*))) |
| 288 |
(bv (u8-list->bytevector input))) |
| 289 |
(qsort (bytevector->pointer bv) (bytevector-length bv) 1 |
| 290 |
(procedure->pointer int cmp (list '* '*))) |
| 291 |
#f) |
| 292 |
(throw 'unresolved))) |
| 293 |
|
| 294 |
(pass-if "bijection" |
| 295 |
(if (defined? 'procedure->pointer) |
| 296 |
(let* ((proc (lambda (x y z) |
| 297 |
(+ x y z 0.0))) |
| 298 |
(ret double) |
| 299 |
(args (list float int16 double)) |
| 300 |
(proc* (pointer->procedure ret |
| 301 |
(procedure->pointer ret proc args) |
| 302 |
args)) |
| 303 |
(arg1 (map (cut / <> 2.0) (iota 123))) |
| 304 |
(arg2 (iota 123 32000)) |
| 305 |
(arg3 (map (cut / <> 4.0) (iota 123 100 4)))) |
| 306 |
(equal? (map proc arg1 arg2 arg3) |
| 307 |
(map proc* arg1 arg2 arg3))) |
| 308 |
(throw 'unresolved))) |
| 309 |
|
| 310 |
(pass-if "procedures returning a pointer" |
| 311 |
(if (defined? 'procedure->pointer) |
| 312 |
(let* ((called? #f) |
| 313 |
(proc (lambda (i) (set! called? #t) (make-pointer i))) |
| 314 |
(pointer (procedure->pointer '* proc (list int))) |
| 315 |
(proc* (pointer->procedure '* pointer (list int))) |
| 316 |
(result (proc* 777))) |
| 317 |
(and called? (equal? result (make-pointer 777)))) |
| 318 |
(throw 'unresolved))) |
| 319 |
|
| 320 |
(pass-if "procedures returning void" |
| 321 |
(if (defined? 'procedure->pointer) |
| 322 |
(let* ((called? #f) |
| 323 |
(proc (lambda () (set! called? #t))) |
| 324 |
(pointer (procedure->pointer void proc '())) |
| 325 |
(proc* (pointer->procedure void pointer '()))) |
| 326 |
(proc*) |
| 327 |
called?) |
| 328 |
(throw 'unresolved))) |
| 329 |
|
| 330 |
(pass-if "procedure is retained" |
| 331 |
;; The lambda passed to `procedure->pointer' must remain live. |
| 332 |
(if (defined? 'procedure->pointer) |
| 333 |
(let* ((ptr (procedure->pointer int |
| 334 |
(lambda (x) (+ x 7)) |
| 335 |
(list int))) |
| 336 |
(procs (unfold (cut >= <> 10000) |
| 337 |
(lambda (i) |
| 338 |
(pointer->procedure int ptr (list int))) |
| 339 |
1+ |
| 340 |
0))) |
| 341 |
(gc) (gc) (gc) |
| 342 |
(every (cut = <> 9) |
| 343 |
(map (lambda (f) (f 2)) procs))) |
| 344 |
(throw 'unresolved))) |
| 345 |
|
| 346 |
(pass-if "arity" |
| 347 |
(if (and qsort (defined? 'procedure->pointer)) |
| 348 |
(equal? '(4 0 #f) (procedure-minimum-arity qsort)) |
| 349 |
(throw 'unresolved)))) |
| 350 |
|
| 351 |
|
| 352 |
(with-test-prefix "structs" |
| 353 |
|
| 354 |
(pass-if "sizeof { int8, double }" |
| 355 |
(= (sizeof (list int8 double)) |
| 356 |
(+ (alignof double) (sizeof double)))) |
| 357 |
|
| 358 |
(pass-if "sizeof { double, int8 }" |
| 359 |
(= (sizeof (list double int8)) |
| 360 |
(+ (alignof double) (sizeof double)))) |
| 361 |
|
| 362 |
(pass-if "sizeof { short, int, long, pointer }" |
| 363 |
(let ((layout (list short int long '*))) |
| 364 |
(>= (sizeof layout) |
| 365 |
(reduce + 0.0 (map sizeof layout))))) |
| 366 |
|
| 367 |
(pass-if "alignof { int8, double, int8 }" |
| 368 |
;; alignment of the most strictly aligned component |
| 369 |
(let ((layout (list int8 double int8))) |
| 370 |
(= (alignof layout) (alignof double)))) |
| 371 |
|
| 372 |
(pass-if "parse-c-struct" |
| 373 |
(let ((layout (list int64 uint8)) |
| 374 |
(data (list -300 43))) |
| 375 |
(equal? (parse-c-struct (make-c-struct layout data) |
| 376 |
layout) |
| 377 |
data))) |
| 378 |
|
| 379 |
(pass-if "alignment constraints honored" |
| 380 |
(let ((layout (list int8 double)) |
| 381 |
(data (list -7 3.14))) |
| 382 |
(equal? (parse-c-struct (make-c-struct layout data) |
| 383 |
layout) |
| 384 |
data))) |
| 385 |
|
| 386 |
(pass-if "int8, pointer" |
| 387 |
(let ((layout (list uint8 '*)) |
| 388 |
(data (list 222 (make-pointer 7777)))) |
| 389 |
(equal? (parse-c-struct (make-c-struct layout data) |
| 390 |
layout) |
| 391 |
data))) |
| 392 |
|
| 393 |
(pass-if "unsigned-long, int8, size_t" |
| 394 |
(let ((layout (list unsigned-long int8 size_t)) |
| 395 |
(data (list (expt 2 17) -128 (expt 2 18)))) |
| 396 |
(equal? (parse-c-struct (make-c-struct layout data) |
| 397 |
layout) |
| 398 |
data))) |
| 399 |
|
| 400 |
(pass-if "long, int, pointer" |
| 401 |
(let ((layout (list long int '*)) |
| 402 |
(data (list (- (expt 2 17)) -222 (make-pointer 777)))) |
| 403 |
(equal? (parse-c-struct (make-c-struct layout data) |
| 404 |
layout) |
| 405 |
data))) |
| 406 |
|
| 407 |
(pass-if "int8, pointer, short, double" |
| 408 |
(let ((layout (list int8 '* short double)) |
| 409 |
(data (list 77 %null-pointer -42 3.14))) |
| 410 |
(equal? (parse-c-struct (make-c-struct layout data) |
| 411 |
layout) |
| 412 |
data))) |
| 413 |
|
| 414 |
(pass-if "int8, { int8, double, int8 }, int16" |
| 415 |
(let ((layout (list int8 (list int8 double int8) int16)) |
| 416 |
(data (list 77 (list 42 4.2 55) 88))) |
| 417 |
(equal? (parse-c-struct (make-c-struct layout data) |
| 418 |
layout) |
| 419 |
data))) |
| 420 |
|
| 421 |
(pass-if "complex types" |
| 422 |
(let ((layout (list complex-float int complex-double)) |
| 423 |
(data '(1+3i 99 3-1i))) |
| 424 |
(equal? data (parse-c-struct (make-c-struct layout data) |
| 425 |
layout))))) |
| 426 |
|
| 427 |
|
| 428 |
(with-test-prefix "host-type-rename?" |
| 429 |
(with-test-prefix "cyg" |
| 430 |
(pass-if "name is #f" |
| 431 |
(equal? #f (lib->cyg #f))) |
| 432 |
|
| 433 |
(pass-if "name too short" |
| 434 |
(string=? (lib->cyg "a") "a")) |
| 435 |
|
| 436 |
(pass-if "name starts with 'lib'" |
| 437 |
(string=? (lib->cyg "libfoo.dll") "cygfoo.dll")) |
| 438 |
|
| 439 |
(pass-if "name contains 'lib'" |
| 440 |
(string=? (lib->cyg "foolib.dll") "foolib.dll")) |
| 441 |
|
| 442 |
(pass-if "name doesn't contain 'lib'" |
| 443 |
(string=? (lib->cyg "foobar.dll") "foobar.dll")) |
| 444 |
|
| 445 |
(pass-if "name in path too short" |
| 446 |
(string=? (lib->cyg "/lib/a") "/lib/a")) |
| 447 |
|
| 448 |
(pass-if "name in path starts with 'lib'" |
| 449 |
(string=? (lib->cyg "/lib/libfoo.dll") "/lib/cygfoo.dll")) |
| 450 |
|
| 451 |
(pass-if "name in path contains 'lib'" |
| 452 |
(string=? (lib->cyg "/lib/foolib.dll") "/lib/foolib.dll")) |
| 453 |
|
| 454 |
(pass-if "name in path doesn't contain 'lib'" |
| 455 |
(string=? (lib->cyg "/lib/foobar.dll") "/lib/foobar.dll")) |
| 456 |
|
| 457 |
(pass-if "name in windows path starts with 'lib'" |
| 458 |
(string=? (lib->cyg "c:\\lib\\libfoo.dll") "c:\\lib\\cygfoo.dll")) |
| 459 |
|
| 460 |
(pass-if "name in windows path doesn't contain 'lib'" |
| 461 |
(string=? (lib->cyg "c:\\lib\\foobar.dll") "c:\\lib\\foobar.dll"))) |
| 462 |
|
| 463 |
(with-test-prefix "msys" |
| 464 |
|
| 465 |
(pass-if "name is #f" |
| 466 |
(equal? #f (lib->msys #f))) |
| 467 |
|
| 468 |
(pass-if "name too short" |
| 469 |
(string=? (lib->msys "a") "a")) |
| 470 |
|
| 471 |
(pass-if "name starts with 'lib'" |
| 472 |
(string=? (lib->msys "libfoo.dll") "msys-foo.dll")) |
| 473 |
|
| 474 |
(pass-if "name contains 'lib'" |
| 475 |
(string=? (lib->msys "foolib.dll") "foolib.dll")) |
| 476 |
|
| 477 |
(pass-if "name doesn't contain 'lib'" |
| 478 |
(string=? (lib->msys "foobar.dll") "foobar.dll")) |
| 479 |
|
| 480 |
(pass-if "name in path too short" |
| 481 |
(string=? (lib->msys "/lib/a") "/lib/a")) |
| 482 |
|
| 483 |
(pass-if "name in path starts with 'lib'" |
| 484 |
(string=? (lib->msys "/lib/libfoo.dll") "/lib/msys-foo.dll")) |
| 485 |
|
| 486 |
(pass-if "name in path contains 'lib'" |
| 487 |
(string=? (lib->msys "/lib/foolib.dll") "/lib/foolib.dll")) |
| 488 |
|
| 489 |
(pass-if "name in path doesn't contain 'lib'" |
| 490 |
(string=? (lib->msys "/lib/foobar.dll") "/lib/foobar.dll")) |
| 491 |
|
| 492 |
(pass-if "name in windows path starts with 'lib'" |
| 493 |
(string=? (lib->msys "c:\\lib\\libfoo.dll") "c:\\lib\\msys-foo.dll")) |
| 494 |
|
| 495 |
(pass-if "name in windows path doesn't contain 'lib'" |
| 496 |
(string=? (lib->msys "c:\\lib\\foobar.dll") "c:\\lib\\foobar.dll")))) |
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
(with-test-prefix "dll-name-match?" |
| 501 |
(let ((dll-name-match? (@@ (system foreign-library) dll-name-match?))) |
| 502 |
(pass-if "libfoo.dll == libfoo.dll" |
| 503 |
(dll-name-match? "libfoo.dll" "libfoo.dll")) |
| 504 |
(pass-if "libfoo-1.dll == libfoo.dll" |
| 505 |
(dll-name-match? "libfoo-1.dll" "libfoo.dll")) |
| 506 |
(pass-if "libfoo-10.dll == libfoo.dll" |
| 507 |
(dll-name-match? "libfoo-10.dll" "libfoo.dll")) |
| 508 |
(pass-if "libfoo-.dll != libfoo.dll" |
| 509 |
(not (dll-name-match? "libfoo-.dll" "libfoo.dll"))) |
| 510 |
(pass-if "libfoo-a.dll != libfoo.dll" |
| 511 |
(not (dll-name-match? "libfoo-a.dll" "libfoo.dll"))) |
| 512 |
(pass-if "libfoo-1a.dll != libfoo.dll" |
| 513 |
(not (dll-name-match? "libfoo-a.dll" "libfoo.dll"))))) |
| 514 |
|
| 515 |
(with-test-prefix "find-best-dll-from-matches" |
| 516 |
(let ((find-best? (@@ (system foreign-library) find-best-dll-from-matches))) |
| 517 |
(pass-if-equal "prefer unversioned name" |
| 518 |
"libfoo.dll" |
| 519 |
(find-best? "libfoo.dll" '("libfoo.dll" "libfoo-1.dll"))) |
| 520 |
(pass-if-equal "allow versioned name" |
| 521 |
"libfoo-1.dll" |
| 522 |
(find-best? "libfoo.dll" '("libfoo-1.dll"))) |
| 523 |
(pass-if-equal "larger is better" |
| 524 |
"libfoo-2.dll" |
| 525 |
(find-best? "libfoo.dll" '("libfoo-1.dll" "libfoo-2.dll"))) |
| 526 |
(pass-if-equal "multiple digits ok" |
| 527 |
"libfoo-123.dll" |
| 528 |
(find-best? "libfoo.dll" '("libfoo-1.dll" "libfoo-123.dll"))))) |