Changeset 36724 in project


Ignore:
Timestamp:
10/27/18 17:24:10 (3 weeks ago)
Author:
kon
Message:

add init & update test, add mem bug (?) test
-This line, and those below, will be ignored--

M message-digest-primitive/trunk/tests/message-digest-primitive-test.scm

File:
1 edited

Legend:

Unmodified
Added
Removed
  • release/5/message-digest-primitive/trunk/tests/message-digest-primitive-test.scm

    r36722 r36724  
    1 ;;;; message-digest-primitive-test.scm  -*- Scheme -*-
    2 ;;;; Kon Lovett, Jul '18
     1;;;;message-digest-primitive-test.scm  -*- Scheme -*-
     2;;;;Kon Lovett, Jul '18
    33
    44(import test)
     
    88;;;
    99
    10 (import (chicken blob) message-digest-primitive)
     10(import message-digest-primitive)
     11
     12;;
     13
     14(import (chicken blob))
    1115
    1216;;
     
    107111    (assert (not (not bytes)))
    108112    (assert (< 0 count))
    109     (assert (<= count CONTEXT-SIZE))  ; So no mem overflow
     113    (assert (<= count CONTEXT-SIZE))  ;So no mem overflow
    110114    (assert (pointer? ctx))
    111115    (assert (blob? bytes))
     
    119123    (assert (pointer? ctx))
    120124    (assert (or (blob? result) (string? result)))
    121     ; So no mem overflow
     125    ;So no mem overflow
    122126    (assert (<= DIGEST-LENGTH (if (blob? result) (blob-size result) (string-length result))))
    123127    (move-memory! ctx result DIGEST-LENGTH) )
     
    148152    (assert (not (not bytes)))
    149153    (assert (< 0 count))
    150     (assert (<= count CONTEXT-SIZE))  ; So no mem overflow
     154    (assert (<= count CONTEXT-SIZE))  ;So no mem overflow
    151155    (assert (blob? ctx))
    152156    (assert (blob? bytes))
     
    160164    (assert (blob? ctx))
    161165    (assert (blob? result))
    162     (assert (<= (blob-size result) DIGEST-LENGTH))  ; So no mem overflow
     166    (assert (<= (blob-size result) DIGEST-LENGTH))  ;So no mem overflow
    163167    (move-memory! ctx result DIGEST-LENGTH) )
    164168
     
    171175)
    172176
    173 ;
     177;uses foreign
    174178#+compiling
    175179(begin
     
    186190    (define raw-update
    187191      (foreign-lambda* void ((c-pointer pctx) (c-pointer pdat) (unsigned-int n))
    188         "memmove(pctx, pdat, n);"))
     192        "memmove( pctx, pdat, n );"))
    189193
    190194    (define (final ctx result)
     
    194198      (assert (pointer? ctx))
    195199      (assert (or (blob? result) (string? result)))
    196       ; So no mem overflow
     200      ;So no mem overflow
    197201      (assert (<= DIGEST-LENGTH (if (blob? result) (blob-size result) (string-length result))))
    198202      (move-memory! ctx result DIGEST-LENGTH) )
     
    201205      (mdp (make-message-digest-primitive CONTEXT-SIZE DIGEST-LENGTH init #f final #:raw-update raw-update))
    202206      (ctx (make-message-digest-primitive-context mdp)) )
    203       (test-assert "allocated context" ctx)
    204       (test-assert "generated update"(message-digest-primitive-update mdp))
    205       ((message-digest-primitive-update mdp) ctx "foobar" 3)
    206       (test "f[oo]" #\f (integer->char (pointer-u8-ref ctx)))
    207       (test "fo[o]" #\o (integer->char (pointer-u8-ref (pointer+ ctx 1))))
    208       (test "foo[]" #\o (integer->char (pointer-u8-ref (pointer+ ctx 2))))
    209       ;FIXME Add Life-Cycle Tests
    210       )
     207      (test-assert "allocated context" (pointer? ctx))
     208      (test-assert "initialize" ((message-digest-primitive-init mdp) ctx))
     209      (test "initialize worked" the-ctx ctx)
     210      (test-assert "generated update" (procedure? (message-digest-primitive-update mdp)))
     211      (test-assert "update" ((message-digest-primitive-update mdp) ctx "foobar" 3))
     212      (test "update worked" #\f (integer->char (pointer-u8-ref ctx)))
     213      ;FIXME bugs in chicken memory ?
     214      (test-assert "BUG?: @ptr != @(ptr + 0)" (not (equal? (pointer->address ctx) (pointer->address (pointer+ ctx 0)))))
     215      ;
     216      ;(print "@+0: " (+ (pointer->address ctx) 0))
     217      ;(print "@+0<->: " (pointer->address (address->pointer (+ (pointer->address ctx) 0))))
     218      ;
     219      ;Error: segmentation violation
     220      ;(test-assert (pointer-u8-ref (address->pointer (+ (pointer->address ctx) 0))))
     221      ;
     222      ;(test "f[oo]" #\f (integer->char (pointer-u8-ref (address->pointer (+ (pointer->address ctx) 0)))))
     223      ;
     224      ;(print (pointer->address ctx))
     225      ;(print (pointer->address (pointer+ ctx 0)))
     226      ;(print (pointer->address (pointer+ ctx 1)))
     227      ;(print (pointer->address (pointer+ ctx 2)))
     228      ;
     229      ;(test "f[oo]" #\f (integer->char (pointer-u8-ref (pointer+ ctx 0))))
     230      ;(test "fo[o]" #\o (integer->char (pointer-u8-ref (pointer+ ctx 1))))
     231      ;(test "foo[]" #\o (integer->char (pointer-u8-ref (pointer+ ctx 2))))
     232    )
    211233  )
    212234)
Note: See TracChangeset for help on using the changeset viewer.