1 # Copyright (C) 2012 Nippon Telegraph and Telephone Corporation.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
20 from nose.tools import ok_, eq_
22 from ryu.lib import pack_utils
25 class TestMsgPackInto(unittest.TestCase):
26 """ Test case for msg_pack_into
29 def _test_msg_pack_into(self, offset_type='e'):
31 len_ = struct.calcsize(fmt)
37 if offset_type == 'l':
39 elif offset_type == 'g':
42 pack_utils.msg_pack_into(fmt, buf, offset, arg1, arg2)
44 check_offset = len(buf) - len_
45 res = struct.unpack_from(fmt, six.binary_type(buf), check_offset)
52 def test_msg_pack_into(self):
53 ok_(self._test_msg_pack_into())
55 def test_msg_pack_into_less(self):
56 ok_(self._test_msg_pack_into('l'))
58 def test_msg_pack_into_greater(self):
59 ok_(self._test_msg_pack_into('g'))