aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Ingebrigtsen2019-06-15 15:57:01 +0200
committerLars Ingebrigtsen2019-06-15 15:57:01 +0200
commit60a6992ae3ab66999d64a97ce3fb0bd60090b189 (patch)
treeb367b7ecf0cf2b357d95ad4a7147506307bcd583
parent777f410666c252751f1f2b79b0d4ae76c546c8b4 (diff)
downloademacs-60a6992ae3ab66999d64a97ce3fb0bd60090b189.tar.gz
emacs-60a6992ae3ab66999d64a97ce3fb0bd60090b189.zip
New file to test bindat functions
-rw-r--r--test/lisp/emacs-lisp/bindat-tests.el70
1 files changed, 70 insertions, 0 deletions
diff --git a/test/lisp/emacs-lisp/bindat-tests.el b/test/lisp/emacs-lisp/bindat-tests.el
new file mode 100644
index 00000000000..df82ea67128
--- /dev/null
+++ b/test/lisp/emacs-lisp/bindat-tests.el
@@ -0,0 +1,70 @@
1;;; bindat-tests.el --- tests for bindat.el -*- lexical-binding: t; -*-
2
3;; Copyright (C) 2019 Free Software Foundation, Inc.
4
5;; This file is part of GNU Emacs.
6
7;; GNU Emacs is free software; you can redistribute it and/or modify
8;; it under the terms of the GNU General Public License as published by
9;; the Free Software Foundation, either version 3 of the License, or
10;; (at your option) any later version.
11
12;; GNU Emacs is distributed in the hope that it will be useful,
13;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;; GNU General Public License for more details.
16
17;; You should have received a copy of the GNU General Public License
18;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
19
20;;; Code:
21
22(require 'ert)
23(require 'bindat)
24(require 'cl-lib)
25
26(defvar header-bindat-spec
27 '((dest-ip ip)
28 (src-ip ip)
29 (dest-port u16)
30 (src-port u16)))
31
32(defvar data-bindat-spec
33 '((type u8)
34 (opcode u8)
35 (length u16r) ;; little endian order
36 (id strz 8)
37 (data vec (length))
38 (align 4)))
39
40(ert-deftest bindat-test-pack ()
41 (let* ((packet-bindat-spec
42 '((header struct header-bindat-spec)
43 (items u8)
44 (fill 3)
45 (item repeat (items)
46 (struct data-bindat-spec))))
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
70;;; bindat-tests.el ends here