[svn] commit: r809 - in /branches/jelte-configuration/src/lib/cc/cpp: data.cc data_unittests.cc
BIND 10 source code commits
bind10-changes at lists.isc.org
Fri Feb 12 14:36:24 UTC 2010
Author: jelte
Date: Fri Feb 12 14:36:24 2010
New Revision: 809
Log:
found bug when to/fromwiring empty lists
added unittest
Modified:
branches/jelte-configuration/src/lib/cc/cpp/data.cc
branches/jelte-configuration/src/lib/cc/cpp/data_unittests.cc
Modified: branches/jelte-configuration/src/lib/cc/cpp/data.cc
==============================================================================
--- branches/jelte-configuration/src/lib/cc/cpp/data.cc (original)
+++ branches/jelte-configuration/src/lib/cc/cpp/data.cc Fri Feb 12 14:36:24 2010
@@ -829,13 +829,19 @@
(*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 @@
// add length if needed
//
if (omit_length) {
- ss << ss2.rdbuf();
- } else {
-
+ 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;
+ }
}
}
Modified: branches/jelte-configuration/src/lib/cc/cpp/data_unittests.cc
==============================================================================
--- branches/jelte-configuration/src/lib/cc/cpp/data_unittests.cc (original)
+++ branches/jelte-configuration/src/lib/cc/cpp/data_unittests.cc Fri Feb 12 14:36:24 2010
@@ -266,5 +266,13 @@
//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);
+}
+
More information about the bind10-changes
mailing list