Update mussa to build on ubuntu 10.04 with qt 4.6.2 +boost 1.40.0.1
[mussa.git] / alg / test / test_annotations.cpp
1 #define BOOST_TEST_DYN_LINK
2 #define BOOST_TEST_MODULE test_annotations
3 #include <boost/test/unit_test.hpp>
4
5 #include <boost/shared_ptr.hpp>
6 #include "annotations.hpp"
7 #include "mussa_exceptions.hpp"
8
9 BOOST_AUTO_TEST_CASE( annotations_constructors )
10 {
11   Annotations a;
12   BOOST_CHECK_EQUAL(a.name(), "");
13   
14   Annotations b("bee");
15   BOOST_CHECK_EQUAL(b.name(), "bee");
16   
17   boost::shared_ptr<Annotations> asp(new Annotations);
18   BOOST_CHECK_EQUAL(asp->name(), "");
19   
20   boost::shared_ptr<Annotations> bsp(new Annotations("bee pointer"));
21   BOOST_CHECK_EQUAL(bsp->name(), "bee pointer");
22 }
23
24 BOOST_AUTO_TEST_CASE( annotations_copy_constructor )
25 {
26   AnnotationsRef a(new Annotations("a"));
27   AnnotationsRef b(a);
28   AnnotationsRef c(new Annotations(a));
29
30   // b is a copy of a's pointer and thus changes
31   // to b update a   
32   b->setName("bee");
33   BOOST_CHECK_EQUAL(a->name(), "bee");
34   BOOST_CHECK_EQUAL(b->name(), "bee");
35
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");
39   c->setName("cee");
40   BOOST_CHECK_EQUAL(c->name(), "cee");
41
42   BOOST_CHECK_EQUAL(a->name(), "bee");
43   BOOST_CHECK_EQUAL(b->name(), "bee");
44   
45 }
46
47 BOOST_AUTO_TEST_CASE( annotations_get_metadata )
48 {
49   boost::shared_ptr<Annotations> asp(new Annotations("asp"));
50   asp->set("header", "> amsp");
51   
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 ); 
55 }
56
57
58 BOOST_AUTO_TEST_CASE( annotations_getdefault_metadata )
59 {
60   boost::shared_ptr<Annotations> asp(new Annotations("asp"));
61   asp->set("header", "> amsp");
62   
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" ); 
66 }
67 BOOST_AUTO_TEST_CASE( annotations_has_key )
68 {
69   boost::shared_ptr<Annotations> asp(new Annotations("asp"));
70   asp->set("header", "> amsp");
71   
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);
75 }
76