]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
test/formatter: test stream clearing
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Thu, 4 Aug 2011 21:11:42 +0000 (14:11 -0700)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Thu, 4 Aug 2011 21:11:42 +0000 (14:11 -0700)
Signed-off-by: Colin McCabe <colin.mccabe@dreamhost.com>
src/test/formatter.cc

index eec69bf7ad1c7658ec22d3d849e1657ca88fdd3c..61e725264bcc41f919b145633ab5a67312b4f306 100644 (file)
@@ -139,3 +139,26 @@ TEST(XmlFormatter, DTD) {
   ASSERT_EQ(oss.str(), "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
     "<foo><blah>hithere</blah><pi>3.14</pi></foo>");
 }
+
+TEST(XmlFormatter, Clear) {
+  ostringstream oss;
+  XMLFormatter fmt(false);
+
+  fmt.write_raw_data(XMLFormatter::XML_1_DTD);
+  fmt.open_array_section("foo");
+  fmt.dump_stream("blah") << "hithere";
+  fmt.dump_float("pi", 3.14);
+  fmt.close_section();
+  fmt.flush(oss);
+  ASSERT_EQ(oss.str(), "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+    "<foo><blah>hithere</blah><pi>3.14</pi></foo>");
+
+  ostringstream oss2;
+  fmt.flush(oss2);
+  ASSERT_EQ(oss2.str(), "");
+
+  ostringstream oss3;
+  fmt.reset();
+  fmt.flush(oss3);
+  ASSERT_EQ(oss3.str(), "");
+}