Scroom  0.14
pipette-tests.cc File Reference
#include <stack>
#include <thread>
#include <boost/dll.hpp>
#include <boost/test/unit_test.hpp>
#include <scroom/gtk-test-helpers.hh>
#include "pipette.hh"
Include dependency graph for pipette-tests.cc:

Classes

class  DummyPresentation
 
class  DummyView
 
class  DummyPluginInterface
 

Functions

 BOOST_AUTO_TEST_CASE (pipette_selection_end)
 
 BOOST_AUTO_TEST_CASE (pipette_selection_update)
 
 BOOST_AUTO_TEST_CASE (pipette_enable_disable)
 
 BOOST_AUTO_TEST_CASE (pipette_metadata)
 
 BOOST_AUTO_TEST_CASE (pipette_value_display_presentation)
 
 BOOST_AUTO_TEST_CASE (pipette_value_display_no_presentation)
 
 BOOST_AUTO_TEST_CASE (pipette_view_add)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/7]

BOOST_AUTO_TEST_CASE ( pipette_enable_disable  )
172 {
174 
175  // questionably useful
176  handler->onEnable();
177  BOOST_CHECK(handler->isEnabled());
178  handler->onDisable();
179  BOOST_CHECK(!handler->isEnabled());
180 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [2/7]

BOOST_AUTO_TEST_CASE ( pipette_metadata  )
183 {
184  const auto pluginInterface = DummyPluginInterface::create();
185 
186  Pipette::Ptr const pipette = Pipette::create();
187 
188  const int pre_view_observers = pluginInterface->view_observers;
189 
190  pipette->registerCapabilities(pluginInterface);
191 
192  // maybe not worth testing
193  BOOST_CHECK_EQUAL(pipette->getPluginName(), "Pipette");
194  BOOST_CHECK(!pipette->getPluginVersion().empty());
195  BOOST_CHECK_EQUAL(pre_view_observers + 1, pluginInterface->view_observers);
196 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [3/7]

BOOST_AUTO_TEST_CASE ( pipette_selection_end  )
121 {
123 
124  Selection const sel(10, 11);
125 
126  handler->onSelectionEnd(sel, nullptr);
127  BOOST_CHECK(!handler->getSelection());
128 
129  handler->onEnable();
130  handler->onSelectionEnd(sel, DummyView::createWithPresentation());
131  auto selection = handler->getSelection();
132  BOOST_REQUIRE(selection);
133  Scroom::Utils::Point<double> const expected{10, 11};
134  BOOST_CHECK_EQUAL(selection->start, expected);
135 
136  handler->onDisable();
137  handler->onSelectionEnd(sel, nullptr);
138  BOOST_CHECK(!handler->getSelection());
139 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [4/7]

BOOST_AUTO_TEST_CASE ( pipette_selection_update  )
142 {
144 
145  Selection const sel(10, 11);
146 
147  // should not do anything but will be called from the view so should not crash
148  handler->onSelectionStart(sel, nullptr);
149 
150  handler->onSelectionUpdate(sel, nullptr);
151  BOOST_CHECK(!handler->getSelection());
152 
153  handler->onEnable();
154  handler->onSelectionUpdate(sel, nullptr);
155  auto selection = handler->getSelection();
156  BOOST_REQUIRE(selection);
157  Scroom::Utils::Point<double> const expected{10, 11};
158  BOOST_CHECK_EQUAL(selection->start, expected);
159 
161  cairo_t* cr = cairo_create(cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1, 1));
162  handler->render(vi, cr, {0, 0, 0, 0}, 1);
163  handler->render(vi, cr, {0, 0, 0, 0}, -2);
164 
165  handler->onDisable();
166  handler->onSelectionUpdate(sel, nullptr);
167  BOOST_CHECK(!handler->getSelection());
168  handler->render(vi, cr, {0, 0, 0, 0}, 1);
169 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [5/7]

BOOST_AUTO_TEST_CASE ( pipette_value_display_no_presentation  )
219 {
221  const auto view = DummyView::createWithoutPresentation();
222 
223  handler->onEnable();
224 
225  handler->computeValues(view, Scroom::Utils::Rectangle<double>(10, 11, 12, 13));
226  BOOST_CHECK_EQUAL(view->nextStatusMessage(), "Computing color values...");
227  BOOST_CHECK_EQUAL(view->nextStatusMessage(), "Pipette is not supported for this presentation.");
228 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [6/7]

BOOST_AUTO_TEST_CASE ( pipette_value_display_presentation  )
199 {
201  const auto view = DummyView::createWithPresentation();
202 
203  handler->onEnable();
204 
205  handler->computeValues(view, Scroom::Utils::Rectangle<double>(10, 11, 12, 13));
206  BOOST_CHECK_EQUAL(view->nextStatusMessage(), "Computing color values...");
207  BOOST_CHECK_EQUAL(view->nextStatusMessage(),
208  "Top-left: (10,11), Bottom-right: (22,24), Height: 13, Width: 12, "
209  "Colors: C: 1.00");
210 
211  handler->computeValues(view, Scroom::Utils::Rectangle<double>(-10, -11, 20, 22));
212  BOOST_CHECK_EQUAL(view->nextStatusMessage(), "Computing color values...");
213  BOOST_CHECK_EQUAL(view->nextStatusMessage(),
214  "Top-left: (0,0), Bottom-right: (10,11), Height: 11, Width: 10, "
215  "Colors: C: 1.00");
216 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [7/7]

BOOST_AUTO_TEST_CASE ( pipette_view_add  )
231 {
232  Pipette::Ptr const pipette = Pipette::create();
233  const auto view = DummyView::createWithPresentation();
234 
235  const int pre_reg_sel = view->reg_sel;
236  const int pre_reg_post = view->reg_post;
237  const int pre_tool_btn = view->tool_btn;
238 
239  Scroom::Bookkeeping::Token const token = pipette->viewAdded(view);
240 
241  BOOST_CHECK_EQUAL(pre_reg_sel + 1, view->reg_sel);
242  BOOST_CHECK_EQUAL(pre_reg_post + 1, view->reg_post);
243  BOOST_CHECK_EQUAL(pre_tool_btn + 1, view->tool_btn);
244  BOOST_CHECK(token != nullptr);
245 }
Here is the call graph for this function:
PipetteHandler::Ptr
boost::shared_ptr< PipetteHandler > Ptr
Definition: pipette.hh:27
PipetteHandler::create
static Ptr create()
Definition: pipette.cc:58
BOOST_CHECK_EQUAL
BOOST_CHECK_EQUAL(sample.expectedColors, originalColormap->colors.size())
ViewInterface::Ptr
boost::shared_ptr< ViewInterface > Ptr
Definition: viewinterface.hh:193
Selection
Definition: viewinterface.hh:38
Pipette::create
static Ptr create()
Definition: pipette.cc:24
DummyView::createWithPresentation
static Ptr createWithPresentation()
Definition: pipette-tests.cc:50
BOOST_REQUIRE
BOOST_REQUIRE(originalColormap)
DummyPluginInterface::create
static Ptr create()
Definition: pipette-tests.cc:102
Pipette::Ptr
boost::shared_ptr< Pipette > Ptr
Definition: pipette.hh:79
DummyView::createWithoutPresentation
static Ptr createWithoutPresentation()
Definition: pipette-tests.cc:51
Scroom::Bookkeeping::Token
Definition: bookkeeping.hh:37
Scroom::Utils::Rectangle< double >
Scroom::Utils::Point< double >