]> git.gag.com Git - debian/openrocket/blobdiff - test/net/sf/openrocket/util/TestMutex.java
SafetyMutex and rocket optimization updates
[debian/openrocket] / test / net / sf / openrocket / util / TestMutex.java
index dd01848dd8d33968dcac39afbfe3bb794c132968..94d5a9f58cf884d55c588b8b373de13102718125 100644 (file)
@@ -2,13 +2,19 @@ package net.sf.openrocket.util;
 
 import static org.junit.Assert.*;
 
+import org.junit.Before;
 import org.junit.Test;
 
 public class TestMutex {
        
+       @Before
+       public void setup() {
+               System.setProperty("openrocket.debug.safetycheck", "true");
+       }
+       
        @Test
        public void testSingleLocking() {
-               SafetyMutex m = new SafetyMutex();
+               SafetyMutex.ConcreteSafetyMutex m = new SafetyMutex.ConcreteSafetyMutex();
                
                // Test single locking
                assertNull(m.lockingThread);
@@ -21,7 +27,7 @@ public class TestMutex {
        
        @Test
        public void testDoubleLocking() {
-               SafetyMutex m = new SafetyMutex();
+               SafetyMutex.ConcreteSafetyMutex m = new SafetyMutex.ConcreteSafetyMutex();
                
                // Test double locking
                m.verify();
@@ -37,9 +43,9 @@ public class TestMutex {
        
        @Test
        public void testDoubleUnlocking() {
-               SafetyMutex m = new SafetyMutex();
+               SafetyMutex.ConcreteSafetyMutex m = new SafetyMutex.ConcreteSafetyMutex();
                // Mark error reported to not init exception handler
-               SafetyMutex.errorReported = true;
+               SafetyMutex.ConcreteSafetyMutex.errorReported = true;
                
                m.lock("here");
                assertTrue(m.unlock("here"));
@@ -53,7 +59,7 @@ public class TestMutex {
        
        @Test(timeout = 1000)
        public void testThreadingErrors() {
-               final SafetyMutex m = new SafetyMutex();
+               final SafetyMutex.ConcreteSafetyMutex m = new SafetyMutex.ConcreteSafetyMutex();
                
                // Initialize and start the thread
                Thread thread = new Thread() {
@@ -153,4 +159,17 @@ public class TestMutex {
                }
        }
        
+       
+       public void testBogusMutex() {
+               SafetyMutex m = new SafetyMutex.BogusSafetyMutex();
+               m.lock("foo");
+               m.lock("bar");
+               m.lock("baz");
+               m.verify();
+               m.unlock("a");
+               m.unlock(null);
+               m.unlock("");
+               m.unlock("c");
+       }
+       
 }