From c096af1234f9d9e4c4b65ff4ea738b32d511f8fc Mon Sep 17 00:00:00 2001 From: Masayuki Takagi Date: Sat, 2 May 2015 10:24:48 +0900 Subject: [PATCH] Add tests so full test coverage. --- t/intel-hex.lisp | 78 +++++++++++++++++++++++++++++++++++++++++++++--- t/test1.hex | 1 + 2 files changed, 75 insertions(+), 4 deletions(-) diff --git a/t/intel-hex.lisp b/t/intel-hex.lisp index 9fb3f84..5a0edd1 100644 --- a/t/intel-hex.lisp +++ b/t/intel-hex.lisp @@ -13,16 +13,86 @@ (plan nil) +;;; +;;; test READ-START-CODE function +;;; + +(diag "READ-START-CODE") + +(with-input-from-string (stream "foo") + (is-error (intel-hex::read-start-code stream) 'simple-error + "Unexpected character.")) + + +;;; +;;; test READ-NEWLINE function +;;; + +(diag "READ-NEWLINE") + +(with-input-from-string (stream "foo") + (is-error (intel-hex::read-newline stream) 'simple-error + "Unexpected character.")) + +;;; +;;; test VERIFY-CHECK-SUM function +;;; + +(diag "VERIFY-CHECK-SUM") + +(with-input-from-string (stream ":0100000000FE") + (let ((intel-hex::*check-sum* 0)) + (intel-hex::read-start-code stream) + (intel-hex::read-word8 stream t) + (intel-hex::read-word8 stream t) + (intel-hex::read-word8 stream t) + (intel-hex::read-word8 stream t) + (intel-hex::read-word8 stream t) + (is-error (intel-hex::verify-check-sum stream) simple-error + "Unmatched check sum."))) + + +;;; +;;; test READ-HEX function +;;; + +(diag "READ-HEX") + +(with-input-from-string (stream ":020000021200EA") + (is-error (read-hex 256 stream) simple-error + "Record type '02' not implemented.")) + +(with-input-from-string (stream ":0400000300003800C1") + (is-error (read-hex 256 stream) simple-error + "Record type '03' not implemented.")) + +(with-input-from-string (stream ":04000005000000CD2A") + (is-error (read-hex 256 stream) simple-error + "Record type '05' not implemented.")) + + ;;; ;;; test READ-HEX-FROM-FILE function ;;; +(diag "READ-HEX-FROM-FILE") + (let* ((path (asdf:system-relative-pathname :intel-hex #P"t/test1.hex")) (bytes (read-hex-from-file 512 path))) - (is (aref bytes #x100) #x21) - (is (aref bytes #x101) #x46) - (is (aref bytes #x102) #x01) - (is (aref bytes #x13F) #x21)) + (is (aref bytes #x100) #x21 "The first byte of the array is 0x21.") + (is (aref bytes #x101) #x46 "The second byte of the array is 0x46.") + (is (aref bytes #x102) #x01 "The thrid byte of the array is 0x01.") + (is (aref bytes #x13F) #x21 "The last byte of the array is 0x21.")) + + +;;; +;;; test READ-HEX-FROM-STRING function +;;; + +(diag "READ-HEX-FROM-STRING") + +(let ((bytes (read-hex-from-string 256 ":00000001FF"))) + (is (aref bytes #x00) #x00 "The first byte of the array is 0x00.")) (finalize) diff --git a/t/test1.hex b/t/test1.hex index 9e790e5..1c28159 100644 --- a/t/test1.hex +++ b/t/test1.hex @@ -1,3 +1,4 @@ +:020000040000FA :10010000214601360121470136007EFE09D2190140 :100110002146017E17C20001FF5F16002148011928 :10012000194E79234623965778239EDA3F01B2CAA7