Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 77 lines (69 sloc) 2.835 kb
59697b40 »
2012-05-06 Initial checkin of files. These files were initially part of the
1 ;;; websocket-test.el --- Unit tests for the websocket layer
2
3 ;; Copyright (c) 2010 Andrew Hyatt
4 ;;
5 ;; Author: Andrew Hyatt <ahyatt at gmail dot com>
6 ;; Maintainer: Andrew Hyatt <ahyatt at gmail dot com>
7 ;;
8 ;; This program is free software; you can redistribute it and/or
9 ;; modify it under the terms of the GNU General Public License as
10 ;; published by the Free Software Foundation; either version 2 of the
11 ;; License, or (at your option) any later version.
12 ;;
13 ;; This program is distributed in the hope that it will be useful, but
14 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 ;; General Public License for more details.
17 ;;
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program; if not, write to the Free Software
20 ;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 ;; 02110-1301, USA.
22
23 ;;; Commentary:
24 ;; This defines and runs ert unit tests. You can download ert from:
25 ;; http://github.com/ohler/ert, it also comes with Emacs 24 and above.
26
27 (require 'ert)
28 (require 'cl)
29
30 (defun websocket-test-get-filtered-response (outputs)
31 (let ((packet-data nil)
32 (websocket
33 (make-websocket :conn "fake-conn"
34 :filter (lambda (packet) (push packet packet-data))
35 :close-callback (lambda (not-called) (assert nil))
36 :url "ws://foo/bar"
37 :v75 nil)))
38 (dolist (output outputs)
39 (websocket-outer-filter websocket output))
40 (nreverse packet-data)))
41
42 (ert-deftest websocket-filter-basic ()
43 (should (equal
44 '("foo")
45 (websocket-test-get-filtered-response '("\0foo\377"))))
46 (should (equal
47 '("foo" "bar")
48 (websocket-test-get-filtered-response
49 '("\0foo\377\0bar\377"))))
50 (should (equal
51 '("foo" "bar")
52 (websocket-test-get-filtered-response
53 '("\0foo\377" "\0bar\377")))))
54
55 (ert-deftest websocket-filter-inflight-packets ()
56 (should (equal
57 '("foo" "bar")
58 (websocket-test-get-filtered-response
59 '("\0foo\377\0b" "a" "r\377"))))
60 (should (equal
61 '("foo" "bar")
62 (websocket-test-get-filtered-response
63 '("\0foo\377\0ba" "r\377baz")))))
64
65 (ert-deftest websocket-filter-first-response ()
66 (should (equal
67 '("foo" "bar")
68 (websocket-test-get-filtered-response
69 '("HTTP 1.1\0foo\377\0bar\377"))))
70 (should (equal
71 '("foo")
72 (websocket-test-get-filtered-response
73 '("HTTP 1.1" "\0foo\377")))))
74
75 (ert-run-tests-interactively 'websocket-filter-basic)
76 (ert-run-tests-interactively 'websocket-filter-inflight-packets)
77 (ert-run-tests-interactively 'websocket-filter-first-response)
Something went wrong with that request. Please try again.