1 #include "canvas/lookup_table.h"
2 #include "canvas/types.h"
3 #include "canvas/rectangle.h"
4 #include "canvas/group.h"
5 #include "canvas/canvas.h"
6 #include "optimizing_lookup_table.h"
9 using namespace ArdourCanvas;
11 CPPUNIT_TEST_SUITE_REGISTRATION (OptimizingLookupTableTest);
14 OptimizingLookupTableTest::build_1 ()
17 Rectangle a (canvas.root(), Rect (0, 0, 32, 32));
18 a.set_outline_width (0);
19 Rectangle b (canvas.root(), Rect (0, 33, 32, 64));
20 b.set_outline_width (0);
21 Rectangle c (canvas.root(), Rect (33, 0, 64, 32));
22 c.set_outline_width (0);
23 Rectangle d (canvas.root(), Rect (33, 33, 64, 64));
24 d.set_outline_width (0);
25 OptimizingLookupTable table (*canvas.root(), 1);
27 CPPUNIT_ASSERT (table._items_per_cell == 1);
28 CPPUNIT_ASSERT (table._cell_size.x == 32);
29 CPPUNIT_ASSERT (table._cell_size.y == 32);
30 CPPUNIT_ASSERT (table._cells[0][0].front() == &a);
31 CPPUNIT_ASSERT (table._cells[0][1].front() == &b);
32 CPPUNIT_ASSERT (table._cells[1][0].front() == &c);
33 CPPUNIT_ASSERT (table._cells[1][1].front() == &d);
37 OptimizingLookupTableTest::build_2 ()
40 Rectangle a (canvas.root(), Rect (0, 0, 713, 1024));
41 a.set_outline_width (0);
42 Rectangle b (canvas.root(), Rect (0, 0, 0, 1024));
43 b.set_outline_width (0);
44 OptimizingLookupTable table (*canvas.root(), 64);
48 OptimizingLookupTableTest::build_negative ()
51 Rectangle a (canvas.root(), Rect (-32, -32, 32, 32));
52 OptimizingLookupTable table (*canvas.root(), 1);
56 OptimizingLookupTableTest::get_small ()
59 Rectangle a (canvas.root(), Rect (0, 0, 32, 32));
60 a.set_outline_width (0);
61 Rectangle b (canvas.root(), Rect (0, 33, 32, 64));
62 b.set_outline_width (0);
63 Rectangle c (canvas.root(), Rect (33, 0, 64, 32));
64 c.set_outline_width (0);
65 Rectangle d (canvas.root(), Rect (33, 33, 64, 64));
66 d.set_outline_width (0);
67 OptimizingLookupTable table (*canvas.root(), 1);
69 vector<Item*> items = table.get (Rect (16, 16, 48, 48));
70 CPPUNIT_ASSERT (items.size() == 4);
72 items = table.get (Rect (32, 32, 33, 33));
73 CPPUNIT_ASSERT (items.size() == 1);
77 OptimizingLookupTableTest::get_big ()
84 for (int x = 0; x < N; ++x) {
85 for (int y = 0; y < N; ++y) {
86 Rectangle* r = new Rectangle (canvas.root());
87 r->set_outline_width (0);
88 r->set (Rect (x * s, y * s, (x + 1) * s, (y + 1) * s));
92 OptimizingLookupTable table (*canvas.root(), 16);
93 vector<Item*> items = table.get (Rect (0, 0, 15, 15));
94 CPPUNIT_ASSERT (items.size() == 16);
97 /** Check that calling OptimizingLookupTable::get() returns things in the correct order.
98 * The order should be the same as it is in the owning group.
101 OptimizingLookupTableTest::check_ordering ()
105 Rectangle a (canvas.root (), Rect (0, 0, 64, 64));
106 Rectangle b (canvas.root (), Rect (0, 0, 64, 64));
107 Rectangle c (canvas.root (), Rect (0, 0, 64, 64));
109 /* since there have been bugs introduced due to sorting pointers,
110 get these rectangles in ascending order of their address
114 items.push_back (&a);
115 items.push_back (&b);
116 items.push_back (&c);
119 /* now arrange these items in the group in reverse order of address */
121 for (list<Item*>::reverse_iterator i = items.rbegin(); i != items.rend(); ++i) {
122 (*i)->raise_to_top ();
125 /* ask the LUT for the items */
127 canvas.root()->ensure_lut ();
128 vector<Item*> lut_items = canvas.root()->_lut->get (Rect (0, 0, 64, 64));
129 CPPUNIT_ASSERT (lut_items.size() == 3);
131 /* check that they are in the right order */
133 vector<Item*>::iterator i = lut_items.begin ();
134 list<Item*>::reverse_iterator j = items.rbegin ();
136 while (i != lut_items.end ()) {
137 CPPUNIT_ASSERT (*i == *j);