create a metadata holding class
[mussa.git] / alg / test / test_annotations.cpp
diff --git a/alg/test/test_annotations.cpp b/alg/test/test_annotations.cpp
new file mode 100644 (file)
index 0000000..8bb0bea
--- /dev/null
@@ -0,0 +1,64 @@
+#define BOOST_AUTO_TEST_MAIN
+#include <boost/test/auto_unit_test.hpp>
+
+#include <boost/shared_ptr.hpp>
+#include "annotations.hpp"
+#include "mussa_exceptions.hpp"
+
+BOOST_AUTO_TEST_CASE( annotations_constructors )
+{
+  Annotations a;
+  BOOST_CHECK_EQUAL(a.name(), "");
+  
+  Annotations b("bee");
+  BOOST_CHECK_EQUAL(b.name(), "bee");
+  
+  boost::shared_ptr<Annotations> asp(new Annotations);
+  BOOST_CHECK_EQUAL(asp->name(), "");
+  
+  boost::shared_ptr<Annotations> bsp(new Annotations("bee pointer"));
+  BOOST_CHECK_EQUAL(bsp->name(), "bee pointer");
+}
+
+BOOST_AUTO_TEST_CASE( annotations_copy_constructor )
+{
+  AnnotationsRef a(new Annotations("a"));
+  AnnotationsRef b(a);
+  AnnotationsRef c(new Annotations(a));
+
+  // b is a copy of a's pointer and thus changes
+  // to b update a   
+  b->setName("bee");
+  BOOST_CHECK_EQUAL(a->name(), "bee");
+  BOOST_CHECK_EQUAL(b->name(), "bee");
+
+  // c is a copy of a, and not a pointer to a
+  // so updates of a, b wont affect c and vice versa  
+  BOOST_CHECK_EQUAL(c->name(), "a");
+  c->setName("cee");
+  BOOST_CHECK_EQUAL(c->name(), "cee");
+
+  BOOST_CHECK_EQUAL(a->name(), "bee");
+  BOOST_CHECK_EQUAL(b->name(), "bee");
+  
+}
+
+BOOST_AUTO_TEST_CASE( annotations_get_metadata )
+{
+  boost::shared_ptr<Annotations> asp(new Annotations("asp"));
+  asp->set("header", "> amsp");
+  
+  BOOST_CHECK_EQUAL( asp->size(), 2 );
+  BOOST_CHECK_EQUAL( asp->get("header"), "> amsp" );
+  BOOST_CHECK_THROW( asp->get("not there"), annotations_key_error ); 
+}
+
+BOOST_AUTO_TEST_CASE( annotations_has_key )
+{
+  boost::shared_ptr<Annotations> asp(new Annotations("asp"));
+  asp->set("header", "> amsp");
+  
+  BOOST_CHECK_EQUAL(asp->has_key("header"), true);
+  BOOST_CHECK_EQUAL(asp->has_key("name"), true);
+  BOOST_CHECK_EQUAL(asp->has_key("secret"), false);
+}
\ No newline at end of file