Scroom  0.14
function-additor-tests.cc File Reference
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/thread.hpp>
#include <scroom/function-additor.hh>
#include <scroom/semaphore.hh>
#include "helpers.hh"
Include dependency graph for function-additor-tests.cc:

Functions

static const millisec short_timeout (250)
 
static const millisec long_timeout (2000)
 
 BOOST_AUTO_TEST_CASE (clear_clears)
 
 BOOST_AUTO_TEST_CASE (pass_passes)
 
 BOOST_AUTO_TEST_CASE (destroy_destroys)
 
 BOOST_AUTO_TEST_CASE (additor_adds)
 
 BOOST_AUTO_TEST_CASE (order_is_preserved)
 
 BOOST_AUTO_TEST_CASE (left_association)
 
 BOOST_AUTO_TEST_CASE (right_association)
 
 BOOST_AUTO_TEST_CASE (Multiplier_multiplies)
 
 BOOST_AUTO_TEST_CASE (Test_If_Expressions_Compile)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/9]

BOOST_AUTO_TEST_CASE ( additor_adds  )
67 {
68  Semaphore s1(0);
69  Semaphore s2(0);
70  BOOST_REQUIRE(!s1.try_P());
71  BOOST_REQUIRE(!s2.try_P());
72  (clear(&s1) + clear(&s2))();
73  BOOST_REQUIRE(s1.try_P());
74  BOOST_REQUIRE(s2.try_P());
75 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [2/9]

BOOST_AUTO_TEST_CASE ( clear_clears  )
34 {
35  Semaphore s(0);
36  BOOST_REQUIRE(!s.try_P());
37  clear (&s)();
38  BOOST_REQUIRE(s.try_P());
39 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [3/9]

BOOST_AUTO_TEST_CASE ( destroy_destroys  )
49 {
50  boost::shared_ptr<int> p(new int(4));
51  boost::weak_ptr<int> const w(p);
52  BOOST_REQUIRE(w.lock());
53 
54  boost::function<void()> const f(destroy(p));
55  p.reset();
56  BOOST_REQUIRE(w.lock());
57 
58  f();
59  BOOST_REQUIRE(!w.lock());
60 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [4/9]

BOOST_AUTO_TEST_CASE ( left_association  )
91 {
93  Semaphore s1(0);
94  Semaphore s2(0);
95  a += pass(&s1);
96  BOOST_CHECK_EQUAL(&a, &(a + clear(&s2)));
97 
98  boost::thread t(a);
99  BOOST_CHECK(!s2.P(short_timeout));
100  s1.V();
101  BOOST_CHECK(s2.P(long_timeout));
102  BOOST_CHECK(t.timed_join(long_timeout));
103 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [5/9]

BOOST_AUTO_TEST_CASE ( Multiplier_multiplies  )
125 {
126  Semaphore s(5);
127 
128  (5 * pass(&s))();
129  BOOST_REQUIRE(!s.try_P());
130 
131  Semaphore s2(25);
132  ((5 * pass(&s2)) * 5)();
133  BOOST_REQUIRE(!s2.try_P());
134 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [6/9]

BOOST_AUTO_TEST_CASE ( order_is_preserved  )
78 {
79  Semaphore s1(0);
80  Semaphore s2(0);
81  BOOST_CHECK(!s1.try_P());
82  BOOST_CHECK(!s2.try_P());
83  boost::thread t(pass(&s1) + clear(&s2));
84  BOOST_CHECK(!s2.P(short_timeout));
85  s1.V();
86  BOOST_CHECK(s2.P(long_timeout));
87  BOOST_CHECK(t.timed_join(long_timeout));
88 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [7/9]

BOOST_AUTO_TEST_CASE ( pass_passes  )
42 {
43  Semaphore s(1);
44  pass (&s)();
45  BOOST_REQUIRE(!s.try_P());
46 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [8/9]

BOOST_AUTO_TEST_CASE ( right_association  )
106 {
108  Semaphore s1(0);
109  Semaphore s2(0);
110  a += clear(&s2);
111 
112  BOOST_CHECK_EQUAL(&a, &(pass(&s1) + a));
113  boost::thread t(a);
114  BOOST_CHECK(!s2.P(short_timeout));
115  s1.V();
116  BOOST_CHECK(s2.P(long_timeout));
117  BOOST_CHECK(t.timed_join(long_timeout));
118 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [9/9]

BOOST_AUTO_TEST_CASE ( Test_If_Expressions_Compile  )
141 {
142  (void)(clear(nullptr) + 5 * clear(nullptr));
143  (void)(clear(nullptr) + (5 * clear(nullptr)) * 5);
144  (void)(clear(nullptr) + 5 * (5 * clear(nullptr)));
145  (void)(4 * (clear(nullptr) + clear(nullptr)));
146  (void)((clear(nullptr) + clear(nullptr)) * 4);
147 }
Here is the call graph for this function:

◆ long_timeout()

static const millisec long_timeout ( 2000  )
static

Referenced by BOOST_AUTO_TEST_CASE().

Here is the caller graph for this function:

◆ short_timeout()

static const millisec short_timeout ( 250  )
static

Referenced by BOOST_AUTO_TEST_CASE().

Here is the caller graph for this function:
clear
boost::function< void()> clear(Semaphore *s)
Definition: helpers.cc:29
Scroom::Detail::ThreadPool::FunctionAdditor
Definition: function-additor.hh:16
BOOST_CHECK_EQUAL
BOOST_CHECK_EQUAL(sample.expectedColors, originalColormap->colors.size())
destroy
boost::function< void()> destroy(boost::shared_ptr< void > p)
Definition: helpers.cc:31
Scroom::Semaphore
Definition: semaphore.hh:15
BOOST_REQUIRE
BOOST_REQUIRE(originalColormap)
pass
boost::function< void()> pass(Semaphore *s)
Definition: helpers.cc:27
short_timeout
static const millisec short_timeout(250)
long_timeout
static const millisec long_timeout(2000)