Update mussa to build on ubuntu 10.04 with qt 4.6.2 +boost 1.40.0.1
[mussa.git] / alg / test / test_drawable.cpp
1 #define BOOST_TEST_DYN_LINK
2 #define BOOST_TEST_MODULE test_drawable
3 #include <boost/test/unit_test.hpp>
4
5 #include <boost/shared_ptr.hpp>
6
7 #include "drawable.hpp"
8 #include "seq_span.hpp"
9
10 BOOST_AUTO_TEST_CASE( drawable_empty_constructors )
11 {
12   Drawable a;
13   BOOST_CHECK_EQUAL(a.x(), 0);
14   BOOST_CHECK_EQUAL(a.y(), 0);
15   BOOST_CHECK_EQUAL(a.z(), 0);
16   BOOST_CHECK_EQUAL(a.height(), 0);
17   
18   DrawableRef asp(new Drawable);
19   BOOST_CHECK_EQUAL(asp->x(), 0);
20   BOOST_CHECK_EQUAL(asp->y(), 0);
21   BOOST_CHECK_EQUAL(asp->z(), 0);
22   BOOST_CHECK_EQUAL(asp->height(), 0);
23 }
24
25 BOOST_AUTO_TEST_CASE( drawable_filled_constructors )
26 {
27   ColorRef white(new Color(1.0, 1.0, 1.0));
28    
29   Drawable a(1.0,2.0,3.0,4.0, white);
30   BOOST_CHECK_EQUAL(a.x(), 1.0);
31   BOOST_CHECK_EQUAL(a.y(), 2.0);
32   BOOST_CHECK_EQUAL(a.z(), 3.0);
33   BOOST_CHECK_EQUAL(a.height(), 4.0);
34   BOOST_CHECK_EQUAL(*(a.color()), *white);
35   
36   DrawableRef asp(new Drawable(1.0,2.0,3.0,4.0, white));
37   BOOST_CHECK_EQUAL(asp->x(), 1.0);
38   BOOST_CHECK_EQUAL(asp->y(), 2.0);
39   BOOST_CHECK_EQUAL(asp->z(), 3.0);
40   BOOST_CHECK_EQUAL(asp->height(), 4.0);
41   BOOST_CHECK_EQUAL(*(asp->color()), *white);
42 }
43
44 BOOST_AUTO_TEST_CASE( drawable_copyref_constructor )
45 {
46   ColorRef white(new Color(1.0, 1.0, 1.0));
47   ColorRef grey(new Color(0.5, 0.5, 0.5));
48   ColorRef black(new Color(0.0, 0.0, 0.0));
49    
50   DrawableRef asp(new Drawable(1.0,1.0,1.0,1.0, white));
51   DrawableRef bsp(asp);
52   DrawableRef csp(new Drawable(asp));
53   
54   bsp->setX(2.0);
55   bsp->setColor(grey);
56   BOOST_CHECK_EQUAL(asp->x(), bsp->x());
57   BOOST_CHECK_EQUAL(asp->x(), 2.0);
58   BOOST_CHECK_EQUAL(*asp->color(), grey);
59
60   // csp shouldn't have changed
61   BOOST_CHECK_EQUAL(csp->x(), 1.0);
62   BOOST_CHECK_EQUAL(*csp->color(), white);
63   
64   // changes to csp should only affect csp
65   csp->setColor(black);
66   BOOST_CHECK_EQUAL(*asp->color(), *grey);
67   BOOST_CHECK_EQUAL(*bsp->color(), *grey);
68   BOOST_CHECK_EQUAL(*csp->color(), *black); 
69 }
70
71 void test_draw_func_null(SeqSpanRef r, float, float)
72 {
73 }
74
75 BOOST_AUTO_TEST_CASE( drawable_null_draw_func )
76 {
77   ColorRef white(new Color(1.0, 1.0, 1.0));  
78   DrawableRef asp(new Drawable(1.0,1.0,1.0,1.0, white, test_draw_func_null));
79   
80   BOOST_CHECK_EQUAL(asp->drawFunction(), test_draw_func_null);
81   
82   DrawableRef bsp(asp);
83   BOOST_CHECK_EQUAL(bsp->drawFunction(), test_draw_func_null);
84 }
85
86 void test_draw_func_find_drawable(SeqSpanRef ref, float l, float r)
87 {
88   BOOST_REQUIRE(ref->drawable());
89   BOOST_REQUIRE_EQUAL(ref->drawable()->drawFunction(), test_draw_func_find_drawable);
90 }
91
92 BOOST_AUTO_TEST_CASE( test_drawable_find_drawable )
93 {
94   ColorRef white(new Color(1.0, 1.0, 1.0));  
95   DrawableRef drawsp(new Drawable(1.0,1.0,1.0,1.0, white, test_draw_func_find_drawable));
96   SeqSpanRef ssp(new SeqSpan("AAAA"));
97   ssp->setDrawable(drawsp);
98      
99   BOOST_CHECK_EQUAL(drawsp->drawFunction(), test_draw_func_find_drawable);
100   ssp->drawable()->drawFunction();
101 }