ts_Semaphore.cpp
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 // This file is part of FZIs ic_workspace.
5 //
6 // This program is free software licensed under the LGPL
7 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
8 // You can find a copy of this license in LICENSE folder in the top
9 // directory of the source code.
10 //
11 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
12 //
13 // -- END LICENSE BLOCK ------------------------------------------------
14 
15 //----------------------------------------------------------------------
22 //----------------------------------------------------------------------
23 #include <boost/test/unit_test.hpp>
24 #include <icl_core_thread/Sem.h>
25 
26 using icl_core::TimeSpan;
29 
30 BOOST_AUTO_TEST_SUITE(ts_Semaphore)
31 
32 BOOST_AUTO_TEST_CASE(SemaphorePostWait)
33 {
34  Semaphore sem(0);
35  sem.post();
36  BOOST_CHECK(sem.wait());
37 }
38 
39 BOOST_AUTO_TEST_CASE(SemaphoreTryWait)
40 {
41  Semaphore sem(0);
42  BOOST_CHECK(!sem.tryWait());
43  sem.post();
44  BOOST_CHECK(sem.tryWait());
45 }
46 
47 BOOST_AUTO_TEST_CASE(SemaphoreWaitAbsoluteTimeout)
48 {
49  Semaphore sem(0);
50  BOOST_CHECK(!sem.wait(TimeStamp::now() + TimeSpan(1, 0)));
51  sem.post();
52  BOOST_CHECK(sem.wait(TimeStamp::now() + TimeSpan(1, 0)));
53 }
54 
55 BOOST_AUTO_TEST_CASE(SemaphoreWaitRelativeTimeout)
56 {
57  Semaphore sem(0);
58  BOOST_CHECK(!sem.wait(TimeSpan(1, 0)));
59  sem.post();
60  BOOST_CHECK(sem.wait(TimeSpan(1, 0)));
61 }
62 
63 BOOST_AUTO_TEST_SUITE_END()
Represents absolute times.
Definition: TimeStamp.h:61
BOOST_AUTO_TEST_CASE(SemaphorePostWait)
Repesents absolute times.
Definition: TimeSpan.h:46
Contains icl_core::thread::Semaphore.


fzi_icl_core
Author(s):
autogenerated on Mon Jun 10 2019 13:17:58