Commit 67ff28d5 authored by chenzhengzhang's avatar chenzhengzhang
Browse files

[trac253] fix some comments and unittest

parent 3c06d0d6
...@@ -38,7 +38,6 @@ static PyObject* MessageRenderer_getLength(s_MessageRenderer* self); ...@@ -38,7 +38,6 @@ static PyObject* MessageRenderer_getLength(s_MessageRenderer* self);
static PyObject* MessageRenderer_isTruncated(s_MessageRenderer* self); static PyObject* MessageRenderer_isTruncated(s_MessageRenderer* self);
static PyObject* MessageRenderer_getLengthLimit(s_MessageRenderer* self); static PyObject* MessageRenderer_getLengthLimit(s_MessageRenderer* self);
static PyObject* MessageRenderer_getCompressMode(s_MessageRenderer* self); static PyObject* MessageRenderer_getCompressMode(s_MessageRenderer* self);
// TODO: set/get compressmode
static PyObject* MessageRenderer_setTruncated(s_MessageRenderer* self); static PyObject* MessageRenderer_setTruncated(s_MessageRenderer* self);
static PyObject* MessageRenderer_setLengthLimit(s_MessageRenderer* self, PyObject* args); static PyObject* MessageRenderer_setLengthLimit(s_MessageRenderer* self, PyObject* args);
static PyObject* MessageRenderer_setCompressMode(s_MessageRenderer* self, PyObject* args); static PyObject* MessageRenderer_setCompressMode(s_MessageRenderer* self, PyObject* args);
...@@ -206,7 +205,8 @@ MessageRenderer_setCompressMode(s_MessageRenderer* self, ...@@ -206,7 +205,8 @@ MessageRenderer_setCompressMode(s_MessageRenderer* self,
Py_RETURN_NONE; Py_RETURN_NONE;
} else { } else {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"Message mode must be Message.PARSE or Message.RENDER"); "MessageRenderer compress mode must be MessageRenderer.CASE_INSENSITIVE"
"or MessageRenderer.CASE_SENSITIVE");
return (NULL); return (NULL);
} }
} }
......
...@@ -28,7 +28,7 @@ class MessageRendererTest(unittest.TestCase): ...@@ -28,7 +28,7 @@ class MessageRendererTest(unittest.TestCase):
c = RRClass("IN") c = RRClass("IN")
t = RRType("A") t = RRType("A")
ttl = RRTTL("3600") ttl = RRTTL("3600")
message = Message(Message.RENDER) message = Message(Message.RENDER)
message.set_qid(123) message.set_qid(123)
message.set_opcode(Opcode.QUERY()) message.set_opcode(Opcode.QUERY())
...@@ -56,14 +56,14 @@ class MessageRendererTest(unittest.TestCase): ...@@ -56,14 +56,14 @@ class MessageRendererTest(unittest.TestCase):
self.message1.to_wire(self.renderer1) self.message1.to_wire(self.renderer1)
self.message2.to_wire(self.renderer2) self.message2.to_wire(self.renderer2)
self.message2.to_wire(self.renderer3) self.message2.to_wire(self.renderer3)
def test_messagerenderer_get_data(self): def test_messagerenderer_get_data(self):
data1 = b'\x00{\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x07example\x03com\x00\x00\x01\x00\x01' data1 = b'\x00{\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x07example\x03com\x00\x00\x01\x00\x01'
self.assertEqual(data1, self.renderer1.get_data()) self.assertEqual(data1, self.renderer1.get_data())
data2 = b'\x00{\x84\x00\x00\x01\x00\x00\x00\x02\x00\x00\x07example\x03com\x00\x00\x01\x00\x01\xc0\x0c\x00\x01\x00\x01\x00\x00\x0e\x10\x00\x04\xc0\x00\x02b\xc0\x0c\x00\x01\x00\x01\x00\x00\x0e\x10\x00\x04\xc0\x00\x02c' data2 = b'\x00{\x84\x00\x00\x01\x00\x00\x00\x02\x00\x00\x07example\x03com\x00\x00\x01\x00\x01\xc0\x0c\x00\x01\x00\x01\x00\x00\x0e\x10\x00\x04\xc0\x00\x02b\xc0\x0c\x00\x01\x00\x01\x00\x00\x0e\x10\x00\x04\xc0\x00\x02c'
self.assertEqual(data2, self.renderer2.get_data()) self.assertEqual(data2, self.renderer2.get_data())
def test_messagerenderer_get_length(self): def test_messagerenderer_get_length(self):
self.assertEqual(29, self.renderer1.get_length()) self.assertEqual(29, self.renderer1.get_length())
self.assertEqual(61, self.renderer2.get_length()) self.assertEqual(61, self.renderer2.get_length())
...@@ -106,6 +106,9 @@ class MessageRendererTest(unittest.TestCase): ...@@ -106,6 +106,9 @@ class MessageRendererTest(unittest.TestCase):
renderer.set_compress_mode(MessageRenderer.CASE_SENSITIVE) renderer.set_compress_mode(MessageRenderer.CASE_SENSITIVE)
self.assertEqual(MessageRenderer.CASE_SENSITIVE, self.assertEqual(MessageRenderer.CASE_SENSITIVE,
renderer.get_compress_mode()) renderer.get_compress_mode())
renderer.set_compress_mode(MessageRenderer.CASE_INSENSITIVE)
self.assertEqual(MessageRenderer.CASE_INSENSITIVE,
renderer.get_compress_mode())
self.assertRaises(TypeError, renderer.set_compress_mode, "wrong") self.assertRaises(TypeError, renderer.set_compress_mode, "wrong")
if __name__ == '__main__': if __name__ == '__main__':
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment