blob: 81acfeb048d3b2032a7948cfa2adea7ce64f95ae [file] [log] [blame]
Jamie Gennis2da489c2012-09-19 18:06:29 -07001#!/usr/bin/env python
2#
3# Copyright 2011, Google Inc.
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions are
8# met:
9#
10# * Redistributions of source code must retain the above copyright
11# notice, this list of conditions and the following disclaimer.
12# * Redistributions in binary form must reproduce the above
13# copyright notice, this list of conditions and the following disclaimer
14# in the documentation and/or other materials provided with the
15# distribution.
16# * Neither the name of Google Inc. nor the names of its
17# contributors may be used to endorse or promote products derived from
18# this software without specific prior written permission.
19#
20# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
32
33"""Tests for stream module."""
34
35
36import unittest
37
38import set_sys_path # Update sys.path to locate mod_pywebsocket module.
39
40from mod_pywebsocket import common
41from mod_pywebsocket import stream
42
43
44class StreamTest(unittest.TestCase):
45 """A unittest for stream module."""
46
47 def test_create_header(self):
48 # more, rsv1, ..., rsv4 are all true
49 header = stream.create_header(common.OPCODE_TEXT, 1, 1, 1, 1, 1, 1)
50 self.assertEqual('\xf1\x81', header)
51
52 # Maximum payload size
53 header = stream.create_header(
54 common.OPCODE_TEXT, (1 << 63) - 1, 0, 0, 0, 0, 0)
55 self.assertEqual('\x01\x7f\x7f\xff\xff\xff\xff\xff\xff\xff', header)
56
57 # Invalid opcode 0x10
58 self.assertRaises(ValueError,
59 stream.create_header,
60 0x10, 0, 0, 0, 0, 0, 0)
61
62 # Invalid value 0xf passed to more parameter
63 self.assertRaises(ValueError,
64 stream.create_header,
65 common.OPCODE_TEXT, 0, 0xf, 0, 0, 0, 0)
66
67 # Too long payload_length
68 self.assertRaises(ValueError,
69 stream.create_header,
70 common.OPCODE_TEXT, 1 << 63, 0, 0, 0, 0, 0)
71
72
73if __name__ == '__main__':
74 unittest.main()
75
76
77# vi:sts=4 sw=4 et