1 #define BOOST_TEST_DYN_LINK
2 #define BOOST_TEST_MODULE test_annotations
3 #include <boost/test/unit_test.hpp>
5 #include <boost/shared_ptr.hpp>
6 #include "annotations.hpp"
7 #include "mussa_exceptions.hpp"
9 BOOST_AUTO_TEST_CASE( annotations_constructors )
12 BOOST_CHECK_EQUAL(a.name(), "");
15 BOOST_CHECK_EQUAL(b.name(), "bee");
17 boost::shared_ptr<Annotations> asp(new Annotations);
18 BOOST_CHECK_EQUAL(asp->name(), "");
20 boost::shared_ptr<Annotations> bsp(new Annotations("bee pointer"));
21 BOOST_CHECK_EQUAL(bsp->name(), "bee pointer");
24 BOOST_AUTO_TEST_CASE( annotations_copy_constructor )
26 AnnotationsRef a(new Annotations("a"));
28 AnnotationsRef c(new Annotations(a));
30 // b is a copy of a's pointer and thus changes
33 BOOST_CHECK_EQUAL(a->name(), "bee");
34 BOOST_CHECK_EQUAL(b->name(), "bee");
36 // c is a copy of a, and not a pointer to a
37 // so updates of a, b wont affect c and vice versa
38 BOOST_CHECK_EQUAL(c->name(), "a");
40 BOOST_CHECK_EQUAL(c->name(), "cee");
42 BOOST_CHECK_EQUAL(a->name(), "bee");
43 BOOST_CHECK_EQUAL(b->name(), "bee");
47 BOOST_AUTO_TEST_CASE( annotations_get_metadata )
49 boost::shared_ptr<Annotations> asp(new Annotations("asp"));
50 asp->set("header", "> amsp");
52 BOOST_CHECK_EQUAL( asp->size(), 2 );
53 BOOST_CHECK_EQUAL( asp->get("header"), "> amsp" );
54 BOOST_CHECK_THROW( asp->get("not there"), annotations_key_error );
58 BOOST_AUTO_TEST_CASE( annotations_getdefault_metadata )
60 boost::shared_ptr<Annotations> asp(new Annotations("asp"));
61 asp->set("header", "> amsp");
63 BOOST_CHECK_EQUAL( asp->size(), 2 );
64 BOOST_CHECK_EQUAL( asp->getdefault("header", "foo"), "> amsp" );
65 BOOST_CHECK_EQUAL( asp->getdefault("not there", "foo"), "foo" );
67 BOOST_AUTO_TEST_CASE( annotations_has_key )
69 boost::shared_ptr<Annotations> asp(new Annotations("asp"));
70 asp->set("header", "> amsp");
72 BOOST_CHECK_EQUAL(asp->has_key("header"), true);
73 BOOST_CHECK_EQUAL(asp->has_key("name"), true);
74 BOOST_CHECK_EQUAL(asp->has_key("secret"), false);