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  ** TESTS
00039  *****************************************************************************/
00040 
00041 TEST(MutexTests,selfDestruct)
00042 {
00043   #if defined(NDEBUG) || defined(ECL_NDEBUG)
00044     std::cout << "Skipping deadlock tests - posix doesn't help you in release mode." << std::endl;
00045     SUCCEED();
00046   #else
00047     // It will now attempt to self-destruct while locked and throw an exception.
00048     // This behaviour is only provided by posix in debug mode.
00049     Mutex mutex;
00050     mutex.lock();
00051     try {
00052       mutex.lock();
00053     } catch (StandardException &e) {
00054       SUCCEED();
00055     }
00056     mutex.unlock();
00057   #endif
00058 }
00059 
00060 TEST(MutexTests,tryLock)
00061 {
00062   // It will now attempt to self-destruct while locked and throw an exception.
00063   Mutex mutex;
00064   mutex.trylock();
00065   EXPECT_FALSE(mutex.trylock());
00066   mutex.unlock();
00067 }
00068 
00069 TEST(MutexTests,timedLock)
00070 {
00071   // It will now attempt to self-destruct while locked and throw an exception.
00072   // Trying to activate from the same thread will cause a deadlock
00073   // and thus exception. Need to make a test with different threads here.
00074   // Duration duration(1,500000000);
00075   // Mutex mutex;
00076   // mutex.lock();
00077   // mutex.timedlock(duration);
00078 }
00079 
00080 /*****************************************************************************
00081  ** Main program
00082  *****************************************************************************/
00083 
00084 int main(int argc, char **argv)
00085 {
00086 
00087   testing::InitGoogleTest(&argc, argv);
00088   return RUN_ALL_TESTS();
00089 }
00090 
00091 #else
00092 
00093 /*****************************************************************************
00094  ** Alternative main
00095  *****************************************************************************/
00096 
00097 int main(int argc, char **argv)
00098 {
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 Thu Jun 6 2019 21:18:01