00001 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*- 00002 00003 // -- BEGIN LICENSE BLOCK ---------------------------------------------- 00004 // This file is part of FZIs ic_workspace. 00005 // 00006 // This program is free software licensed under the LGPL 00007 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3). 00008 // You can find a copy of this license in LICENSE folder in the top 00009 // directory of the source code. 00010 // 00011 // © Copyright 2014 FZI Forschungszentrum Informatik, Karlsruhe, Germany 00012 // 00013 // -- END LICENSE BLOCK ------------------------------------------------ 00014 00015 //---------------------------------------------------------------------- 00022 //---------------------------------------------------------------------- 00023 #include <boost/test/unit_test.hpp> 00024 #include <icl_core_thread/Sem.h> 00025 00026 using icl_core::TimeSpan; 00027 using icl_core::TimeStamp; 00028 using icl_core::thread::Semaphore; 00029 00030 BOOST_AUTO_TEST_SUITE(ts_Semaphore) 00031 00032 BOOST_AUTO_TEST_CASE(SemaphorePostWait) 00033 { 00034 Semaphore sem(0); 00035 sem.post(); 00036 BOOST_CHECK(sem.wait()); 00037 } 00038 00039 BOOST_AUTO_TEST_CASE(SemaphoreTryWait) 00040 { 00041 Semaphore sem(0); 00042 BOOST_CHECK(!sem.tryWait()); 00043 sem.post(); 00044 BOOST_CHECK(sem.tryWait()); 00045 } 00046 00047 BOOST_AUTO_TEST_CASE(SemaphoreWaitAbsoluteTimeout) 00048 { 00049 Semaphore sem(0); 00050 BOOST_CHECK(!sem.wait(TimeStamp::now() + TimeSpan(1, 0))); 00051 sem.post(); 00052 BOOST_CHECK(sem.wait(TimeStamp::now() + TimeSpan(1, 0))); 00053 } 00054 00055 BOOST_AUTO_TEST_CASE(SemaphoreWaitRelativeTimeout) 00056 { 00057 Semaphore sem(0); 00058 BOOST_CHECK(!sem.wait(TimeSpan(1, 0))); 00059 sem.post(); 00060 BOOST_CHECK(sem.wait(TimeSpan(1, 0))); 00061 } 00062 00063 BOOST_AUTO_TEST_SUITE_END()