copied everything over from 2012 and removed all of the actual robot code except the drivetrain stuff
git-svn-id: https://robotics.mvla.net/svn/frc971/2013/trunk/src@4078 f308d9b7-e957-4cde-b6ac-9a88185e7312
diff --git a/aos/common/mutex_test.cpp b/aos/common/mutex_test.cpp
new file mode 100644
index 0000000..a5d5e86
--- /dev/null
+++ b/aos/common/mutex_test.cpp
@@ -0,0 +1,55 @@
+#include "aos/common/mutex.h"
+
+#include "gtest/gtest.h"
+
+namespace aos {
+namespace testing {
+
+class MutexTest : public ::testing::Test {
+ public:
+ Mutex test_mutex;
+};
+
+typedef MutexTest MutexDeathTest;
+
+TEST_F(MutexTest, TryLock) {
+ EXPECT_TRUE(test_mutex.TryLock());
+ EXPECT_FALSE(test_mutex.TryLock());
+}
+
+TEST_F(MutexTest, Lock) {
+ test_mutex.Lock();
+ EXPECT_FALSE(test_mutex.TryLock());
+}
+
+TEST_F(MutexTest, Unlock) {
+ test_mutex.Lock();
+ EXPECT_FALSE(test_mutex.TryLock());
+ test_mutex.Unlock();
+ EXPECT_TRUE(test_mutex.TryLock());
+}
+
+#ifndef __VXWORKS__
+// Sees what happens with multiple unlocks.
+TEST_F(MutexDeathTest, RepeatUnlock) {
+ test_mutex.Lock();
+ test_mutex.Unlock();
+ EXPECT_DEATH(test_mutex.Unlock(), ".*multiple unlock.*");
+}
+
+// Sees what happens if you unlock without ever locking (or unlocking) it.
+TEST_F(MutexDeathTest, NeverLock) {
+ EXPECT_DEATH(test_mutex.Unlock(), ".*multiple unlock.*");
+}
+#endif
+
+TEST_F(MutexTest, MutexLocker) {
+ {
+ aos::MutexLocker locker(&test_mutex);
+ EXPECT_FALSE(test_mutex.TryLock());
+ }
+ EXPECT_TRUE(test_mutex.TryLock());
+}
+
+} // namespace testing
+} // namespace aos