69667466de98853671f85b37a9cadf8f6386d9a1
[ardour.git] / libs / canvas / test / types.cc
1 #include "canvas/types.h"
2 #include "types.h"
3
4 using namespace std;
5 using namespace ArdourCanvas;
6
7 CPPUNIT_TEST_SUITE_REGISTRATION (TypesTest);
8
9 void
10 TypesTest::intersect ()
11 {
12         {
13                 Rect a (0, 0, 1024, 1024);
14                 Rect b (0, 0, 512, 512);
15                 boost::optional<Rect> c = a.intersection (b);
16
17                 CPPUNIT_ASSERT (c.is_initialized ());
18                 CPPUNIT_ASSERT (c->x0 == 0);
19                 CPPUNIT_ASSERT (c->x1 == 512);
20                 CPPUNIT_ASSERT (c->y0 == 0);
21                 CPPUNIT_ASSERT (c->y1 == 512);
22         }
23
24         {
25                 Rect a (0, 0, 512, 512);
26                 Rect b (513, 513, 1024, 1024);
27                 boost::optional<Rect> c = a.intersection (b);
28
29                 CPPUNIT_ASSERT (!c.is_initialized ());
30         }
31 }
32
33 void
34 TypesTest::extend ()
35 {
36         {
37                 Rect a (50, 60, 70, 80);
38                 Rect b (100, 110, 120, 130);
39                 Rect c = a.extend (b);
40
41                 CPPUNIT_ASSERT (c.x0 == 50);
42                 CPPUNIT_ASSERT (c.y0 == 60);
43                 CPPUNIT_ASSERT (c.x1 == 120);
44                 CPPUNIT_ASSERT (c.y1 == 130);
45         }
46 }
47                 
48 void
49 TypesTest::test_safe_add ()
50 {
51         CPPUNIT_ASSERT (safe_add (4, 9) == 13);
52         CPPUNIT_ASSERT (safe_add (4, COORD_MAX) == COORD_MAX);
53         CPPUNIT_ASSERT (safe_add (COORD_MAX, 4) == COORD_MAX);
54 }