Refined test skipping.
authorMarkus Kauppila <markus.kauppila@gmail.com>
Tue, 19 Jul 2011 21:38:15 +0300
changeset 5773 a610795fd8fe
parent 5772 a6c404e897af
child 5774 4f9f82aa1a33
child 5775 61b87cd64b4d
Refined test skipping.
test/test-automation/runner.c
test/test-automation/support.c
--- a/test/test-automation/runner.c	Mon Jul 18 22:26:26 2011 +0300
+++ b/test/test-automation/runner.c	Tue Jul 19 21:38:15 2011 +0300
@@ -439,12 +439,6 @@
 		}
 	}
 
-	if(testReference->requirements & TEST_REQUIRES_AUDIO) {
-		//printf("Debug: checking for audio support.\n");
-		retVal = PlatformSupportsAudio();
-		//printf("Debug: Audio support: %d\n", retVal);
-	}
-
 	return retVal;
 }
 
@@ -638,6 +632,29 @@
 	exit(TEST_RESULT_KILLED);
 }
 
+/*!
+ * Checks if given test case can be executed on the current platform.
+ *
+ * \param testCase Test to be checked
+ * \returns 1 if test is runnable, otherwise 0. On error returns -1
+ */
+int
+CheckTestRequirements(TestCase *testCase)
+{
+	int retVal = 1;
+
+	if(testCase == NULL) {
+		fprintf(stderr, "TestCase parameter can't be NULL");
+		return -1;
+	}
+
+	if(testCase->requirements & TEST_REQUIRES_AUDIO) {
+		retVal = PlatformSupportsAudio();
+	}
+
+	return retVal;
+}
+
 
 /*
  * Execute a test. Loads the test, executes it and
@@ -647,35 +664,40 @@
  * \param test result
  */
 int
-RunTest(TestCase *testItem)
+RunTest(TestCase *testCase)
 {
-	if(testItem->timeout > 0 || universal_timeout > 0) {
+	int runnable = CheckTestRequirements(testCase);
+	if(runnable != 1) {
+		return TEST_RESULT_SKIPPED;
+	}
+
+	if(testCase->timeout > 0 || universal_timeout > 0) {
 		if(execute_inproc) {
 			Log(time(0), "Test asked for timeout which is not supported.");
 		}
 		else {
-			SetTestTimeout(testItem->timeout, KillHungTestInChildProcess);
+			SetTestTimeout(testCase->timeout, KillHungTestInChildProcess);
 		}
 	}
 
-	testItem->initTestEnvironment();
+	testCase->initTestEnvironment();
 
-	if(testItem->testSetUp) {
-		testItem->testSetUp(0x0);
+	if(testCase->testSetUp) {
+		testCase->testSetUp(0x0);
 	}
 
-	int cntFailedAsserts = testItem->countFailedAsserts();
+	int cntFailedAsserts = testCase->countFailedAsserts();
 	if(cntFailedAsserts != 0) {
 		return TEST_RESULT_SETUP_FAILURE;
 	}
 
-	testItem->testCase(0x0);
+	testCase->testCase(0x0);
 
-	if(testItem->testTearDown) {
-		testItem->testTearDown(0x0);
+	if(testCase->testTearDown) {
+		testCase->testTearDown(0x0);
 	}
 
-	return testItem->quitTestEnvironment();
+	return testCase->quitTestEnvironment();
 }
 
 
--- a/test/test-automation/support.c	Mon Jul 18 22:26:26 2011 +0300
+++ b/test/test-automation/support.c	Tue Jul 19 21:38:15 2011 +0300
@@ -37,7 +37,19 @@
 	return retValue;
 }
 
+
 /*
+
+Example of implementing new PlatformSupportXXX functions. The function
+should return 1 if the feature is supported. Otherwise return 0.
+
+Add call to the implemented function to runner.c in function
+CheckTestRequirements. Use the current implementation as a guide.
+
+Also add TEST_REQUIRES_XXX to SDL_test.h and use it in your tests
+TestCaseReference. In this case, you'd add TEST_REQUIRES_OPENGL to
+SDL_test.h
+
 int
 PlatformSupportsOpenGL() {
 	int retValue = 0;