diff options
author | Jelte Jansen <jelte@isc.org> | 2010-06-27 19:04:17 +0200 |
---|---|---|
committer | Jelte Jansen <jelte@isc.org> | 2010-06-27 19:04:17 +0200 |
commit | a4939e499f8a0a961f3358d505870826422069ed (patch) | |
tree | 57131ea0e8dff8777c42829ac6b1ee098dae14c0 | |
parent | removed some constants which weren't used anymore (diff) | |
download | kea-a4939e499f8a0a961f3358d505870826422069ed.tar.xz kea-a4939e499f8a0a961f3358d505870826422069ed.zip |
addressed first part of review comments
git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac172@2295 e5f2f494-b856-4b98-b285-d166d9295462
-rw-r--r-- | src/lib/cc/data.h | 12 | ||||
-rw-r--r-- | src/lib/cc/data_unittests.cc | 192 | ||||
-rw-r--r-- | src/lib/python/isc/cc/tests/Makefile.am | 3 | ||||
-rw-r--r-- | src/lib/python/isc/cc/tests/session_test.py | 4 | ||||
-rw-r--r-- | src/lib/python/isc/cc/tests/test.py | 109 |
5 files changed, 128 insertions, 192 deletions
diff --git a/src/lib/cc/data.h b/src/lib/cc/data.h index 1567db7dc4..d704c7c286 100644 --- a/src/lib/cc/data.h +++ b/src/lib/cc/data.h @@ -92,10 +92,6 @@ public: /// \return the type of this element int getType() { return type; }; - /// \returns true if the other ElementPtr has the same type and - /// value - virtual bool equals(ElementPtr other) = 0; - /// Returns a string representing the Element and all its /// child elements; note that this is different from stringValue(), /// which only returns the single value of a StringElement @@ -108,14 +104,16 @@ public: /// Returns the wireformat for the Element and all its child /// elements. /// - /// \param omit_length If this is non-zero, the item length will - /// be omitted from the wire format /// \return std::string containing the element in wire format std::string toWire(); void toWire(std::ostream& out); - // pure virtuals, every derived class must implement these + /// \name pure virtuals, every derived class must implement these + /// \returns true if the other ElementPtr has the same type and + /// value + virtual bool equals(ElementPtr other) = 0; + /// Converts the Element to JSON format and appends it to /// the given stringstream. virtual void toJSON(std::ostream& ss) = 0; diff --git a/src/lib/cc/data_unittests.cc b/src/lib/cc/data_unittests.cc index ed4ff148b8..0144b57b5b 100644 --- a/src/lib/cc/data_unittests.cc +++ b/src/lib/cc/data_unittests.cc @@ -107,8 +107,10 @@ TEST(Element, from_and_to_json) { EXPECT_EQ("1", Element::fromJSON("1.0")->str()); EXPECT_EQ("120", Element::fromJSON("1.2e2")->str()); EXPECT_EQ("100", Element::fromJSON("1.0e2")->str()); + EXPECT_EQ("100", Element::fromJSON("1.0E2")->str()); EXPECT_EQ("0.01", Element::fromJSON("1.0e-2")->str()); EXPECT_EQ("0.012", Element::fromJSON("1.2e-2")->str()); + EXPECT_EQ("0.012", Element::fromJSON("1.2E-2")->str()); // number overflows EXPECT_THROW(Element::fromJSON("12345678901234567890")->str(), JSONError); @@ -132,6 +134,7 @@ TEST(Element, create_and_value_throws) { el = Element::create(1); + EXPECT_NO_THROW(el->intValue()); EXPECT_THROW(el->doubleValue(), TypeError); EXPECT_THROW(el->boolValue(), TypeError); EXPECT_THROW(el->stringValue(), TypeError); @@ -167,6 +170,7 @@ TEST(Element, create_and_value_throws) { el = Element::create(1.1); EXPECT_THROW(el->intValue(), TypeError); + EXPECT_NO_THROW(el->doubleValue()); EXPECT_THROW(el->boolValue(), TypeError); EXPECT_THROW(el->stringValue(), TypeError); EXPECT_THROW(el->listValue(), TypeError); @@ -190,6 +194,7 @@ TEST(Element, create_and_value_throws) { el = Element::create(true); EXPECT_THROW(el->intValue(), TypeError); EXPECT_THROW(el->doubleValue(), TypeError); + EXPECT_NO_THROW(el->boolValue()); EXPECT_THROW(el->stringValue(), TypeError); EXPECT_THROW(el->listValue(), TypeError); EXPECT_THROW(el->mapValue(), TypeError); @@ -208,6 +213,7 @@ TEST(Element, create_and_value_throws) { EXPECT_THROW(el->intValue(), TypeError); EXPECT_THROW(el->doubleValue(), TypeError); EXPECT_THROW(el->boolValue(), TypeError); + EXPECT_NO_THROW(el->stringValue()); EXPECT_THROW(el->listValue(), TypeError); EXPECT_THROW(el->mapValue(), TypeError); EXPECT_FALSE(el->getValue(i)); @@ -226,6 +232,7 @@ TEST(Element, create_and_value_throws) { EXPECT_THROW(el->doubleValue(), TypeError); EXPECT_THROW(el->boolValue(), TypeError); EXPECT_THROW(el->stringValue(), TypeError); + EXPECT_NO_THROW(el->listValue()); EXPECT_THROW(el->mapValue(), TypeError); EXPECT_FALSE(el->getValue(i)); EXPECT_FALSE(el->getValue(d)); @@ -244,6 +251,7 @@ TEST(Element, create_and_value_throws) { EXPECT_THROW(el->boolValue(), TypeError); EXPECT_THROW(el->stringValue(), TypeError); EXPECT_THROW(el->listValue(), TypeError); + EXPECT_NO_THROW(el->mapValue()); EXPECT_FALSE(el->getValue(i)); EXPECT_FALSE(el->getValue(d)); EXPECT_FALSE(el->getValue(b)); @@ -277,15 +285,6 @@ TEST(Element, ListElement) { EXPECT_EQ(el->get(2)->intValue(), 32); } -namespace { -const string long_maptag("0123456789abcdef1123456789abcdef2123456789abcdef" - "3123456789abcdef4123456789abcdef5123456789abcdef" - "6123456789abcdef7123456789abcdef8123456789abcdef" - "9123456789abcdefa123456789abcdefb123456789abcdef" - "c123456789abcdefd123456789abcdefe123456789abcdef" - "f123456789abcdef"); -} - TEST(Element, MapElement) { // this function checks the specific functions for ListElements ElementPtr el = Element::fromJSON("{ \"name\": \"foo\", \"value1\": \"bar\", \"value2\": { \"number\": 42 } }"); @@ -362,56 +361,56 @@ ElementPtr efs(const std::string& str) { TEST(Element, equals) { // why does EXPECT_EQ not work? - EXPECT_TRUE(efs("1") == efs("1")); - EXPECT_FALSE(efs("1") == efs("2")); - EXPECT_FALSE(efs("1") == efs("\"1\"")); - EXPECT_FALSE(efs("1") == efs("[]")); - EXPECT_FALSE(efs("1") == efs("True")); - EXPECT_FALSE(efs("1") == efs("{}")); - - EXPECT_TRUE(efs("1.1") == efs("1.1")); - EXPECT_FALSE(efs("1.0") == efs("1")); - EXPECT_FALSE(efs("1.1") == efs("\"1\"")); - EXPECT_FALSE(efs("1.1") == efs("[]")); - EXPECT_FALSE(efs("1.1") == efs("True")); - EXPECT_FALSE(efs("1.1") == efs("{}")); - - EXPECT_TRUE(efs("True") == efs("True")); - EXPECT_FALSE(efs("True") == efs("False")); - EXPECT_FALSE(efs("True") == efs("1")); - EXPECT_FALSE(efs("True") == efs("\"1\"")); - EXPECT_FALSE(efs("True") == efs("[]")); - EXPECT_FALSE(efs("True") == efs("{}")); - - EXPECT_TRUE(efs("\"foo\"") == efs("\"foo\"")); - EXPECT_FALSE(efs("\"foo\"") == efs("\"bar\"")); - EXPECT_FALSE(efs("\"foo\"") == efs("1")); - EXPECT_FALSE(efs("\"foo\"") == efs("\"1\"")); - EXPECT_FALSE(efs("\"foo\"") == efs("True")); - EXPECT_FALSE(efs("\"foo\"") == efs("[]")); - EXPECT_FALSE(efs("\"foo\"") == efs("{}")); - - EXPECT_TRUE(efs("[]") == efs("[]")); - EXPECT_TRUE(efs("[ 1, 2, 3 ]") == efs("[ 1, 2, 3 ]")); - EXPECT_TRUE(efs("[ \"a\", [ True, 1], 2.2 ]") == efs("[ \"a\", [ True, 1], 2.2 ]")); - EXPECT_FALSE(efs("[ \"a\", [ True, 1], 2.2 ]") == efs("[ \"a\", [ True, 2], 2.2 ]")); - EXPECT_FALSE(efs("[]") == efs("[1]")); - EXPECT_FALSE(efs("[]") == efs("1")); - EXPECT_FALSE(efs("[]") == efs("\"1\"")); - EXPECT_FALSE(efs("[]") == efs("{}")); - - EXPECT_TRUE(efs("{}") == efs("{}")); - EXPECT_TRUE(efs("{ \"foo\": \"bar\" }") == efs("{ \"foo\": \"bar\" }")); - EXPECT_TRUE(efs("{ \"item1\": 1, \"item2\": [ \"a\", \"list\" ], \"item3\": { \"foo\": \"bar\" } }") == efs("{ \"item1\": 1, \"item2\": [ \"a\", \"list\" ], \"item3\": { \"foo\": \"bar\" } }")); - EXPECT_FALSE(efs("{ \"item1\": 1, \"item2\": [ \"a\", \"list\" ], \"item3\": { \"foo\": \"bar\" } }") == efs("{ \"item1\": 1, \"item2\": [ \"a\", \"list\" ], \"item3\": { \"foo\": \"bar2\" } }")); - EXPECT_FALSE(efs("{ \"item1\": 1, \"item2\": [ \"a\", \"list\" ], \"item3\": { \"foo\": \"bar\" } }") == efs("{ \"item1\": 1, \"item2\": [ \"a\", \"list\", 1 ], \"item3\": { \"foo\": \"bar\" } }")); - EXPECT_FALSE(efs("{ \"foo\": \"bar\" }") == efs("1")); - EXPECT_FALSE(efs("{ \"foo\": \"bar\" }") == efs("\"1\"")); - EXPECT_FALSE(efs("{ \"foo\": \"bar\" }") == efs("[]")); - EXPECT_FALSE(efs("{ \"foo\": \"bar\" }") == efs("{}")); - EXPECT_FALSE(efs("{ \"foo\": \"bar\" }") == efs("{ \"something\": \"different\" }")); - - EXPECT_TRUE(efs("null") == Element::create()); + EXPECT_EQ(efs("1"), efs("1")); + EXPECT_NE(efs("1"), efs("2")); + EXPECT_NE(efs("1"), efs("\"1\"")); + EXPECT_NE(efs("1"), efs("[]")); + EXPECT_NE(efs("1"), efs("True")); + EXPECT_NE(efs("1"), efs("{}")); + + EXPECT_EQ(efs("1.1"), efs("1.1")); + EXPECT_NE(efs("1.0"), efs("1")); + EXPECT_NE(efs("1.1"), efs("\"1\"")); + EXPECT_NE(efs("1.1"), efs("[]")); + EXPECT_NE(efs("1.1"), efs("True")); + EXPECT_NE(efs("1.1"), efs("{}")); + + EXPECT_EQ(efs("True"), efs("True")); + EXPECT_NE(efs("True"), efs("False")); + EXPECT_NE(efs("True"), efs("1")); + EXPECT_NE(efs("True"), efs("\"1\"")); + EXPECT_NE(efs("True"), efs("[]")); + EXPECT_NE(efs("True"), efs("{}")); + + EXPECT_EQ(efs("\"foo\""), efs("\"foo\"")); + EXPECT_NE(efs("\"foo\""), efs("\"bar\"")); + EXPECT_NE(efs("\"foo\""), efs("1")); + EXPECT_NE(efs("\"foo\""), efs("\"1\"")); + EXPECT_NE(efs("\"foo\""), efs("True")); + EXPECT_NE(efs("\"foo\""), efs("[]")); + EXPECT_NE(efs("\"foo\""), efs("{}")); + + EXPECT_EQ(efs("[]"), efs("[]")); + EXPECT_EQ(efs("[ 1, 2, 3 ]"), efs("[ 1, 2, 3 ]")); + EXPECT_EQ(efs("[ \"a\", [ True, 1], 2.2 ]"), efs("[ \"a\", [ True, 1], 2.2 ]")); + EXPECT_NE(efs("[ \"a\", [ True, 1], 2.2 ]"), efs("[ \"a\", [ True, 2], 2.2 ]")); + EXPECT_NE(efs("[]"), efs("[1]")); + EXPECT_NE(efs("[]"), efs("1")); + EXPECT_NE(efs("[]"), efs("\"1\"")); + EXPECT_NE(efs("[]"), efs("{}")); + + EXPECT_EQ(efs("{}"), efs("{}")); + EXPECT_EQ(efs("{ \"foo\": \"bar\" }"), efs("{ \"foo\": \"bar\" }")); + EXPECT_EQ(efs("{ \"item1\": 1, \"item2\": [ \"a\", \"list\" ], \"item3\": { \"foo\": \"bar\" } }"), efs("{ \"item1\": 1, \"item2\": [ \"a\", \"list\" ], \"item3\": { \"foo\": \"bar\" } }")); + EXPECT_NE(efs("{ \"item1\": 1, \"item2\": [ \"a\", \"list\" ], \"item3\": { \"foo\": \"bar\" } }"), efs("{ \"item1\": 1, \"item2\": [ \"a\", \"list\" ], \"item3\": { \"foo\": \"bar2\" } }")); + EXPECT_NE(efs("{ \"item1\": 1, \"item2\": [ \"a\", \"list\" ], \"item3\": { \"foo\": \"bar\" } }"), efs("{ \"item1\": 1, \"item2\": [ \"a\", \"list\", 1 ], \"item3\": { \"foo\": \"bar\" } }")); + EXPECT_NE(efs("{ \"foo\": \"bar\" }"), efs("1")); + EXPECT_NE(efs("{ \"foo\": \"bar\" }"), efs("\"1\"")); + EXPECT_NE(efs("{ \"foo\": \"bar\" }"), efs("[]")); + EXPECT_NE(efs("{ \"foo\": \"bar\" }"), efs("{}")); + EXPECT_NE(efs("{ \"foo\": \"bar\" }"), efs("{ \"something\": \"different\" }")); + + EXPECT_EQ(efs("null"), Element::create()); } TEST(Element, removeIdentical) { @@ -419,49 +418,49 @@ TEST(Element, removeIdentical) { ElementPtr b = Element::createMap(); ElementPtr c = Element::createMap(); removeIdentical(a, b); - EXPECT_TRUE(a == c); + EXPECT_EQ(a, c); a = Element::fromJSON("{ \"a\": 1 }"); b = Element::fromJSON("{ \"a\": 1 }"); c = Element::createMap(); removeIdentical(a, b); - EXPECT_TRUE(a == c); + EXPECT_EQ(a, c); a = Element::fromJSON("{ \"a\": 1, \"b\": [ 1, 2 ] }"); b = Element::createMap(); c = Element::fromJSON("{ \"a\": 1, \"b\": [ 1, 2 ] }"); removeIdentical(a, b); - EXPECT_TRUE(a == c); + EXPECT_EQ(a, c); a = Element::fromJSON("{ \"a\": 1, \"b\": [ 1, 2 ] }"); b = Element::fromJSON("{ \"a\": 1, \"b\": [ 1, 2 ] }"); c = Element::createMap(); removeIdentical(a, b); - EXPECT_TRUE(a == c); + EXPECT_EQ(a, c); a = Element::fromJSON("{ \"a\": 1, \"b\": [ 1, 2 ] }"); b = Element::fromJSON("{ \"a\": 1, \"b\": [ 1, 3 ] }"); c = Element::fromJSON("{ \"b\": [ 1, 2 ] }"); removeIdentical(a, b); - EXPECT_TRUE(a == c); + EXPECT_EQ(a, c); a = Element::fromJSON("{ \"a\": { \"b\": \"c\" } }"); b = Element::createMap(); c = Element::fromJSON("{ \"a\": { \"b\": \"c\" } }"); removeIdentical(a, b); - EXPECT_TRUE(a == c); + EXPECT_EQ(a, c); a = Element::fromJSON("{ \"a\": { \"b\": \"c\" } }"); b = Element::fromJSON("{ \"a\": { \"b\": \"c\" } }"); c = Element::createMap(); removeIdentical(a, b); - EXPECT_TRUE(a == c); + EXPECT_EQ(a, c); a = Element::fromJSON("{ \"a\": { \"b\": \"c\" } }"); b = Element::fromJSON("{ \"a\": { \"b\": \"d\" } }"); c = Element::fromJSON("{ \"a\": { \"b\": \"c\" } }"); removeIdentical(a, b); - EXPECT_TRUE(a == c); + EXPECT_EQ(a, c); EXPECT_THROW(removeIdentical(Element::create(1), Element::create(2)), TypeError); } @@ -472,7 +471,7 @@ TEST(Element, merge) ElementPtr b = Element::createMap(); ElementPtr c = Element::createMap(); merge(a, b); - EXPECT_TRUE(a == c); + EXPECT_EQ(a, c); a = Element::fromJSON("1"); b = Element::createMap(); @@ -482,24 +481,73 @@ TEST(Element, merge) b = Element::fromJSON("{ \"a\": 1 }"); c = Element::fromJSON("{ \"a\": 1 }"); merge(a, b); - EXPECT_TRUE(a == c); + EXPECT_EQ(a, c); + + a = Element::createMap(); + b = Element::fromJSON("{ \"a\": 1 }"); + c = Element::fromJSON("{ \"a\": 1 }"); + merge(b, a); + EXPECT_EQ(b, c); a = Element::fromJSON("{ \"a\": 1 }"); b = Element::fromJSON("{ \"a\": 2 }"); c = Element::fromJSON("{ \"a\": 2 }"); merge(a, b); - EXPECT_TRUE(a == c); + EXPECT_EQ(a, c); + + a = Element::fromJSON("{ \"a\": 1 }"); + b = Element::fromJSON("{ \"a\": 2 }"); + c = Element::fromJSON("{ \"a\": 1 }"); + merge(b, a); + EXPECT_EQ(b, c); a = Element::fromJSON("{ \"a\": { \"b\": \"c\" } }"); b = Element::fromJSON("{ \"a\": { \"b\": \"d\" } }"); c = Element::fromJSON("{ \"a\": { \"b\": \"d\" } }"); merge(a, b); - EXPECT_TRUE(a == c); + EXPECT_EQ(a, c); + + a = Element::fromJSON("{ \"a\": { \"b\": \"c\" } }"); + b = Element::fromJSON("{ \"a\": { \"b\": \"d\" } }"); + c = Element::fromJSON("{ \"a\": { \"b\": \"c\" } }"); + merge(b, a); + EXPECT_EQ(b, c); a = Element::fromJSON("{ \"a\": { \"b\": \"c\" } }"); b = Element::fromJSON("{ \"a\": null }"); c = Element::fromJSON("{ }"); merge(a, b); - EXPECT_TRUE(a == c); + EXPECT_EQ(a, c); + + a = Element::fromJSON("{ \"a\": { \"b\": \"c\" } }"); + b = Element::fromJSON("{ \"a\": null }"); + c = Element::fromJSON("{ \"a\": { \"b\": \"c\" } }"); + merge(b, a); + EXPECT_EQ(b, c); + + // And some tests with multiple values + a = Element::fromJSON("{ \"a\": 1, \"b\": true, \"c\": null }"); + b = Element::fromJSON("{ \"a\": 1, \"b\": null, \"c\": \"a string\" }"); + c = Element::fromJSON("{ \"a\": 1, \"c\": \"a string\" }"); + merge(a, b); + EXPECT_EQ(a, c); + + a = Element::fromJSON("{ \"a\": 1, \"b\": true, \"c\": null }"); + b = Element::fromJSON("{ \"a\": 1, \"b\": null, \"c\": \"a string\" }"); + c = Element::fromJSON("{ \"a\": 1, \"b\": true }"); + merge(b, a); + EXPECT_EQ(b, c); + + a = Element::fromJSON("{ \"a\": 1, \"b\": 2, \"c\": 3 }"); + b = Element::fromJSON("{ \"a\": 3, \"b\": 2, \"c\": 1 }"); + c = Element::fromJSON("{ \"a\": 3, \"b\": 2, \"c\": 1 }"); + merge(a, b); + EXPECT_EQ(a, c); + + a = Element::fromJSON("{ \"a\": 1, \"b\": 2, \"c\": 3 }"); + b = Element::fromJSON("{ \"a\": 3, \"b\": 2, \"c\": 1 }"); + c = Element::fromJSON("{ \"a\": 1, \"b\": 2, \"c\": 3 }"); + merge(b, a); + EXPECT_EQ(b, c); } diff --git a/src/lib/python/isc/cc/tests/Makefile.am b/src/lib/python/isc/cc/tests/Makefile.am index a3920925f9..5860ca99c1 100644 --- a/src/lib/python/isc/cc/tests/Makefile.am +++ b/src/lib/python/isc/cc/tests/Makefile.am @@ -1,5 +1,4 @@ -PYTESTS = message_test.py -#data_test.py session_test.py test.py +PYTESTS = message_test.py data_test.py session_test.py # NOTE: test_session.py is to be run manually, so not automated. EXTRA_DIST = $(PYTESTS) EXTRA_DIST += sendcmd.py diff --git a/src/lib/python/isc/cc/tests/session_test.py b/src/lib/python/isc/cc/tests/session_test.py index 284fe5d78f..08661920fa 100644 --- a/src/lib/python/isc/cc/tests/session_test.py +++ b/src/lib/python/isc/cc/tests/session_test.py @@ -39,8 +39,8 @@ class MySocket(): pass def send(self, data): - #print("[XX] send called:") - #print(data) + print("[XX] send called:") + print(data) self.sendqueue.extend(data); pass diff --git a/src/lib/python/isc/cc/tests/test.py b/src/lib/python/isc/cc/tests/test.py deleted file mode 100644 index 6c9c34f62b..0000000000 --- a/src/lib/python/isc/cc/tests/test.py +++ /dev/null @@ -1,109 +0,0 @@ -# -*- coding: UTF8 -*- - -import isc -import unittest - -class TestCCWireEncoding(unittest.TestCase): - def setUp(self): pass - - def test_to_wire_of_string(self): - wire = isc.cc.message.to_wire({ "simple" : "string" }) - self.assertEqual(wire, b'Skan\x06simple(\x06string') - - def test_from_wire_of_string(self): - wire = b'Skan\x06simple(\x06string' - decoded = isc.cc.message.from_wire(wire) - self.assertEqual(decoded["simple"], "string") - - def test_to_wire_of_binary_string(self): - wire = isc.cc.message.to_wire({ "simple" : b'\x01\xff\x02\x85' }) - self.assertEqual(wire, b'Skan\x06simple!\x04\x01\xff\x02\x85') - - def test_from_wire_of_binary_string(self): - wire = b'Skan\x06simple!\x04\x01\xff\x02\x85' - decoded = isc.cc.message.from_wire(wire) - self.assertEqual(decoded["simple"], b'\x01\xff\x02\x85') - - def test_to_wire_of_list(self): - wire = isc.cc.message.to_wire({ "simple" : [ "string" ] }) - self.assertEqual(wire, b'Skan\x06simple#\x08(\x06string') - - def test_from_wire_of_list(self): - wire = b'Skan\x06simple#\x08(\x06string' - decoded = isc.cc.message.from_wire(wire) - self.assertEqual(decoded["simple"], [ "string" ]) - - def test_to_wire_of_hash(self): - wire = isc.cc.message.to_wire({ "simple" : { "string" : 1 }}) - self.assertEqual(wire, b'Skan\x06simple"\n\x06string&\x011') - - def test_from_wire_of_hash(self): - wire = b'Skan\x06simple"\n\x06string(\x011' - decoded = isc.cc.message.from_wire(wire) - self.assertEqual(decoded["simple"], { "string" : '1' }) - - def test_to_wire_of_none(self): - wire = isc.cc.message.to_wire({ "simple" : None }) - self.assertEqual(wire, b'Skan\x06simple\x04') - - def test_from_wire_of_none(self): - wire = b'Skan\x06simple\x04' - decoded = isc.cc.message.from_wire(wire) - self.assertEqual(decoded["simple"], None) - - def test_to_wire_of_empty_string(self): - wire = isc.cc.message.to_wire({ "simple" : "" }) - self.assertEqual(wire, b'Skan\x06simple(\x00') - - def test_from_wire_of_empty_string(self): - wire = b'Skan\x06simple(\x00' - decoded = isc.cc.message.from_wire(wire) - self.assertEqual(decoded["simple"], "") - - def test_to_wire_of_utf8_string(self): - wire = isc.cc.message.to_wire({ "simple" : "せんせい" }) - self.assertEqual(wire, b'Skan\x06simple(\x0c\xe3\x81\x9b\xe3\x82\x93\xe3\x81\x9b\xe3\x81\x84') - - def test_from_wire_of_utf8_string(self): - wire = b'Skan\x06simple(\x0c\xe3\x81\x9b\xe3\x82\x93\xe3\x81\x9b\xe3\x81\x84' - decoded = isc.cc.message.from_wire(wire) - self.assertEqual(decoded["simple"], "せんせい") - - def test_to_wire_of_utf8_label(self): - wire = isc.cc.message.to_wire({ "せんせい" : "string" }) - self.assertEqual(wire, b'Skan\x0c\xe3\x81\x9b\xe3\x82\x93\xe3\x81\x9b\xe3\x81\x84(\x06string') - - def test_from_wire_of_utf8_label(self): - wire = b'Skan\x0c\xe3\x81\x9b\xe3\x82\x93\xe3\x81\x9b\xe3\x81\x84(\x06string' - decoded = isc.cc.message.from_wire(wire) - self.assertEqual(decoded["せんせい"], "string") - - def test_to_wire_of_bool_true(self): - wire = isc.cc.message.to_wire({ "bool": True }) - self.assertEqual(wire, b'Skan\x04bool%\x011') - - def test_to_wire_of_bool_false(self): - wire = isc.cc.message.to_wire({ "bool": False }) - self.assertEqual(wire, b'Skan\x04bool%\x010') - - def test_from_wire_of_bool_true(self): - wire = b'Skan\x04bool%\x01\x01' - decoded = isc.cc.message.from_wire(wire) - self.assertEqual(decoded["bool"], True) - - def test_from_wire_of_bool_true(self): - wire = b'Skan\x04bool%\x01\x00' - decoded = isc.cc.message.from_wire(wire) - self.assertEqual(decoded["bool"], False) - - def test_to_wire_of_int(self): - wire = isc.cc.message.to_wire({ "number": 123 }) - self.assertEqual(wire, b'Skan\x06number&\x03123') - - def test_from_wire_of_int(self): - wire = b'Skan\x06number&\x03123' - decoded = isc.cc.message.from_wire(wire) - self.assertEqual(decoded["number"], 123) - -if __name__ == '__main__': - unittest.main() |