blob: 81ecee2c427da90c174df8c795da1dc1f835a9eb [file] [log] [blame]
Rich Lane15cbe842013-04-26 16:04:11 -07001#!/usr/bin/env python
2# Copyright 2013, Big Switch Networks, Inc.
3#
4# LoxiGen is licensed under the Eclipse Public License, version 1.0 (EPL), with
5# the following special exception:
6#
7# LOXI Exception
8#
9# As a special exception to the terms of the EPL, you may distribute libraries
10# generated by LoxiGen (LoxiGen Libraries) under the terms of your choice, provided
11# that copyright and licensing notices generated by LoxiGen are not altered or removed
12# from the LoxiGen Libraries and the notice provided below is (i) included in
13# the LoxiGen Libraries, if distributed in source code form and (ii) included in any
14# documentation for the LoxiGen Libraries, if distributed in binary form.
15#
16# Notice: "Copyright 2013, Big Switch Networks, Inc. This library was generated by the LoxiGen Compiler."
17#
18# You may not use this file except in compliance with the EPL or LOXI Exception. You may obtain
19# a copy of the EPL at:
20#
21# http://www.eclipse.org/legal/epl-v10.html
22#
23# Unless required by applicable law or agreed to in writing, software
24# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
25# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
26# EPL for the specific language governing permissions and limitations
27# under the EPL.
28import unittest
29
30try:
31 import loxi
32 import loxi.generic_util
33except ImportError:
34 exit("loxi package not found. Try setting PYTHONPATH.")
35
36class TestUnpackArray(unittest.TestCase):
37 def test_simple(self):
38 a = loxi.generic_util.unpack_array(str, 3, "abcdefghi")
39 self.assertEquals(['abc', 'def', 'ghi'], a)
40
41 with self.assertRaisesRegexp(loxi.ProtocolError, "invalid array length"):
42 loxi.generic_util.unpack_array(str, 3, "abcdefgh")
43
44class TestUnpackList(unittest.TestCase):
45 def test_simple(self):
46 a = loxi.generic_util.unpack_list(str, '!B', "\x04abc\x03de\x02f\x01")
47 self.assertEquals(['\x04abc', '\x03de', '\x02f', '\x01'], a)
48
49if __name__ == '__main__':
50 unittest.main()