diff options
| author | Lars Ingebrigtsen | 2019-06-15 16:06:38 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2019-06-15 16:06:38 +0200 |
| commit | f03343747e380174400ac0529030dc4d35bea715 (patch) | |
| tree | c85e847f2f4dbed07d2fc2a1b623eade5c9acf7c | |
| parent | 60a6992ae3ab66999d64a97ce3fb0bd60090b189 (diff) | |
| download | emacs-f03343747e380174400ac0529030dc4d35bea715.tar.gz emacs-f03343747e380174400ac0529030dc4d35bea715.zip | |
Refactor for reuse
| -rw-r--r-- | test/lisp/emacs-lisp/bindat-tests.el | 59 |
1 files changed, 31 insertions, 28 deletions
diff --git a/test/lisp/emacs-lisp/bindat-tests.el b/test/lisp/emacs-lisp/bindat-tests.el index df82ea67128..854fd5b62d5 100644 --- a/test/lisp/emacs-lisp/bindat-tests.el +++ b/test/lisp/emacs-lisp/bindat-tests.el | |||
| @@ -37,34 +37,37 @@ | |||
| 37 | (data vec (length)) | 37 | (data vec (length)) |
| 38 | (align 4))) | 38 | (align 4))) |
| 39 | 39 | ||
| 40 | (defvar packet-bindat-spec | ||
| 41 | '((header struct header-bindat-spec) | ||
| 42 | (items u8) | ||
| 43 | (fill 3) | ||
| 44 | (item repeat (items) | ||
| 45 | (struct data-bindat-spec)))) | ||
| 46 | |||
| 47 | (defvar struct-bindat | ||
| 48 | '((header | ||
| 49 | (dest-ip . [192 168 1 100]) | ||
| 50 | (src-ip . [192 168 1 101]) | ||
| 51 | (dest-port . 284) | ||
| 52 | (src-port . 5408)) | ||
| 53 | (items . 2) | ||
| 54 | (item ((data . [1 2 3 4 5]) | ||
| 55 | (id . "ABCDEF") | ||
| 56 | (length . 5) | ||
| 57 | (opcode . 3) | ||
| 58 | (type . 2)) | ||
| 59 | ((data . [6 7 8 9 10 11 12]) | ||
| 60 | (id . "BCDEFG") | ||
| 61 | (length . 7) | ||
| 62 | (opcode . 4) | ||
| 63 | (type . 1))))) | ||
| 64 | |||
| 40 | (ert-deftest bindat-test-pack () | 65 | (ert-deftest bindat-test-pack () |
| 41 | (let* ((packet-bindat-spec | 66 | (should (equal |
| 42 | '((header struct header-bindat-spec) | 67 | (cl-map 'vector #'identity |
| 43 | (items u8) | 68 | (bindat-pack packet-bindat-spec struct-bindat)) |
| 44 | (fill 3) | 69 | [ 192 168 1 100 192 168 1 101 01 28 21 32 2 0 0 0 |
| 45 | (item repeat (items) | 70 | 2 3 5 0 ?A ?B ?C ?D ?E ?F 0 0 1 2 3 4 5 0 0 0 |
| 46 | (struct data-bindat-spec)))) | 71 | 1 4 7 0 ?B ?C ?D ?E ?F ?G 0 0 6 7 8 9 10 11 12 0 ]))) |
| 47 | (struct | ||
| 48 | '((header | ||
| 49 | (dest-ip . [192 168 1 100]) | ||
| 50 | (src-ip . [192 168 1 101]) | ||
| 51 | (dest-port . 284) | ||
| 52 | (src-port . 5408)) | ||
| 53 | (items . 2) | ||
| 54 | (item ((data . [1 2 3 4 5]) | ||
| 55 | (id . "ABCDEF") | ||
| 56 | (length . 5) | ||
| 57 | (opcode . 3) | ||
| 58 | (type . 2)) | ||
| 59 | ((data . [6 7 8 9 10 11 12]) | ||
| 60 | (id . "BCDEFG") | ||
| 61 | (length . 7) | ||
| 62 | (opcode . 4) | ||
| 63 | (type . 1)))))) | ||
| 64 | (should (equal | ||
| 65 | (cl-map 'vector #'identity (bindat-pack packet-bindat-spec struct)) | ||
| 66 | [ 192 168 1 100 192 168 1 101 01 28 21 32 2 0 0 0 | ||
| 67 | 2 3 5 0 ?A ?B ?C ?D ?E ?F 0 0 1 2 3 4 5 0 0 0 | ||
| 68 | 1 4 7 0 ?B ?C ?D ?E ?F ?G 0 0 6 7 8 9 10 11 12 0 ])))) | ||
| 69 | 72 | ||
| 70 | ;;; bindat-tests.el ends here | 73 | ;;; bindat-tests.el ends here |