test/mutex.cpp
Go to the documentation of this file.
1 
11 /*****************************************************************************
12  ** Platform Check
13  *****************************************************************************/
14 #include <iostream>
15 #include <ecl/config/ecl.hpp>
16 #if defined(ECL_IS_POSIX)
17 
18 /*****************************************************************************
19  ** Includes
20  *****************************************************************************/
21 
22 #include <iostream>
23 #include <gtest/gtest.h>
24 #include <ecl/config/ecl.hpp>
26 #include <ecl/time/timestamp.hpp>
27 #include "../../include/ecl/threads/mutex.hpp"
28 
29 /*****************************************************************************
30  ** Using
31  *****************************************************************************/
32 
34 using ecl::Mutex;
35 using ecl::Duration;
36 
37 /*****************************************************************************
38  ** TESTS
39  *****************************************************************************/
40 
41 TEST(MutexTests,selfDestruct)
42 {
43  #if defined(NDEBUG) || defined(ECL_NDEBUG)
44  std::cout << "Skipping deadlock tests - posix doesn't help you in release mode." << std::endl;
45  SUCCEED();
46  #else
47  // It will now attempt to self-destruct while locked and throw an exception.
48  // This behaviour is only provided by posix in debug mode.
49  Mutex mutex;
50  mutex.lock();
51  try {
52  mutex.lock();
53  } catch (StandardException &e) {
54  SUCCEED();
55  }
56  mutex.unlock();
57  #endif
58 }
59 
60 TEST(MutexTests,tryLock)
61 {
62  // It will now attempt to self-destruct while locked and throw an exception.
63  Mutex mutex;
64  mutex.trylock();
65  EXPECT_FALSE(mutex.trylock());
66  mutex.unlock();
67 }
68 
69 TEST(MutexTests,timedLock)
70 {
71  // It will now attempt to self-destruct while locked and throw an exception.
72  // Trying to activate from the same thread will cause a deadlock
73  // and thus exception. Need to make a test with different threads here.
74  // Duration duration(1,500000000);
75  // Mutex mutex;
76  // mutex.lock();
77  // mutex.timedlock(duration);
78 }
79 
80 /*****************************************************************************
81  ** Main program
82  *****************************************************************************/
83 
84 int main(int argc, char **argv)
85 {
86 
87  testing::InitGoogleTest(&argc, argv);
88  return RUN_ALL_TESTS();
89 }
90 
91 #else
92 
93 /*****************************************************************************
94  ** Alternative main
95  *****************************************************************************/
96 
97 int main(int argc, char **argv)
98 {
99 
100  std::cout << "Currently not supported on your platform." << std::endl;
101 }
102 
103 #endif /* ECL_IS_POSIX */
int main(int argc, char **argv)
Definition: test/mutex.cpp:97
TEST(TypeTests, fundamentals)
TimeStamp Duration
ecl::Mutex mutex


ecl_threads
Author(s): Daniel Stonier
autogenerated on Mon Jun 10 2019 13:08:44