Fix `foreign.test' for big endian machines.
authorLudovic Courtès <ludo@gnu.org>
Fri, 6 May 2011 15:43:37 +0000 (17:43 +0200)
committerLudovic Courtès <ludo@gnu.org>
Fri, 6 May 2011 15:43:37 +0000 (17:43 +0200)
* test-suite/tests/foreign.test ("pointer<->bytevector")["pointer from
  bits", "dereference-pointer"]: Fix iteration order for big endian
  machines.

test-suite/tests/foreign.test

index 60b466e..5ddd31c 100644 (file)
 
   (pass-if "pointer from bits"
     (let* ((bytes (iota (sizeof '*)))
-           (bv    (u8-list->bytevector bytes)))
+           (bv    (u8-list->bytevector bytes))
+           (fold  (case (native-endianness)
+                    ((little) fold-right)
+                    ((big)    fold)
+                    (else     (error "unsupported endianness")))))
       (= (pointer-address
           (make-pointer (bytevector-uint-ref bv 0 (native-endianness)
                                              (sizeof '*))))
-         (fold-right (lambda (byte address)
-                       (+ byte (* 256 address)))
-                     0
-                     bytes))))
+         (fold (lambda (byte address)
+                 (+ byte (* 256 address)))
+               0
+               bytes))))
 
   (pass-if "dereference-pointer"
     (let* ((bytes (iota (sizeof '*)))
-           (bv    (u8-list->bytevector bytes)))
+           (bv    (u8-list->bytevector bytes))
+           (fold  (case (native-endianness)
+                    ((little) fold-right)
+                    ((big)    fold)
+                    (else     (error "unsupported endianness")))))
       (= (pointer-address
           (dereference-pointer (bytevector->pointer bv)))
-         (fold-right (lambda (byte address)
-                       (+ byte (* 256 address)))
-                     0
-                     bytes)))))
+         (fold (lambda (byte address)
+                 (+ byte (* 256 address)))
+               0
+               bytes)))))
 
 \f
 (with-test-prefix "pointer<->string"