Ignore:
Timestamp:
10/26/18 18:28:33 (2 years ago)
Author:
Kon Lovett
Message:

add raw -> cooked

File:
1 edited

Legend:

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

    r35915 r36722  
    171171)
    172172
     173;
     174#+compiling
     175(begin
     176  (import (chicken foreign) (chicken memory))
     177  (test-group "Raw => Cooked"
     178
     179    (define the-ctx #f)
     180
     181    (define (init ctx)
     182      ;(printf "  Init Ctx: ~S~%" ctx)
     183      (set! the-ctx ctx)
     184      (assert (pointer? ctx)) )
     185
     186    (define raw-update
     187      (foreign-lambda* void ((c-pointer pctx) (c-pointer pdat) (unsigned-int n))
     188        "memmove(pctx, pdat, n);"))
     189
     190    (define (final ctx result)
     191      ;(printf " Final Ctx: ~S Result: ~S~%" ctx result)
     192      (assert (eq? ctx the-ctx))
     193      (assert (not (not result)))
     194      (assert (pointer? ctx))
     195      (assert (or (blob? result) (string? result)))
     196      ; So no mem overflow
     197      (assert (<= DIGEST-LENGTH (if (blob? result) (blob-size result) (string-length result))))
     198      (move-memory! ctx result DIGEST-LENGTH) )
     199
     200    (let* (
     201      (mdp (make-message-digest-primitive CONTEXT-SIZE DIGEST-LENGTH init #f final #:raw-update raw-update))
     202      (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      )
     211  )
     212)
     213
    173214;;;
    174215
Note: See TracChangeset for help on using the changeset viewer.