libmoost
/home/mhx/git/github/libmoost/test/thread/token_mutex.cpp
Go to the documentation of this file.
00001 /* vim:set ts=3 sw=3 sts=3 et: */
00028 #include <boost/test/unit_test.hpp>
00029 #include <boost/test/test_tools.hpp>
00030 
00031 #include <vector>
00032 #include <string>
00033 
00034 #include "../../include/moost/thread/token_mutex.hpp"
00035 
00036 using namespace moost::thread;
00037 
00038 BOOST_AUTO_TEST_SUITE( token_mutex_test )
00039 
00040 struct Fixture
00041 {
00042   token_mutex<int> int_mutex;
00043 
00044   Fixture()
00045   {
00046   }
00047 
00048   ~Fixture()
00049   {
00050   }
00051 };
00052 
00053 BOOST_FIXTURE_TEST_CASE( test_trylock, Fixture )
00054 {
00055   BOOST_CHECK(int_mutex.trylock(3));
00056   BOOST_CHECK(int_mutex.trylock(4));
00057   BOOST_CHECK(!int_mutex.trylock(3));
00058   int_mutex.unlock(3);
00059   BOOST_CHECK(int_mutex.trylock(3));
00060 }
00061 
00062 BOOST_FIXTURE_TEST_CASE( test_tryscopedlock, Fixture )
00063 {
00064   token_mutex<int>::scoped_try_lock lock1(int_mutex, 3);
00065   BOOST_CHECK(lock1);
00066   token_mutex<int>::scoped_try_lock lock2(int_mutex, 4);
00067   BOOST_CHECK(lock2);
00068   token_mutex<int>::scoped_try_lock lock3(int_mutex, 3);
00069   BOOST_CHECK(!lock3);
00070 }
00071 
00072 // TODO: figure out some nifty threaded way of testing rest of token_mutex
00073 
00074 BOOST_AUTO_TEST_SUITE_END()