diff options
author | Yves Fischer <yvesf-git@xapek.org> | 2016-08-14 19:25:26 +0200 |
---|---|---|
committer | Yves Fischer <yvesf-git@xapek.org> | 2016-08-14 19:25:26 +0200 |
commit | caae83f445935c06cd6aef36f283a4688675278a (patch) | |
tree | 5e63cbfd2877195430a8657dcd75f42b6a4d7110 /ebus-racket/tests | |
download | ebus-caae83f445935c06cd6aef36f283a4688675278a.tar.gz ebus-caae83f445935c06cd6aef36f283a4688675278a.zip |
refactored ebus code
Diffstat (limited to 'ebus-racket/tests')
-rw-r--r-- | ebus-racket/tests/layer2-test.rkt | 71 | ||||
-rw-r--r-- | ebus-racket/tests/layer7-test.rkt | 62 |
2 files changed, 133 insertions, 0 deletions
diff --git a/ebus-racket/tests/layer2-test.rkt b/ebus-racket/tests/layer2-test.rkt new file mode 100644 index 0000000..6be2ba8 --- /dev/null +++ b/ebus-racket/tests/layer2-test.rkt @@ -0,0 +1,71 @@ +#lang racket/base +(require rackunit + rackunit/text-ui + (prefix-in layer2- "../ebus/layer2.rkt")) + +(define layer2-test + (test-suite + "Tests for Ebus Parser" + (test-case + "Test sample Master-Master Paket" + (let + ([paket (layer2-read-ebus + (open-input-bytes + (bytes + 170 ; SYN + 170 + 003 ; Source + 241 ; Destination + 008 ; primaryCommand + 000 ; secondaryCommand + 008 ; payloadLength + 128 ; p1 + 040 ; p2 + 230 ; p3 + 002 ; p4 + 000 ; p5 + 002 ; p6 + 000 ; p7 + 010 ; p8 + 128 ; CRC + 000 ; ACK + 170 ; SYN + 170)))]) + (check-eq? (layer2-ebus-paket-source paket) 003) + (check-eq? (layer2-ebus-paket-destination paket) 241) + (check-eq? (layer2-ebus-paket-primaryCommand paket) 008) + (check-eq? (layer2-ebus-paket-secondaryCommand paket) 000) + (check-eq? (layer2-ebus-paket-payloadLength paket) 008) + (check-eq? (layer2-ebus-paket-payloadLength paket) + (length (layer2-ebus-paket-payload paket))) + )) + (test-case + "test invalid paket" + (let + ([paket (layer2-read-ebus + (open-input-bytes + (bytes + 170 ;SYN + 170 ;SYN + 016 ;SRC + 003 ;DEST + 008 ;PRIM => sollwertuebertragungRegler + 000 ;SEC => sollwertuebertragungRegler + 008 ;PAY + 051 ;P1 + 042 ;P2 + 000 ;P3 + 009 ;P4 + 128 ;P5 + 019 ;P6 + 000 ;P7 | ACK + 045 ;P8 | ??? + 170 ;SYN + 170 ;SYN + )))]) + (check-eq? paket eof) + )) + )) + + +(exit (run-tests layer2-test)) diff --git a/ebus-racket/tests/layer7-test.rkt b/ebus-racket/tests/layer7-test.rkt new file mode 100644 index 0000000..5fa8c4a --- /dev/null +++ b/ebus-racket/tests/layer7-test.rkt @@ -0,0 +1,62 @@ +#lang racket/base +(require rackunit + rackunit/text-ui + racket/list + (prefix-in layer2- "../ebus/layer2.rkt") + (prefix-in layer7- "../ebus/layer7.rkt")) + +(define layer7-test + (test-suite + "Tests for Ebus Layer 7 Parser" + (test-case + "Test sample Master-Master Paket" + (parameterize ([layer7-definition (layer7-read-ebus-xml "../../ebus-xml/ebus.xml")]) + (let* + ([l2paket (layer2-read-ebus (open-input-bytes (bytes + 170 ; SYN + 170 + 003 ; Source + 241 ; Destination + 008 ; primaryCommand + 000 ; secondaryCommand + 008 ; payloadLength + 128 ; p1 + 040 ; p2 + 230 ; p3 + 002 ; p4 + 200 ; p5 + 002 ; p6 + 000 ; p7 + 010 ; p8 + 128 ; CRC + 000 ; ACK + 170 ; SYN + 170)))] + [fields (layer7-paket-parse l2paket)]) + (for ([field fields]) + (display field) + (display "\n")) + (check-true (= 5 (length fields)) "Anzahl der gelesenen Felder") + (let ([p (first fields)]) + (check-equal? (first p) "feuerungsautomat1.sollwertuebertragungRegler.TK_soll") + (check-equal? (second p) 'data2b) + (check-equal? (third p) 40.5)) + (let ([p (second fields)]) + (check-equal? (first p) "feuerungsautomat1.sollwertuebertragungRegler.TA_ist") + (check-equal? (second p) 'data2b) + (check-equal? (third p) 2.8984375)) + (let ([p (third fields)]) + (check-equal? (first p) "feuerungsautomat1.sollwertuebertragungRegler.L_zwang") + (check-equal? (second p) 'data1b) + (check-equal? (third p) -56)) + (let ([p (fourth fields)]) + (check-equal? (first p) "feuerungsautomat1.sollwertuebertragungRegler.Status") + (check-equal? (second p) 'bit) + (check-equal? (third p) 0)) + (let ([p (fifth fields)]) + (check-equal? (first p) "feuerungsautomat1.sollwertuebertragungRegler.TB_soll") + (check-equal? (second p) 'data2b) + (check-equal? (third p) 10)) + ))))) + +(exit (run-tests layer7-test)) |