1 #define BOOST_AUTO_TEST_MAIN
2 #include <boost/test/auto_unit_test.hpp>
4 #include <boost/shared_ptr.hpp>
5 #include "annotations.hpp"
6 #include "mussa_exceptions.hpp"
8 BOOST_AUTO_TEST_CASE( annotations_constructors )
11 BOOST_CHECK_EQUAL(a.name(), "");
14 BOOST_CHECK_EQUAL(b.name(), "bee");
16 boost::shared_ptr<Annotations> asp(new Annotations);
17 BOOST_CHECK_EQUAL(asp->name(), "");
19 boost::shared_ptr<Annotations> bsp(new Annotations("bee pointer"));
20 BOOST_CHECK_EQUAL(bsp->name(), "bee pointer");
23 BOOST_AUTO_TEST_CASE( annotations_copy_constructor )
25 AnnotationsRef a(new Annotations("a"));
27 AnnotationsRef c(new Annotations(a));
29 // b is a copy of a's pointer and thus changes
32 BOOST_CHECK_EQUAL(a->name(), "bee");
33 BOOST_CHECK_EQUAL(b->name(), "bee");
35 // c is a copy of a, and not a pointer to a
36 // so updates of a, b wont affect c and vice versa
37 BOOST_CHECK_EQUAL(c->name(), "a");
39 BOOST_CHECK_EQUAL(c->name(), "cee");
41 BOOST_CHECK_EQUAL(a->name(), "bee");
42 BOOST_CHECK_EQUAL(b->name(), "bee");
46 BOOST_AUTO_TEST_CASE( annotations_get_metadata )
48 boost::shared_ptr<Annotations> asp(new Annotations("asp"));
49 asp->set("header", "> amsp");
51 BOOST_CHECK_EQUAL( asp->size(), 2 );
52 BOOST_CHECK_EQUAL( asp->get("header"), "> amsp" );
53 BOOST_CHECK_THROW( asp->get("not there"), annotations_key_error );
57 BOOST_AUTO_TEST_CASE( annotations_getdefault_metadata )
59 boost::shared_ptr<Annotations> asp(new Annotations("asp"));
60 asp->set("header", "> amsp");
62 BOOST_CHECK_EQUAL( asp->size(), 2 );
63 BOOST_CHECK_EQUAL( asp->getdefault("header", "foo"), "> amsp" );
64 BOOST_CHECK_EQUAL( asp->getdefault("not there", "foo"), "foo" );
66 BOOST_AUTO_TEST_CASE( annotations_has_key )
68 boost::shared_ptr<Annotations> asp(new Annotations("asp"));
69 asp->set("header", "> amsp");
71 BOOST_CHECK_EQUAL(asp->has_key("header"), true);
72 BOOST_CHECK_EQUAL(asp->has_key("name"), true);
73 BOOST_CHECK_EQUAL(asp->has_key("secret"), false);