Scroom  0.14
semaphore-tests.cc File Reference
#include <iostream>
#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 semaphore-tests.cc:

Functions

void test_count_equals (Semaphore *s, int i)
 
 BOOST_AUTO_TEST_CASE (try_P)
 
 BOOST_AUTO_TEST_CASE (count_equals_0)
 
 BOOST_AUTO_TEST_CASE (count_equals_1)
 
 BOOST_AUTO_TEST_CASE (count_equals_2)
 
 BOOST_AUTO_TEST_CASE (inc_count_1)
 
 BOOST_AUTO_TEST_CASE (inc_count_2)
 
 BOOST_AUTO_TEST_CASE (inc_count_3)
 
 BOOST_AUTO_TEST_CASE (pass_many)
 
 BOOST_AUTO_TEST_CASE (p_with_timeout)
 
 BOOST_AUTO_TEST_CASE (p_without_timeout)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/10]

BOOST_AUTO_TEST_CASE ( count_equals_0  )
47 {
48  Semaphore s(0);
49  test_count_equals(&s, 0);
50 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [2/10]

BOOST_AUTO_TEST_CASE ( count_equals_1  )
53 {
54  Semaphore s(1);
55  test_count_equals(&s, 1);
56 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [3/10]

BOOST_AUTO_TEST_CASE ( count_equals_2  )
59 {
60  Semaphore s(2);
61  test_count_equals(&s, 2);
62 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [4/10]

BOOST_AUTO_TEST_CASE ( inc_count_1  )
65 {
66  Semaphore s(0);
67  s.V();
68  test_count_equals(&s, 1);
69 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [5/10]

BOOST_AUTO_TEST_CASE ( inc_count_2  )
72 {
73  Semaphore s(0);
74  s.V();
75  s.V();
76  test_count_equals(&s, 2);
77 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [6/10]

BOOST_AUTO_TEST_CASE ( inc_count_3  )
80 {
81  Semaphore s(0);
82  s.V();
83  s.V();
84  s.V();
85  test_count_equals(&s, 3);
86 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [7/10]

BOOST_AUTO_TEST_CASE ( p_with_timeout  )
114 {
115  Semaphore s(0);
116  BOOST_REQUIRE(!s.P(millisec(250)));
117  test_count_equals(&s, 0);
118 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [8/10]

BOOST_AUTO_TEST_CASE ( p_without_timeout  )
121 {
122  Semaphore s(1);
123  BOOST_REQUIRE(s.P(millisec(250)));
124  BOOST_REQUIRE(!s.P(millisec(250)));
125  test_count_equals(&s, 0);
126 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [9/10]

BOOST_AUTO_TEST_CASE ( pass_many  )
89 {
90  Semaphore s(0);
91  boost::thread t(5 * pass(&s));
92  boost::this_thread::sleep(millisec(50));
93  s.V();
94  boost::this_thread::sleep(millisec(100));
95  s.V();
96  boost::this_thread::sleep(millisec(50));
97  s.V();
98  boost::this_thread::sleep(millisec(100));
99  s.V();
100  boost::this_thread::sleep(millisec(50));
101  s.V();
102  t.timed_join(millisec(250));
103  bool const success = boost::thread::id() == t.get_id();
104  BOOST_REQUIRE(success);
105  if(!success)
106  {
107  t.interrupt();
108  t.timed_join(millisec(250));
109  BOOST_REQUIRE(boost::thread::id() == t.get_id());
110  }
111 }
Here is the call graph for this function:

◆ BOOST_AUTO_TEST_CASE() [10/10]

BOOST_AUTO_TEST_CASE ( try_P  )
38 {
39  Semaphore s1(0);
40  BOOST_REQUIRE(!s1.try_P());
41  Semaphore s2(1);
42  BOOST_REQUIRE(s2.try_P());
43  BOOST_REQUIRE(!s2.try_P());
44 }
Here is the call graph for this function:

◆ test_count_equals()

void test_count_equals ( Semaphore s,
int  i 
)
25 {
26  for(int actual = 0; actual < i; actual++)
27  {
28  BOOST_REQUIRE_MESSAGE(s->try_P(), "Could only decrement " << actual << " times, instead of " << i);
29  }
30  BOOST_REQUIRE_MESSAGE(!s->try_P(), "Can decrement " << (i + 1) << " times, instead of " << i);
31 }

Referenced by BOOST_AUTO_TEST_CASE().

Here is the call graph for this function:
Here is the caller graph for this function:
Scroom::Semaphore::try_P
bool try_P()
Definition: semaphore.hh:48
Scroom::Semaphore
Definition: semaphore.hh:15
test_count_equals
void test_count_equals(Semaphore *s, int i)
Definition: semaphore-tests.cc:24
BOOST_REQUIRE
BOOST_REQUIRE(originalColormap)
pass
boost::function< void()> pass(Semaphore *s)
Definition: helpers.cc:27