mutex.cpp
Go to the documentation of this file.
00001 
00011 /*****************************************************************************
00012 ** Platform Check
00013 *****************************************************************************/
00014 #include <iostream>
00015 #include <ecl/config/ecl.hpp>
00016 #if defined(ECL_IS_POSIX)
00017 
00018 /*****************************************************************************
00019 ** Includes
00020 *****************************************************************************/
00021 
00022 #include <iostream>
00023 #include <gtest/gtest.h>
00024 #include <ecl/config/ecl.hpp>
00025 #include <ecl/exceptions/standard_exception.hpp>
00026 #include <ecl/time/timestamp.hpp>
00027 #include "../../include/ecl/threads/mutex.hpp"
00028 
00029 /*****************************************************************************
00030 ** Using
00031 *****************************************************************************/
00032 
00033 using ecl::StandardException;
00034 using ecl::Mutex;
00035 using ecl::Duration;
00036 
00037 /*****************************************************************************
00038 ** Macros
00039 *****************************************************************************/
00040 
00041 // Make sure we can test the debug mode properties.
00042 #if defined(NDEBUG) || defined(ECL_NDEBUG)
00043         #undef NDEBUG
00044         #undef ECL_NDEBUG
00045 #endif
00046 
00047 /*****************************************************************************
00048 ** TESTS
00049 *****************************************************************************/
00050 
00051 TEST(MutexTests,selfDestruct) {
00052         // It will now attempt to self-destruct while locked and throw an exception.
00053         Mutex mutex;
00054     mutex.lock();
00055     try {
00056         mutex.lock();
00057     } catch ( StandardException &e ) {
00058         SUCCEED();
00059     }
00060     mutex.unlock();
00061 }
00062 
00063 TEST(MutexTests,tryLock) {
00064         // It will now attempt to self-destruct while locked and throw an exception.
00065         Mutex mutex;
00066     mutex.trylock();
00067     EXPECT_FALSE(mutex.trylock());
00068     mutex.unlock();
00069 }
00070 
00071 TEST(MutexTests,timedLock) {
00072         // It will now attempt to self-destruct while locked and throw an exception.
00073         // Trying to activate from the same thread will cause a deadlock
00074         // and thus exception. Need to make a test with different threads here.
00075         // Duration duration(1,500000000);
00076         // Mutex mutex;
00077         // mutex.lock();
00078         // mutex.timedlock(duration);
00079 }
00080 
00081 /*****************************************************************************
00082 ** Main program
00083 *****************************************************************************/
00084 
00085 int main(int argc, char **argv) {
00086 
00087     testing::InitGoogleTest(&argc,argv);
00088     return RUN_ALL_TESTS();
00089 }
00090 
00091 
00092 #else
00093 
00094 /*****************************************************************************
00095 ** Alternative main
00096 *****************************************************************************/
00097 
00098 int main(int argc, char **argv) {
00099 
00100         std::cout << "Currently not supported on your platform." << std::endl;
00101 }
00102 
00103 #endif /* ECL_IS_POSIX */


ecl_threads
Author(s): Daniel Stonier
autogenerated on Sun Oct 5 2014 23:35:37