diff options
author | HIYAMA Manabu <hiyama.manabu@po.ntts.co.jp> | 2012-10-03 19:17:20 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2012-10-05 18:57:59 +0900 |
commit | 7ad45aa1c1434c587a672f44e36abd3f5cbaa25f (patch) | |
tree | bec689ee0cacfce396ac7fbd378af9d53d510d91 | |
parent | 12e9445c8778516da10fb04b52bf46747c7913e5 (diff) |
test: fix unittests for of parser
- use bytearray(n) instead of str().zfill(n)
- test data are more strictly.
Signed-off-by: HIYAMA Manabu <hiyama.manabu@po.ntts.co.jp>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/tests/unit/ofproto/test_ofproto_parser.py | 19 | ||||
-rw-r--r-- | ryu/tests/unit/ofproto/test_parser_v10.py | 26 | ||||
-rw-r--r-- | ryu/tests/unit/ofproto/test_parser_v12.py | 26 |
3 files changed, 45 insertions, 26 deletions
diff --git a/ryu/tests/unit/ofproto/test_ofproto_parser.py b/ryu/tests/unit/ofproto/test_ofproto_parser.py index 9baf46ab..be67434b 100644 --- a/ryu/tests/unit/ofproto/test_ofproto_parser.py +++ b/ryu/tests/unit/ofproto/test_ofproto_parser.py @@ -161,16 +161,23 @@ class TestMsgBase(unittest.TestCase): c.set_xid(xid) def _test_parser(self, msg_type=ofproto_v1_0.OFPT_HELLO): + version = ofproto_v1_0.OFP_VERSION + msg_len = ofproto_v1_0.OFP_HEADER_SIZE xid = 2183948390 + data = '\x00\x01\x02\x03' + + fmt = ofproto_v1_0.OFP_HEADER_PACK_STR + buf = struct.pack(fmt, version, msg_type, msg_len, xid) \ + + data + res = ofproto_v1_0_parser.OFPHello.parser( - object, ofproto_v1_0.OFP_VERSION, msg_type, - ofproto_v1_0.OFP_HEADER_SIZE, xid, - str().zfill(ofproto_v1_0.OFP_HEADER_SIZE)) + object, version, msg_type, msg_len, xid, bytearray(buf)) - eq_(ofproto_v1_0.OFP_VERSION, res.version) - eq_(ofproto_v1_0.OFPT_HELLO, res.msg_type) - eq_(ofproto_v1_0.OFP_HEADER_SIZE, res.msg_len) + eq_(version, res.version) + eq_(msg_type, res.msg_type) + eq_(msg_len, res.msg_len) eq_(xid, res.xid) + eq_(buffer(buf), res.buf) # test __str__() list_ = ('version:', 'msg_type', 'xid') diff --git a/ryu/tests/unit/ofproto/test_parser_v10.py b/ryu/tests/unit/ofproto/test_parser_v10.py index 9a47ebca..66a69a44 100644 --- a/ryu/tests/unit/ofproto/test_parser_v10.py +++ b/ryu/tests/unit/ofproto/test_parser_v10.py @@ -2695,18 +2695,24 @@ class TestOFPHello(unittest.TestCase): pass def test_parser(self): + version = ofproto_v1_0.OFP_VERSION + msg_type = ofproto_v1_0.OFPT_HELLO + msg_len = ofproto_v1_0.OFP_HEADER_SIZE xid = 2183948390 - res = OFPHello.parser(object, - ofproto_v1_0.OFP_VERSION, - ofproto_v1_0.OFPT_HELLO, - ofproto_v1_0.OFP_HEADER_SIZE, - xid, - str().zfill(ofproto_v1_0.OFP_HEADER_SIZE)) - - eq_(ofproto_v1_0.OFP_VERSION, res.version) - eq_(ofproto_v1_0.OFPT_HELLO, res.msg_type) - eq_(ofproto_v1_0.OFP_HEADER_SIZE, res.msg_len) + data = '\x00\x01\x02\x03' + + fmt = ofproto_v1_0.OFP_HEADER_PACK_STR + buf = struct.pack(fmt, version, msg_type, msg_len, xid) \ + + data + + res = OFPHello.parser(object, version, msg_type, msg_len, xid, + bytearray(buf)) + + eq_(version, res.version) + eq_(msg_type, res.msg_type) + eq_(msg_len, res.msg_len) eq_(xid, res.xid) + eq_(buffer(buf), res.buf) # test __str__() list_ = ('version:', 'msg_type', 'xid') diff --git a/ryu/tests/unit/ofproto/test_parser_v12.py b/ryu/tests/unit/ofproto/test_parser_v12.py index 5efd527a..7f38725a 100644 --- a/ryu/tests/unit/ofproto/test_parser_v12.py +++ b/ryu/tests/unit/ofproto/test_parser_v12.py @@ -85,18 +85,24 @@ class TestOFPHello(unittest.TestCase): pass def test_parser(self): + version = ofproto_v1_2.OFP_VERSION + msg_type = ofproto_v1_2.OFPT_HELLO + msg_len = ofproto_v1_2.OFP_HEADER_SIZE xid = 2183948390 - res = OFPHello.parser(object, - ofproto_v1_2.OFP_VERSION, - ofproto_v1_2.OFPT_HELLO, - ofproto_v1_2.OFP_HEADER_SIZE, - xid, - str().zfill(ofproto_v1_2.OFP_HEADER_SIZE)) - - eq_(ofproto_v1_2.OFP_VERSION, res.version) - eq_(ofproto_v1_2.OFPT_HELLO, res.msg_type) - eq_(ofproto_v1_2.OFP_HEADER_SIZE, res.msg_len) + data = '\x00\x01\x02\x03' + + fmt = ofproto_v1_2.OFP_HEADER_PACK_STR + buf = pack(fmt, version, msg_type, msg_len, xid) \ + + data + + res = OFPHello.parser(object, version, msg_type, msg_len, xid, + bytearray(buf)) + + eq_(version, res.version) + eq_(msg_type, res.msg_type) + eq_(msg_len, res.msg_len) eq_(xid, res.xid) + eq_(buffer(buf), res.buf) def test_serialize(self): |