aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorLars Ingebrigtsen2016-02-08 14:24:25 +1100
committerLars Ingebrigtsen2016-02-08 14:24:25 +1100
commit0cc907100cbf6b730935cf5beeb943943ab518e3 (patch)
tree370e28ab8e5edb99d14625e83dcba5940465293d /test
parent357ae5dba5faac5ff48ebb971cb29500f87f02a6 (diff)
downloademacs-0cc907100cbf6b730935cf5beeb943943ab518e3.tar.gz
emacs-0cc907100cbf6b730935cf5beeb943943ab518e3.zip
Add network tests
* test/lisp/net/network-stream-tests.el: New suite of network tests.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/net/network-stream-tests.el133
1 files changed, 133 insertions, 0 deletions
diff --git a/test/lisp/net/network-stream-tests.el b/test/lisp/net/network-stream-tests.el
new file mode 100644
index 00000000000..3e0821a8bd5
--- /dev/null
+++ b/test/lisp/net/network-stream-tests.el
@@ -0,0 +1,133 @@
1;;; network-stream-tests.el --- tests for network processes -*- lexical-binding: t; -*-
2
3;; Copyright (C) 2016 Free Software Foundation, Inc.
4
5;; Author: Lars Ingebrigtsen <larsi@gnus.org>
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 <http://www.gnu.org/licenses/>.
19
20;;; Commentary:
21
22
23;;; Code:
24
25(ert-deftest make-local-unix-server ()
26 (let* ((file (make-temp-name "/tmp/server-test"))
27 (server
28 (make-network-process
29 :name "server"
30 :server t
31 :buffer (get-buffer-create "*server*")
32 :noquery t
33 :family 'local
34 :service file)))
35 (should (equal (process-contact server :local) file))
36 (delete-file (process-contact server :local))))
37
38(ert-deftest make-local-tcp-server-with-unspecified-port ()
39 (let ((server
40 (make-network-process
41 :name "server"
42 :server t
43 :noquery t
44 :family 'ipv4
45 :service t
46 :host 'local)))
47 (should (and (arrayp (process-contact server :local))
48 (numberp (aref (process-contact server :local) 4))
49 (> (aref (process-contact server :local) 4) 0)))
50 (delete-process server)))
51
52(ert-deftest make-local-tcp-server-with-specified-port ()
53 (let ((server
54 (make-network-process
55 :name "server"
56 :server t
57 :noquery t
58 :family 'ipv4
59 :service 57869
60 :host 'local)))
61 (should (and (arrayp (process-contact server :local))
62 (= (aref (process-contact server :local) 4) 57869)))
63 (delete-process server)))
64
65(defun make-server (host)
66 (make-network-process
67 :name "server"
68 :server t
69 :noquery t
70 :family 'ipv4
71 :coding 'raw-text-unix
72 :buffer (get-buffer-create "*server*")
73 :service t
74 :sentinel 'server-sentinel
75 :filter 'server-process-filter
76 :host host))
77
78(defun server-sentinel (proc msg)
79 )
80
81(defun server-process-filter (proc string)
82 (message "Received %s" string)
83 (let ((prev (process-get proc 'previous-string)))
84 (when prev
85 (setq string (concat prev string))
86 (process-put proc 'previous-string nil)))
87 (if (and (not (string-match "\n" string))
88 (> (length string) 0))
89 (process-put proc 'previous-string string))
90 (let ((command (split-string string)))
91 (cond
92 ((equal (car command) "echo")
93 (process-send-string proc (concat (cadr command) "\n")))
94 (t
95 ))))
96
97(ert-deftest echo-server-with-dns ()
98 (let* ((server (make-server "mouse"))
99 (port (aref (process-contact server :local) 4))
100 (proc (make-network-process :name "foo"
101 :buffer (generate-new-buffer "*foo*")
102 :host (system-name)
103 :service port)))
104 (with-current-buffer "*foo*"
105 (process-send-string proc "echo foo")
106 (sleep-for 0.1)
107 (should (equal (buffer-string) "foo\n")))))
108
109(ert-deftest echo-server-with-localhost ()
110 (let* ((server (make-server 'local))
111 (port (aref (process-contact server :local) 4))
112 (proc (make-network-process :name "foo"
113 :buffer (generate-new-buffer "*foo*")
114 :host "localhost"
115 :service port)))
116 (with-current-buffer "*foo*"
117 (process-send-string proc "echo foo")
118 (sleep-for 0.1)
119 (should (equal (buffer-string) "foo\n")))))
120
121(ert-deftest echo-server-with-ip ()
122 (let* ((server (make-server 'local))
123 (port (aref (process-contact server :local) 4))
124 (proc (make-network-process :name "foo"
125 :buffer (generate-new-buffer "*foo*")
126 :host "127.0.0.1"
127 :service port)))
128 (with-current-buffer "*foo*"
129 (process-send-string proc "echo foo")
130 (sleep-for 0.1)
131 (should (equal (buffer-string) "foo\n")))))
132
133;;; network-stream-tests.el ends here