29package com.jogamp.openal.test.util;
31import java.io.BufferedReader;
32import java.io.IOException;
33import java.io.InputStreamReader;
34import java.util.Iterator;
37import com.jogamp.common.util.locks.SingletonInstance;
39import org.junit.Assume;
40import org.junit.Before;
41import org.junit.BeforeClass;
42import org.junit.After;
43import org.junit.AfterClass;
44import org.junit.FixMethodOrder;
46import org.junit.rules.TestName;
47import org.junit.runners.MethodSorters;
48import org.junit.runners.model.FrameworkMethod;
49import org.junit.runners.model.TestClass;
51@FixMethodOrder(MethodSorters.NAME_ASCENDING)
53 @Rule
public TestName _unitTestName =
new TestName();
55 public static final String SINGLE_INSTANCE_LOCK_FILE =
"UITestCase.lock";
56 public static final int SINGLE_INSTANCE_LOCK_PORT = 59999;
58 public static final long SINGLE_INSTANCE_LOCK_TO = 6*60*1000;
59 public static final long SINGLE_INSTANCE_LOCK_POLL = 1000;
61 private static volatile SingletonInstance singletonInstance;
63 private static volatile boolean testSupported =
true;
65 private static volatile int maxMethodNameLen = 0;
67 private static final synchronized void initSingletonInstance() {
68 if(
null == singletonInstance ) {
70 singletonInstance = SingletonInstance.createServerSocket(SINGLE_INSTANCE_LOCK_POLL, SINGLE_INSTANCE_LOCK_PORT);
71 if(!singletonInstance.tryLock(SINGLE_INSTANCE_LOCK_TO)) {
72 throw new RuntimeException(
"Fatal: Could not lock single instance: "+singletonInstance.getName());
82 System.err.println(
"setTestSupported: "+v);
87 if(0 == maxMethodNameLen) {
89 final TestClass tc =
new TestClass(getClass());
90 final List<FrameworkMethod> testMethods = tc.getAnnotatedMethods(org.junit.Test.class);
91 for(
final Iterator<FrameworkMethod> iter=testMethods.iterator(); iter.hasNext(); ) {
92 final int l = iter.next().getName().length();
93 if( ml < l ) { ml = l; }
95 maxMethodNameLen = ml;
97 return maxMethodNameLen;
101 return _unitTestName.getMethodName();
105 return getClass().getSimpleName()+separator+getTestMethodName();
109 return getClass().getName()+separator+getTestMethodName();
115 initSingletonInstance();
122 singletonInstance.unlock();
127 System.err.print(
"++++ UITestCase.setUp: "+getFullTestName(
" - "));
129 System.err.println(
" - "+unsupportedTestMsg);
130 Assume.assumeTrue(testSupported);
132 System.err.println();
137 System.err.println(
"++++ UITestCase.tearDown: "+getFullTestName(
" - "));
141 final BufferedReader stdin =
new BufferedReader(
new InputStreamReader(System.in));
142 System.err.println(preMessage+
"> Press enter to continue");
144 System.err.println(stdin.readLine());
145 }
catch (
final IOException e) { }
148 static final String unsupportedTestMsg =
"Test not supported on this platform.";
static void oneTimeTearDown()
static void setTestSupported(final boolean v)
final String getTestMethodName()
final String getSimpleTestName(final String separator)
static boolean isTestSupported()
static void waitForKey(final String preMessage)
static void oneTimeSetUp()
final String getFullTestName(final String separator)