Commit 8e06ee76 authored by Jelte Jansen's avatar Jelte Jansen

found bug when to/fromwiring empty lists

added unittest


git-svn-id: svn://bind10.isc.org/svn/bind10/branches/jelte-configuration@809 e5f2f494-b856-4b98-b285-d166d9295462
parent 04f3eb1b
......@@ -829,13 +829,19 @@ ListElement::toWire(std::stringstream& ss, int omit_length)
(*it)->toWire(ss2, 0);
}
if (omit_length) {
ss << ss2.rdbuf();
stringbuf *ss2_buf = ss2.rdbuf();
if (ss2_buf->in_avail() > 0) {
ss << ss2_buf;
}
} else {
stringbuf *ss2_buf = ss2.rdbuf();
ss2_buf->pubseekpos(0);
ss << encode_length(ss2_buf->in_avail(), ITEM_LIST);
ss << ss2_buf;
if (ss2_buf->in_avail() > 0) {
ss << ss2_buf;
}
}
}
......@@ -873,13 +879,17 @@ MapElement::toWire(std::stringstream& ss, int omit_length)
// add length if needed
//
if (omit_length) {
ss << ss2.rdbuf();
stringbuf *ss2_buf = ss2.rdbuf();
if (ss2_buf->in_avail() > 0) {
ss << ss2_buf;
}
} else {
stringbuf *ss2_buf = ss2.rdbuf();
ss2_buf->pubseekpos(0);
ss << encode_length(ss2_buf->in_avail(), ITEM_HASH);
ss << ss2_buf;
if (ss2_buf->in_avail() > 0) {
ss << ss2_buf;
}
}
}
......
......@@ -266,5 +266,13 @@ TEST(Element, to_and_from_wire) {
//EXPECT_EQ("\047\0031.2", Element::create(1.2)->toWire(0));
EXPECT_EQ("\046\0011", Element::createFromString("[ 1 ]")->toWire(1));
std::string ddef = "{\"data_specification\": {\"config_data\": [ {\"item_default\": \"Hello, world!\", \"item_name\": \"default_name\", \"item_optional\": False, \"item_type\": \"string\"}, {\"item_default\": [ ], \"item_name\": \"zone_list\", \"item_optional\": False, \"item_type\": \"list\", \"list_item_spec\": {\"item_name\": \"zone_name\", \"item_optional\": True, \"item_type\": \"string\"}} ], \"module_name\": \"Auth\"}}";
//std::string ddef = "{\"aaa\": 123, \"test\": [ ], \"zzz\": 123}";
ElementPtr ddef_el = Element::createFromString(ddef);
std::string ddef_wire = ddef_el->toWire();
ElementPtr ddef_el2 = Element::fromWire(ddef_wire);
std::string ddef2 = ddef_el2->str();
EXPECT_EQ(ddef, ddef2);
}
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