emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] feature/async-dns 92acfb9 1/7: Add network tests


From: Lars Ingebrigtsen
Subject: [Emacs-diffs] feature/async-dns 92acfb9 1/7: Add network tests
Date: Tue, 09 Feb 2016 05:09:41 +0000

branch: feature/async-dns
commit 92acfb90c68981544e6074d5779d7859c4fea487
Author: Lars Ingebrigtsen <address@hidden>
Commit: Lars Ingebrigtsen <address@hidden>

    Add network tests
    
    * test/lisp/net/network-stream-tests.el: New suite of network tests.
---
 test/lisp/net/network-stream-tests.el |  133 +++++++++++++++++++++++++++++++++
 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 0000000..3e0821a
--- /dev/null
+++ b/test/lisp/net/network-stream-tests.el
@@ -0,0 +1,133 @@
+;;; network-stream-tests.el --- tests for network processes       -*- 
lexical-binding: t; -*-
+
+;; Copyright (C) 2016 Free Software Foundation, Inc.
+
+;; Author: Lars Ingebrigtsen <address@hidden>
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+
+;;; Code:
+
+(ert-deftest make-local-unix-server ()
+  (let* ((file (make-temp-name "/tmp/server-test"))
+         (server
+          (make-network-process
+           :name "server"
+           :server t
+           :buffer (get-buffer-create "*server*")
+           :noquery t
+           :family 'local
+           :service file)))
+    (should (equal (process-contact server :local) file))
+    (delete-file (process-contact server :local))))
+
+(ert-deftest make-local-tcp-server-with-unspecified-port ()
+  (let ((server
+         (make-network-process
+          :name "server"
+          :server t
+          :noquery t
+          :family 'ipv4
+          :service t
+          :host 'local)))
+    (should (and (arrayp (process-contact server :local))
+                 (numberp (aref (process-contact server :local) 4))
+                 (> (aref (process-contact server :local) 4) 0)))
+    (delete-process server)))
+
+(ert-deftest make-local-tcp-server-with-specified-port ()
+  (let ((server
+         (make-network-process
+          :name "server"
+          :server t
+          :noquery t
+          :family 'ipv4
+          :service 57869
+          :host 'local)))
+    (should (and (arrayp (process-contact server :local))
+                 (= (aref (process-contact server :local) 4) 57869)))
+    (delete-process server)))
+
+(defun make-server (host)
+  (make-network-process
+   :name "server"
+   :server t
+   :noquery t
+   :family 'ipv4
+   :coding 'raw-text-unix
+   :buffer (get-buffer-create "*server*")
+   :service t
+   :sentinel 'server-sentinel
+   :filter 'server-process-filter
+   :host host))
+
+(defun server-sentinel (proc msg)
+  )
+
+(defun server-process-filter (proc string)
+  (message "Received %s" string)
+  (let ((prev (process-get proc 'previous-string)))
+    (when prev
+      (setq string (concat prev string))
+      (process-put proc 'previous-string nil)))
+  (if (and (not (string-match "\n" string))
+           (> (length string) 0))
+      (process-put proc 'previous-string string))
+  (let ((command (split-string string)))
+    (cond
+     ((equal (car command) "echo")
+      (process-send-string proc (concat (cadr command) "\n")))
+     (t
+      ))))
+
+(ert-deftest echo-server-with-dns ()
+  (let* ((server (make-server "mouse"))
+         (port (aref (process-contact server :local) 4))
+         (proc (make-network-process :name "foo"
+                                     :buffer (generate-new-buffer "*foo*")
+                                     :host (system-name)
+                                     :service port)))
+    (with-current-buffer "*foo*"
+      (process-send-string proc "echo foo")
+      (sleep-for 0.1)
+      (should (equal (buffer-string) "foo\n")))))
+
+(ert-deftest echo-server-with-localhost ()
+  (let* ((server (make-server 'local))
+         (port (aref (process-contact server :local) 4))
+         (proc (make-network-process :name "foo"
+                                     :buffer (generate-new-buffer "*foo*")
+                                     :host "localhost"
+                                     :service port)))
+    (with-current-buffer "*foo*"
+      (process-send-string proc "echo foo")
+      (sleep-for 0.1)
+      (should (equal (buffer-string) "foo\n")))))
+
+(ert-deftest echo-server-with-ip ()
+  (let* ((server (make-server 'local))
+         (port (aref (process-contact server :local) 4))
+         (proc (make-network-process :name "foo"
+                                     :buffer (generate-new-buffer "*foo*")
+                                     :host "127.0.0.1"
+                                     :service port)))
+    (with-current-buffer "*foo*"
+      (process-send-string proc "echo foo")
+      (sleep-for 0.1)
+      (should (equal (buffer-string) "foo\n")))))
+
+;;; network-stream-tests.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]