Scroom  0.14
ruler-tests.cc File Reference
#include <cmath>
#include <boost/test/unit_test.hpp>
#include "ruler.hh"
Include dependency graph for ruler-tests.cc:

Macros

#define BOOST_TEST_DYN_LINK
 

Functions

 BOOST_AUTO_TEST_CASE (Ruler_creation_horizontal_signal_handlers)
 
 BOOST_AUTO_TEST_CASE (Ruler_creation_vertical_signal_handlers)
 
void testCorrectIntervalForMinWidth (double lowerLimit, double upperLimit, int expectedInterval)
 
 BOOST_AUTO_TEST_CASE (Ruler_correct_interval_for_minimum_width_interval_1_range_0_to_10)
 
 BOOST_AUTO_TEST_CASE (Ruler_correct_interval_for_minimum_width_interval_1_range_236_to_877)
 
 BOOST_AUTO_TEST_CASE (Ruler_correct_interval_for_minimum_width_interval_1_range_158p2_to_687p3)
 
 BOOST_AUTO_TEST_CASE (Ruler_correct_interval_for_minimum_width_interval_1_range_neg791_to_neg312)
 
 BOOST_AUTO_TEST_CASE (Ruler_correct_interval_for_minimum_width_interval_1_range_neg12p56_to27p82)
 
 BOOST_AUTO_TEST_CASE (Ruler_correct_interval_for_minimum_width_interval_1_range_negLARGE_to_LARGE)
 
 BOOST_AUTO_TEST_CASE (Ruler_correct_interval_for_minimum_width_interval_1_range_0_to_1)
 
 BOOST_AUTO_TEST_CASE (Ruler_correct_interval_for_minimum_width_interval_5_range_0_to_10)
 
 BOOST_AUTO_TEST_CASE (Ruler_correct_interval_for_minimum_width_interval_5_range_236_to_877)
 
 BOOST_AUTO_TEST_CASE (Ruler_correct_interval_for_minimum_width_interval_5_range_158p2_to_687p3)
 
 BOOST_AUTO_TEST_CASE (Ruler_correct_interval_for_minimum_width_interval_5_range_neg791_to_neg312)
 
 BOOST_AUTO_TEST_CASE (Ruler_correct_interval_for_minimum_width_interval_5_range_neg12p56_to27p82)
 
 BOOST_AUTO_TEST_CASE (Ruler_correct_interval_for_minimum_width_interval_5_range_negLARGE_to_LARGE)
 
 BOOST_AUTO_TEST_CASE (Ruler_correct_interval_for_minimum_width_interval_5_range_0_to_1)
 
 BOOST_AUTO_TEST_CASE (Ruler_scaleToRange_src_0_to_10_dest_0_100_x_5)
 
 BOOST_AUTO_TEST_CASE (Ruler_scaleToRange_src_neg28_neg40_dest_0_100_x_neg28)
 
 BOOST_AUTO_TEST_CASE (Ruler_scaleToRange_src_LARGE_dest_LARGE_x_LARGE)
 
 BOOST_AUTO_TEST_CASE (Ruler_scaleToRange_src_SMALL_dest_SMALL_x_SMALL)
 
 BOOST_AUTO_TEST_CASE (Ruler_intervalPixelSpacing_range_0_to_1000_interval_1_size_540px)
 
 BOOST_AUTO_TEST_CASE (Ruler_intervalPixelSpacing_range_0_to_1000_interval_1_size_1920px)
 
 BOOST_AUTO_TEST_CASE (Ruler_intervalPixelSpacing_range_0_to_1000_interval_5_size_540px)
 
 BOOST_AUTO_TEST_CASE (Ruler_intervalPixelSpacing_range_0_to_1000_interval_5_size_1920px)
 
 BOOST_AUTO_TEST_CASE (Ruler_intervalPixelSpacing_range_0_to_1000_interval_25_size_540px)
 
 BOOST_AUTO_TEST_CASE (Ruler_intervalPixelSpacing_range_0_to_1000_interval_25_size_1920px)
 
 BOOST_AUTO_TEST_CASE (Ruler_intervalPixelSpacing_range_0_to_1000_interval_50000000_size_540px)
 
 BOOST_AUTO_TEST_CASE (Ruler_intervalPixelSpacing_range_0_to_1000_interval_50000000_size_1920px)
 
 BOOST_AUTO_TEST_CASE (Ruler_firstTick_lowerLimit_0_interval_1)
 
 BOOST_AUTO_TEST_CASE (Ruler_firstTick_lowerLimit_0_interval_25)
 
 BOOST_AUTO_TEST_CASE (Ruler_firstTick_lowerLimit_0_interval_50000)
 
 BOOST_AUTO_TEST_CASE (Ruler_firstTick_lowerLimit_neg123_interval_1)
 
 BOOST_AUTO_TEST_CASE (Ruler_firstTick_lowerLimit_neg123_interval_25)
 
 BOOST_AUTO_TEST_CASE (Ruler_firstTick_lowerLimit_neg123_interval_50000)
 
 BOOST_AUTO_TEST_CASE (Ruler_firstTick_lowerLimit_360_interval_1)
 
 BOOST_AUTO_TEST_CASE (Ruler_firstTick_lowerLimit_360_interval_25)
 
 BOOST_AUTO_TEST_CASE (Ruler_firstTick_lowerLimit_360_interval_50000)
 
 BOOST_AUTO_TEST_CASE (Ruler_firstTick_lowerLimit_0p1_interval_1)
 
 BOOST_AUTO_TEST_CASE (Ruler_firstTick_lowerLimit_0p1_interval_25)
 
 BOOST_AUTO_TEST_CASE (Ruler_firstTick_lowerLimit_0p1_interval_50000)
 
 BOOST_AUTO_TEST_CASE (Ruler_firstTick_lowerLimit_neg0p1_interval_1)
 
 BOOST_AUTO_TEST_CASE (Ruler_firstTick_lowerLimit_neg0p1_interval_25)
 
 BOOST_AUTO_TEST_CASE (Ruler_firstTick_lowerLimit_neg0p1_interval_50000)
 

Macro Definition Documentation

◆ BOOST_TEST_DYN_LINK

#define BOOST_TEST_DYN_LINK

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/43]

BOOST_AUTO_TEST_CASE ( Ruler_correct_interval_for_minimum_width_interval_1_range_0_to_1  )
93 {
95 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [2/43]

BOOST_AUTO_TEST_CASE ( Ruler_correct_interval_for_minimum_width_interval_1_range_0_to_10  )
69 {
71 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [3/43]

BOOST_AUTO_TEST_CASE ( Ruler_correct_interval_for_minimum_width_interval_1_range_158p2_to_687p3  )
77 {
78  testCorrectIntervalForMinWidth(158.2, 687.3, 1);
79 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [4/43]

BOOST_AUTO_TEST_CASE ( Ruler_correct_interval_for_minimum_width_interval_1_range_236_to_877  )
73 {
74  testCorrectIntervalForMinWidth(236, 877, 1);
75 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [5/43]

BOOST_AUTO_TEST_CASE ( Ruler_correct_interval_for_minimum_width_interval_1_range_neg12p56_to27p82  )
85 {
86  testCorrectIntervalForMinWidth(-12.56, 27.82, 1);
87 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [6/43]

BOOST_AUTO_TEST_CASE ( Ruler_correct_interval_for_minimum_width_interval_1_range_neg791_to_neg312  )
81 {
82  testCorrectIntervalForMinWidth(-791, -312, 1);
83 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [7/43]

BOOST_AUTO_TEST_CASE ( Ruler_correct_interval_for_minimum_width_interval_1_range_negLARGE_to_LARGE  )
89 {
90  testCorrectIntervalForMinWidth(-4.2303e5, 3.2434e5, 1);
91 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [8/43]

BOOST_AUTO_TEST_CASE ( Ruler_correct_interval_for_minimum_width_interval_5_range_0_to_1  )
123 {
125 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [9/43]

BOOST_AUTO_TEST_CASE ( Ruler_correct_interval_for_minimum_width_interval_5_range_0_to_10  )
99 {
101 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [10/43]

BOOST_AUTO_TEST_CASE ( Ruler_correct_interval_for_minimum_width_interval_5_range_158p2_to_687p3  )
107 {
108  testCorrectIntervalForMinWidth(158.2, 687.3, 5);
109 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [11/43]

BOOST_AUTO_TEST_CASE ( Ruler_correct_interval_for_minimum_width_interval_5_range_236_to_877  )
103 {
104  testCorrectIntervalForMinWidth(236, 877, 5);
105 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [12/43]

BOOST_AUTO_TEST_CASE ( Ruler_correct_interval_for_minimum_width_interval_5_range_neg12p56_to27p82  )
115 {
116  testCorrectIntervalForMinWidth(-12.56, 27.82, 5);
117 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [13/43]

BOOST_AUTO_TEST_CASE ( Ruler_correct_interval_for_minimum_width_interval_5_range_neg791_to_neg312  )
111 {
112  testCorrectIntervalForMinWidth(-791, -312, 5);
113 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [14/43]

BOOST_AUTO_TEST_CASE ( Ruler_correct_interval_for_minimum_width_interval_5_range_negLARGE_to_LARGE  )
119 {
120  testCorrectIntervalForMinWidth(-4.2303e5, 3.2434e5, 5);
121 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [15/43]

BOOST_AUTO_TEST_CASE ( Ruler_creation_horizontal_signal_handlers  )
13 {
14  gtk_init(nullptr, nullptr);
15  // Register a new ruler with a dummy drawing area
16  GtkWidget* drawingArea = gtk_drawing_area_new();
18  // Check that the appropriate signals are connected
19 
20  // Currently, this test case only checks that *a* signal handler is connected
21  // for both the "draw" signal and "size-allocate" signal, with a pointer
22  // to the ruler as data.
23  // It does not check whether drawCallback is connected to "draw" and
24  // sizeAllocateCallback to "size-allocate". It probably should, but I can't figure
25  // out these weird types.
26  auto mask = static_cast<GSignalMatchType>(G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DATA);
27  const guint drawID = g_signal_lookup("draw", GTK_TYPE_DRAWING_AREA);
28  const guint sizeAllocateID = g_signal_lookup("size-allocate", GTK_TYPE_DRAWING_AREA);
29  // Check that a signal handler is connected for the "draw" signal, with a pointer to ruler as data
30  BOOST_CHECK(g_signal_handler_find(drawingArea, mask, drawID, 0, nullptr, nullptr, ruler.get()) != 0);
31  // Check that a signal handler is connected for the "size-allocate" signal, with a pointer to ruler as data
32  BOOST_CHECK(g_signal_handler_find(drawingArea, mask, sizeAllocateID, 0, nullptr, nullptr, ruler.get()) != 0);
33 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [16/43]

BOOST_AUTO_TEST_CASE ( Ruler_creation_vertical_signal_handlers  )
36 {
37  gtk_init(nullptr, nullptr);
38  // Register a new ruler with a dummy drawing area
39  GtkWidget* drawingArea = gtk_drawing_area_new();
41  // Check that the appropriate signals are connected
42  auto mask = static_cast<GSignalMatchType>(G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DATA);
43  const guint drawID = g_signal_lookup("draw", GTK_TYPE_DRAWING_AREA);
44  const guint sizeAllocateID = g_signal_lookup("size-allocate", GTK_TYPE_DRAWING_AREA);
45  // Check that a signal handler is connected for the "draw" signal, with a pointer to ruler as data
46  BOOST_CHECK(g_signal_handler_find(drawingArea, mask, drawID, 0, nullptr, nullptr, ruler.get()) != 0);
47  // Check that a signal handler is connected for the "size-allocate" signal, with a pointer to ruler as data
48  BOOST_CHECK(g_signal_handler_find(drawingArea, mask, sizeAllocateID, 0, nullptr, nullptr, ruler.get()) != 0);
49 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [17/43]

BOOST_AUTO_TEST_CASE ( Ruler_firstTick_lowerLimit_0_interval_1  )
199 { BOOST_CHECK(RulerCalculations::firstTick(0, 1) == 0); }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [18/43]

BOOST_AUTO_TEST_CASE ( Ruler_firstTick_lowerLimit_0_interval_25  )
201 { BOOST_CHECK(RulerCalculations::firstTick(0, 25) == 0); }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [19/43]

BOOST_AUTO_TEST_CASE ( Ruler_firstTick_lowerLimit_0_interval_50000  )
203 { BOOST_CHECK(RulerCalculations::firstTick(0, 50000) == 0); }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [20/43]

BOOST_AUTO_TEST_CASE ( Ruler_firstTick_lowerLimit_0p1_interval_1  )
226 { BOOST_CHECK(RulerCalculations::firstTick(0.1, 1) == 0); }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [21/43]

BOOST_AUTO_TEST_CASE ( Ruler_firstTick_lowerLimit_0p1_interval_25  )
228 { BOOST_CHECK(RulerCalculations::firstTick(0.1, 25) == 0); }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [22/43]

BOOST_AUTO_TEST_CASE ( Ruler_firstTick_lowerLimit_0p1_interval_50000  )
231 {
232  BOOST_CHECK(RulerCalculations::firstTick(0.1, 50000) == 0);
233 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [23/43]

BOOST_AUTO_TEST_CASE ( Ruler_firstTick_lowerLimit_360_interval_1  )
217 { BOOST_CHECK(RulerCalculations::firstTick(360, 1) == 360); }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [24/43]

BOOST_AUTO_TEST_CASE ( Ruler_firstTick_lowerLimit_360_interval_25  )
219 { BOOST_CHECK(RulerCalculations::firstTick(360, 25) == 350); }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [25/43]

BOOST_AUTO_TEST_CASE ( Ruler_firstTick_lowerLimit_360_interval_50000  )
222 {
223  BOOST_CHECK(RulerCalculations::firstTick(360, 50000) == 0);
224 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [26/43]

BOOST_AUTO_TEST_CASE ( Ruler_firstTick_lowerLimit_neg0p1_interval_1  )
235 { BOOST_CHECK(RulerCalculations::firstTick(-0.1, 1) == -1); }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [27/43]

BOOST_AUTO_TEST_CASE ( Ruler_firstTick_lowerLimit_neg0p1_interval_25  )
238 {
239  BOOST_CHECK(RulerCalculations::firstTick(-0.1, 25) == -25);
240 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [28/43]

BOOST_AUTO_TEST_CASE ( Ruler_firstTick_lowerLimit_neg0p1_interval_50000  )
243 {
244  BOOST_CHECK(RulerCalculations::firstTick(-0.1, 50000) == -50000);
245 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [29/43]

BOOST_AUTO_TEST_CASE ( Ruler_firstTick_lowerLimit_neg123_interval_1  )
205 { BOOST_CHECK(RulerCalculations::firstTick(-123, 1) == -123); }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [30/43]

BOOST_AUTO_TEST_CASE ( Ruler_firstTick_lowerLimit_neg123_interval_25  )
208 {
209  BOOST_CHECK(RulerCalculations::firstTick(-123, 25) == -125);
210 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [31/43]

BOOST_AUTO_TEST_CASE ( Ruler_firstTick_lowerLimit_neg123_interval_50000  )
213 {
214  BOOST_CHECK(RulerCalculations::firstTick(-123, 50000) == -50000);
215 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [32/43]

BOOST_AUTO_TEST_CASE ( Ruler_intervalPixelSpacing_range_0_to_1000_interval_1_size_1920px  )
160 {
161  BOOST_CHECK(RulerCalculations::intervalPixelSpacing(1, 0, 1000, 1920) == 1);
162 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [33/43]

BOOST_AUTO_TEST_CASE ( Ruler_intervalPixelSpacing_range_0_to_1000_interval_1_size_540px  )
155 {
156  BOOST_CHECK(RulerCalculations::intervalPixelSpacing(1, 0, 1000, 540) == 0);
157 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [34/43]

BOOST_AUTO_TEST_CASE ( Ruler_intervalPixelSpacing_range_0_to_1000_interval_25_size_1920px  )
180 {
181  BOOST_CHECK(RulerCalculations::intervalPixelSpacing(25, 0, 1000, 1920) == 48);
182 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [35/43]

BOOST_AUTO_TEST_CASE ( Ruler_intervalPixelSpacing_range_0_to_1000_interval_25_size_540px  )
175 {
176  BOOST_CHECK(RulerCalculations::intervalPixelSpacing(25, 0, 1000, 540) == 13);
177 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [36/43]

BOOST_AUTO_TEST_CASE ( Ruler_intervalPixelSpacing_range_0_to_1000_interval_50000000_size_1920px  )
190 {
191  BOOST_CHECK(RulerCalculations::intervalPixelSpacing(50000000, 0, 1000000000, 1920) == 95);
192 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [37/43]

BOOST_AUTO_TEST_CASE ( Ruler_intervalPixelSpacing_range_0_to_1000_interval_50000000_size_540px  )
185 {
186  BOOST_CHECK(RulerCalculations::intervalPixelSpacing(50000000, 0, 1000000000, 540) == 27);
187 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [38/43]

BOOST_AUTO_TEST_CASE ( Ruler_intervalPixelSpacing_range_0_to_1000_interval_5_size_1920px  )
170 {
171  BOOST_CHECK(RulerCalculations::intervalPixelSpacing(5, 0, 1000, 1920) == 9);
172 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [39/43]

BOOST_AUTO_TEST_CASE ( Ruler_intervalPixelSpacing_range_0_to_1000_interval_5_size_540px  )
165 {
166  BOOST_CHECK(RulerCalculations::intervalPixelSpacing(5, 0, 1000, 540) == 2);
167 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [40/43]

BOOST_AUTO_TEST_CASE ( Ruler_scaleToRange_src_0_to_10_dest_0_100_x_5  )
131 {
132  BOOST_CHECK(RulerCalculations::scaleToRange(15, 10, 20, 0, 100) == 50);
133 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [41/43]

BOOST_AUTO_TEST_CASE ( Ruler_scaleToRange_src_LARGE_dest_LARGE_x_LARGE  )
141 {
142  BOOST_CHECK(RulerCalculations::scaleToRange(3.532e4, -4.230e8, 3.243e8, 193, 8.234e5) == 466198);
143 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [42/43]

BOOST_AUTO_TEST_CASE ( Ruler_scaleToRange_src_neg28_neg40_dest_0_100_x_neg28  )
136 {
137  BOOST_CHECK(RulerCalculations::scaleToRange(-28, -10, -40, 0, 100) == 60);
138 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [43/43]

BOOST_AUTO_TEST_CASE ( Ruler_scaleToRange_src_SMALL_dest_SMALL_x_SMALL  )
146 {
147  BOOST_CHECK(RulerCalculations::scaleToRange(0.23, 0, 1, 0.4, 0.75) == 0.4);
148 }
Here is the call graph for this function:

◆ testCorrectIntervalForMinWidth()

void testCorrectIntervalForMinWidth ( double  lowerLimit,
double  upperLimit,
int  expectedInterval 
)

Calculates the minimum pixel width for the ruler such that the interval between major ticks equals expectedInterval.

Parameters
lowerLimitLower limit of the ruler range.
upperLimitUpper limit of the ruler range.
expectedIntervalThe expected interval.
59 {
60  const double rangeSize = ceil(upperLimit - lowerLimit);
61  // The minimum pixel width of the ruler such the interval can be expectedInterval
62  const int minRulerWidth = floor(rangeSize / static_cast<double>(expectedInterval) * RulerCalculations::MIN_SPACE_MAJORTICKS);
63 
64  // Test that calculateInterval returns the expected interval
65  BOOST_CHECK(RulerCalculations::calculateInterval(lowerLimit, upperLimit, minRulerWidth) == expectedInterval);
66 }

Referenced by BOOST_AUTO_TEST_CASE().

Here is the call graph for this function:
Here is the caller graph for this function:
RulerCalculations::intervalPixelSpacing
static int intervalPixelSpacing(double interval, double lower, double upper, double allocatedSize)
Definition: ruler.cc:294
RulerCalculations::MIN_SPACE_MAJORTICKS
static constexpr int MIN_SPACE_MAJORTICKS
Definition: ruler.hh:184
RulerCalculations::firstTick
static int firstTick(double lower, int interval)
Definition: ruler.cc:303
Ruler::VERTICAL
@ VERTICAL
Definition: ruler.hh:23
Scroom::Utils::ceil
Point< T > ceil(Point< T > p)
Definition: point.hh:228
drawingArea
static GtkWidget * drawingArea
Definition: measure-framerate-callbacks.cc:18
Ruler::create
static Ptr create(Orientation orientation, GtkWidget *drawArea)
Definition: ruler.cc:12
RulerCalculations::scaleToRange
static double scaleToRange(double x, double src_lower, double src_upper, double dest_lower, double dest_upper)
Definition: ruler.cc:235
testCorrectIntervalForMinWidth
void testCorrectIntervalForMinWidth(double lowerLimit, double upperLimit, int expectedInterval)
Definition: ruler-tests.cc:58
Ruler::Ptr
boost::shared_ptr< Ruler > Ptr
Definition: ruler.hh:18
RulerCalculations::calculateInterval
static int calculateInterval(double lower, double upper, double allocatedSize)
Definition: ruler.cc:244
mask
const unsigned int mask
Definition: sampleiterator-tests.cc:43
Ruler::HORIZONTAL
@ HORIZONTAL
Definition: ruler.hh:22