encoding: Fixing Block (and as a result Name) encoding bugs

As of this commit, all non-const operations on Block will call resetWire
to remove all references to the wire, so it will be recreated next time
"encode" method is called.  Also, all getter methods now have only const
versions and non-const access to the internal data structure is
prohibited.

Change-Id: If4b485dd62541d9d4d168a44490068e4deff56c1
diff --git a/tests/test-name.cpp b/tests/test-name.cpp
index b6501d6..cabfd2f 100644
--- a/tests/test-name.cpp
+++ b/tests/test-name.cpp
@@ -41,8 +41,8 @@
   //   }
   // std::cout << std::endl;
   
-  BOOST_REQUIRE_EQUAL_COLLECTIONS(TestName, TestName+sizeof(TestName),
-                                  wire.begin(), wire.end());
+  BOOST_CHECK_EQUAL_COLLECTIONS(TestName, TestName+sizeof(TestName),
+                                wire.begin(), wire.end());
 }
 
 
@@ -55,6 +55,33 @@
   BOOST_CHECK_EQUAL(name.toUri(), "/local/ndn/prefix");
 }
 
+BOOST_AUTO_TEST_CASE (AppendsAndMultiEncode)
+{
+  Name name("/local");
+
+  const uint8_t name1[] = {0x3,  0x7, // Name
+                           0x4,  0x5, // NameComponent
+                           0x6c,  0x6f,  0x63,  0x61,  0x6c};
+  
+  BOOST_CHECK_EQUAL_COLLECTIONS(name.wireEncode().begin(), name.wireEncode().end(),
+                                name1, name1 + sizeof(name1));
+
+  name.append("ndn");
+  
+  const uint8_t name2[] = {0x3,  0xc, // Name
+                           0x4,  0x5, // NameComponent
+                           0x6c,  0x6f,  0x63,  0x61,  0x6c,
+                           0x4,  0x3, // NameComponent
+                           0x6e,  0x64,  0x6e};
+  
+  BOOST_CHECK_EQUAL_COLLECTIONS(name.wireEncode().begin(), name.wireEncode().end(),
+                                name2, name2 + sizeof(name2));
+
+  name.append("prefix");
+  BOOST_CHECK_EQUAL_COLLECTIONS(name.wireEncode().begin(), name.wireEncode().end(),
+                                TestName, TestName+sizeof(TestName));
+}
+
 BOOST_AUTO_TEST_SUITE_END()
 
 } // namespace ndn