From cd4b36e51d8975af198f84b2b29f83918d2c196c Mon Sep 17 00:00:00 2001 From: Andreas Schiffler Date: Sat, 22 Dec 2012 16:06:55 -0800 Subject: [PATCH] Test lib updates: updated harness to support filtering, added surface comparer, updated interface to test images; added Render test suite from GSOC project --- VisualC/SDLtest/SDLtest_VS2010.vcxproj | 2 + VisualC/SDLtest/SDLtest_VS2012.vcxproj | 2 + include/SDL_test.h | 1 + include/SDL_test_compare.h | 72 ++ include/SDL_test_harness.h | 3 +- include/SDL_test_images.h | 27 +- src/test/SDL_test_compare.c | 83 ++ src/test/SDL_test_fuzzer.c | 8 +- src/test/SDL_test_harness.c | 418 +++++---- src/test/SDL_test_imageBlit.c | 77 ++ src/test/SDL_test_imageBlitBlend.c | 129 +++ src/test/SDL_test_imageFace.c | 28 +- src/test/SDL_test_imagePrimitives.c | 25 + src/test/SDL_test_imagePrimitivesBlend.c | 25 + test/testautomation.c | 12 +- test/tests/testrender.c | 1025 ++++++++++++++++++++++ test/tests/testsuites.h | 4 +- 17 files changed, 1748 insertions(+), 193 deletions(-) create mode 100644 include/SDL_test_compare.h create mode 100644 src/test/SDL_test_compare.c create mode 100644 test/tests/testrender.c diff --git a/VisualC/SDLtest/SDLtest_VS2010.vcxproj b/VisualC/SDLtest/SDLtest_VS2010.vcxproj index 7dac308c9..e4e35b058 100644 --- a/VisualC/SDLtest/SDLtest_VS2010.vcxproj +++ b/VisualC/SDLtest/SDLtest_VS2010.vcxproj @@ -162,6 +162,7 @@ + @@ -178,6 +179,7 @@ + diff --git a/VisualC/SDLtest/SDLtest_VS2012.vcxproj b/VisualC/SDLtest/SDLtest_VS2012.vcxproj index f3eae84f8..2e306c095 100644 --- a/VisualC/SDLtest/SDLtest_VS2012.vcxproj +++ b/VisualC/SDLtest/SDLtest_VS2012.vcxproj @@ -166,6 +166,7 @@ + @@ -182,6 +183,7 @@ + diff --git a/include/SDL_test.h b/include/SDL_test.h index 499f315ad..59cb9b396 100644 --- a/include/SDL_test.h +++ b/include/SDL_test.h @@ -41,6 +41,7 @@ #include "SDL_test_assert.h" #include "SDL_test_harness.h" #include "SDL_test_images.h" +#include "SDL_test_compare.h" #include "begin_code.h" /* Set up for C function definitions, even when using C++ */ diff --git a/include/SDL_test_compare.h b/include/SDL_test_compare.h new file mode 100644 index 000000000..c22eb1bbd --- /dev/null +++ b/include/SDL_test_compare.h @@ -0,0 +1,72 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2012 Sam Lantinga + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +/** + * \file SDL_test_compare.h + * + * Include file for SDL test framework. + * + * This code is a part of the SDL2_test library, not the main SDL library. + */ + +/* + + Defines comparison functions (i.e. for surfaces). + +*/ + +#ifndef _SDL_test_compare_h +#define _SDL_test_compare_h + +#include "SDL.h" +#include "SDL_test_images.h" + +#include "begin_code.h" +/* Set up for C function definitions, even when using C++ */ +#ifdef __cplusplus +/* *INDENT-OFF* */ +extern "C" { +/* *INDENT-ON* */ +#endif + +/** + * \brief Compares a surface and with reference image data for equality + * + * \param sur Surface used in comparison + * \param img Test Surface used in comparison + * \param allowable_error Allowable difference in blending accuracy + * + * \returns 0 if comparison succeeded, >0 (=number of pixels where comparison failed) if comparison failed, <0 for any other error. + */ +int SDLTest_CompareSurfaces(SDL_Surface *sur, SDL_Surface *img, int allowable_error); + + +/* Ends C function definitions when using C++ */ +#ifdef __cplusplus +/* *INDENT-OFF* */ +} +/* *INDENT-ON* */ +#endif +#include "close_code.h" + +#endif /* _SDL_test_compare_h */ + +/* vi: set ts=4 sw=4 expandtab: */ diff --git a/include/SDL_test_harness.h b/include/SDL_test_harness.h index e2608ace9..ef82afc25 100644 --- a/include/SDL_test_harness.h +++ b/include/SDL_test_harness.h @@ -105,11 +105,12 @@ typedef struct SDLTest_TestSuiteReference { * \param testSuites Suites containing the test case. * \param userRunSeed Custom run seed provided by user, or NULL to autogenerate one. * \param userExecKey Custom execution key provided by user, or 0 to autogenerate one. + * \param filter Filter specification. NULL disables. Case sensitive. * \param testIterations Number of iterations to run each test case. * * \returns Test run result; 0 when all tests passed, 1 if any tests failed. */ -int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], char *userRunSeed, Uint64 userExecKey, int testIterations); +int SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], char *userRunSeed, Uint64 userExecKey, char *filter, int testIterations); /* Ends C function definitions when using C++ */ diff --git a/include/SDL_test_images.h b/include/SDL_test_images.h index 52034dd31..a5f531669 100644 --- a/include/SDL_test_images.h +++ b/include/SDL_test_images.h @@ -36,6 +36,8 @@ #ifndef _SDL_test_images_h #define _SDL_test_images_h +#include "SDL.h" + #include "begin_code.h" /* Set up for C function definitions, even when using C++ */ #ifdef __cplusplus @@ -44,29 +46,28 @@ extern "C" { /* *INDENT-ON* */ #endif - /** *Type for test images. */ typedef struct SDLTest_SurfaceImage_s { int width; int height; - unsigned int bytes_per_pixel; /* 3:RGB, 4:RGBA */ + unsigned int bytes_per_pixel; /* 3:RGB, 4:RGBA */ const unsigned char pixel_data[]; } SDLTest_SurfaceImage_t; /* Test images */ -const SDLTest_SurfaceImage_t SDLTest_imageBlit; -const SDLTest_SurfaceImage_t SDLTest_imageBlitColor; -const SDLTest_SurfaceImage_t SDLTest_imageBlitAlpha; -const SDLTest_SurfaceImage_t SDLTest_imageBlitBlendAdd; -const SDLTest_SurfaceImage_t SDLTest_imageBlitBlend; -const SDLTest_SurfaceImage_t SDLTest_imageBlitBlendMod; -const SDLTest_SurfaceImage_t SDLTest_imageBlitBlendNone; -const SDLTest_SurfaceImage_t SDLTest_imageBlitBlendAll; -const SDLTest_SurfaceImage_t SDLTest_ImageFace; -const SDLTest_SurfaceImage_t SDLTest_imagePrimitives; -const SDLTest_SurfaceImage_t SDLTest_imagePrimitivesBlend; +SDL_Surface *SDLTest_ImageBlit(); +SDL_Surface *SDLTest_ImageBlitColor(); +SDL_Surface *SDLTest_ImageBlitAlpha(); +SDL_Surface *SDLTest_ImageBlitBlendAdd(); +SDL_Surface *SDLTest_ImageBlitBlend(); +SDL_Surface *SDLTest_ImageBlitBlendMod(); +SDL_Surface *SDLTest_ImageBlitBlendNone(); +SDL_Surface *SDLTest_ImageBlitBlendAll(); +SDL_Surface *SDLTest_ImageFace(); +SDL_Surface *SDLTest_ImagePrimitives(); +SDL_Surface *SDLTest_ImagePrimitivesBlend(); /* Ends C function definitions when using C++ */ #ifdef __cplusplus diff --git a/src/test/SDL_test_compare.c b/src/test/SDL_test_compare.c new file mode 100644 index 000000000..d2e878d31 --- /dev/null +++ b/src/test/SDL_test_compare.c @@ -0,0 +1,83 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2012 Sam Lantinga + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +/* + + Based on automated SDL_Surface tests originally written by Edgar Simo 'bobbens'. + + Rewritten for test lib by Andreas Schiffler. + +*/ + +#include "SDL_config.h" + +#include "SDL_test.h" + + +int SDLTest_CompareSurfaces( SDL_Surface *surface, SDL_Surface *referenceSurface, int allowable_error ) +{ + int ret; + int i,j; + int bpp, bpp_reference; + Uint8 *p, *p_reference; + int dist; + Uint8 R, G, B, A; + Uint8 Rd, Gd, Bd, Ad; + + /* Make surfacee size is the same. */ + if ((surface->w != referenceSurface->w) || (surface->h != referenceSurface->h)) + { + return -1; + } + + SDL_LockSurface( surface ); + SDL_LockSurface( referenceSurface ); + + ret = 0; + bpp = surface->format->BytesPerPixel; + bpp_reference = referenceSurface->format->BytesPerPixel; + + /* Compare image - should be same format. */ + for (j=0; jh; j++) { + for (i=0; iw; i++) { + p = (Uint8 *)surface->pixels + j * surface->pitch + i * bpp; + p_reference = (Uint8 *)referenceSurface->pixels + j * referenceSurface->pitch + i * bpp_reference; + dist = 0; + + SDL_GetRGBA(*(Uint32*)p, surface->format, &R, &G, &B, &A); + SDL_GetRGBA(*(Uint32*)p_reference, referenceSurface->format, &Rd, &Gd, &Bd, &Ad); + + dist += (R-Rd)*(R-Rd); + dist += (G-Gd)*(G-Gd); + dist += (B-Bd)*(B-Bd); + + /* Allow some difference in blending accuracy */ + if (dist > allowable_error) { + ret++; + } + } + } + + SDL_UnlockSurface( surface ); + SDL_UnlockSurface( referenceSurface ); + + return ret; +} diff --git a/src/test/SDL_test_fuzzer.c b/src/test/SDL_test_fuzzer.c index 3ef546da3..9ae5f88fa 100644 --- a/src/test/SDL_test_fuzzer.c +++ b/src/test/SDL_test_fuzzer.c @@ -116,8 +116,8 @@ SDLTest_RandomUint32() Uint64 SDLTest_RandomUint64() { - Uint64 value; - Uint32 *vp = (void*)&value; + Uint64 value = 0; + Uint32 *vp = (void *)&value; fuzzerInvocationCounter++; @@ -130,8 +130,8 @@ SDLTest_RandomUint64() Sint64 SDLTest_RandomSint64() { - Uint64 value; - Uint32 *vp = (void*)&value; + Uint64 value = 0; + Uint32 *vp = (void *)&value; fuzzerInvocationCounter++; diff --git a/src/test/SDL_test_harness.c b/src/test/SDL_test_harness.c index 50ff47563..023340626 100644 --- a/src/test/SDL_test_harness.c +++ b/src/test/SDL_test_harness.c @@ -1,22 +1,22 @@ /* - Simple DirectMedia Layer - Copyright (C) 1997-2012 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. +Simple DirectMedia Layer +Copyright (C) 1997-2012 Sam Lantinga + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must not +claim that you wrote the original software. If you use this software +in a product, an acknowledgment in the product documentation would be +appreciated but is not required. +2. Altered source versions must be plainly marked as such, and must not be +misrepresented as being the original software. +3. This notice may not be removed or altered from any source distribution. */ #include "SDL_config.h" @@ -41,17 +41,17 @@ const char *SDLTest_FinalResultFormat = ">>> %s '%s': %s\n"; static Uint32 SDLTest_TestCaseTimeout = 3600; /** - * Generates a random run seed string for the harness. The generated seed - * will contain alphanumeric characters (0-9A-Z). - * - * Note: The returned string needs to be deallocated by the caller. - * - * \param length The length of the seed string to generate - * - * \returns The generated seed string - */ +* Generates a random run seed string for the harness. The generated seed +* will contain alphanumeric characters (0-9A-Z). +* +* Note: The returned string needs to be deallocated by the caller. +* +* \param length The length of the seed string to generate +* +* \returns The generated seed string +*/ char * -SDLTest_GenerateRunSeed(const int length) + SDLTest_GenerateRunSeed(const int length) { char *seed = NULL; SDLTest_RandomContext randomContext; @@ -86,18 +86,18 @@ SDLTest_GenerateRunSeed(const int length) } /** - * Generates an execution key for the fuzzer. - * - * \param runSeed The run seed to use - * \param suiteName The name of the test suite - * \param testName The name of the test - * \param iteration The iteration count - * - * \returns The generated execution key to initialize the fuzzer with. - * - */ +* Generates an execution key for the fuzzer. +* +* \param runSeed The run seed to use +* \param suiteName The name of the test suite +* \param testName The name of the test +* \param iteration The iteration count +* +* \returns The generated execution key to initialize the fuzzer with. +* +*/ Uint64 -SDLTest_GenerateExecKey(char *runSeed, char *suiteName, char *testName, int iteration) + SDLTest_GenerateExecKey(char *runSeed, char *suiteName, char *testName, int iteration) { SDLTest_Md5Context md5Context; Uint64 *keys; @@ -157,17 +157,17 @@ SDLTest_GenerateExecKey(char *runSeed, char *suiteName, char *testName, int iter } /** - * \brief Set timeout handler for test. - * - * Note: SDL_Init(SDL_INIT_TIMER) will be called if it wasn't done so before. - * - * \param timeout Timeout interval in seconds. - * \param callback Function that will be called after timeout has elapsed. - * - * \return Timer id or -1 on failure. - */ +* \brief Set timeout handler for test. +* +* Note: SDL_Init(SDL_INIT_TIMER) will be called if it wasn't done so before. +* +* \param timeout Timeout interval in seconds. +* \param callback Function that will be called after timeout has elapsed. +* +* \return Timer id or -1 on failure. +*/ SDL_TimerID -SDLTest_SetTestTimeout(int timeout, void (*callback)()) + SDLTest_SetTestTimeout(int timeout, void (*callback)()) { Uint32 timeoutInMilliseconds; SDL_TimerID timerID; @@ -201,24 +201,27 @@ SDLTest_SetTestTimeout(int timeout, void (*callback)()) return timerID; } +/** +* \brief Timeout handler. Aborts test run and exits harness process. +*/ void -SDLTest_BailOut() + SDLTest_BailOut() { SDLTest_LogError("TestCaseTimeout timer expired. Aborting test run."); exit(TEST_ABORTED); // bail out from the test } /** - * \brief Execute a test using the given execution key. - * - * \param testSuite Suite containing the test case. - * \param testCase Case to execute. - * \param execKey Execution key for the fuzzer. - * - * \returns Test case result. - */ +* \brief Execute a test using the given execution key. +* +* \param testSuite Suite containing the test case. +* \param testCase Case to execute. +* \param execKey Execution key for the fuzzer. +* +* \returns Test case result. +*/ int -SDLTest_RunTest(SDLTest_TestSuiteReference *testSuite, SDLTest_TestCaseReference *testCase, Uint64 execKey) + SDLTest_RunTest(SDLTest_TestSuiteReference *testSuite, SDLTest_TestCaseReference *testCase, Uint64 execKey) { SDL_TimerID timer = 0; int testResult = 0; @@ -232,11 +235,12 @@ SDLTest_RunTest(SDLTest_TestSuiteReference *testSuite, SDLTest_TestCaseReference if (!testCase->enabled) { - SDLTest_Log((char *)SDLTest_FinalResultFormat, "Test", testCase->name, "Skipped"); + SDLTest_Log((char *)SDLTest_FinalResultFormat, "Test", testCase->name, "Skipped (Disabled)"); return TEST_RESULT_SKIPPED; } - // Initialize fuzzer + + // Initialize fuzzer SDLTest_FuzzerInit(execKey); // Reset assert tracker @@ -315,17 +319,21 @@ float GetClock() } /** - * \brief Execute a test suite using the given run seend and execution key. - * - * \param testSuites Suites containing the test case. - * \param userRunSeed Custom run seed provided by user, or NULL to autogenerate one. - * \param userExecKey Custom execution key provided by user, or 0 to autogenerate one. - * \param testIterations Number of iterations to run each test case. - * - * \returns Test run result; 0 when all tests passed, 1 if any tests failed. - */ +* \brief Execute a test suite using the given run seend and execution key. +* +* The filter string is matched to the suite name (full comparison) to select a single suite, +* or if no suite matches, it is matched to the test names (full comparison) to select a single test. +* +* \param testSuites Suites containing the test case. +* \param userRunSeed Custom run seed provided by user, or NULL to autogenerate one. +* \param userExecKey Custom execution key provided by user, or 0 to autogenerate one. +* \param filter Filter specification. NULL disables. Case sensitive. +* \param testIterations Number of iterations to run each test case. +* +* \returns Test run result; 0 when all tests passed, 1 if any tests failed. +*/ int -SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], char *userRunSeed, Uint64 userExecKey, int testIterations) + SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], char *userRunSeed, Uint64 userExecKey, char *filter, int testIterations) { int suiteCounter; int testCounter; @@ -343,6 +351,10 @@ SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], char *userRunSeed, U float suiteEndSeconds; float testEndSeconds; float runtime; + int suiteFilter = 0; + char *suiteFilterName = NULL; + int testFilter = 0; + char *testFilterName = NULL; int testResult = 0; int runResult = 0; Uint32 totalTestFailedCount = 0; @@ -370,6 +382,7 @@ SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], char *userRunSeed, U runSeed = userRunSeed; } + // Reset per-run counters totalTestFailedCount = 0; totalTestPassedCount = 0; @@ -381,121 +394,184 @@ SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], char *userRunSeed, U // Log run with fuzzer parameters SDLTest_Log("::::: Test Run /w seed '%s' started\n", runSeed); + // Initialize filtering + if (filter != NULL && SDL_strlen(filter) > 0) { + /* Loop over all suites to check if we have a filter match */ + suiteCounter = 0; + while (testSuites[suiteCounter] && suiteFilter == 0) { + testSuite=(SDLTest_TestSuiteReference *)testSuites[suiteCounter]; + suiteCounter++; + if (testSuite->name != NULL && SDL_strcmp(filter, testSuite->name) == 0) { + /* Matched a suite name */ + suiteFilter = 1; + suiteFilterName = testSuite->name; + SDLTest_Log("Filtering: running only suite '%s'", suiteFilterName); + break; + } + + /* Within each suite, loop over all test cases to check if we have a filter match */ + testCounter = 0; + while (testSuite->testCases[testCounter] && testFilter == 0) + { + testCase=(SDLTest_TestCaseReference *)testSuite->testCases[testCounter]; + testCounter++; + if (testCase->name != NULL && SDL_strcmp(filter, testCase->name) == 0) { + /* Matched a test name */ + suiteFilter = 1; + suiteFilterName = testSuite->name; + testFilter = 1; + testFilterName = testCase->name; + SDLTest_Log("Filtering: running only test '%s' in suite '%s'", testFilterName, suiteFilterName); + break; + } + } + } + + if (suiteFilter == 0 && testFilter == 0) { + SDLTest_LogError("Filter '%s' did not match any test suite/case.", filter); + SDLTest_Log("Exit code: 2"); + return 2; + } + } + // Loop over all suites suiteCounter = 0; while(testSuites[suiteCounter]) { testSuite=(SDLTest_TestSuiteReference *)testSuites[suiteCounter]; - suiteCounter++; - - // Reset per-suite counters - testFailedCount = 0; - testPassedCount = 0; - testSkippedCount = 0; - - // Take time - suite start - suiteStartSeconds = GetClock(); - - // Log suite started currentSuiteName = (char *)((testSuite->name) ? testSuite->name : SDLTest_InvalidNameFormat); - SDLTest_Log("===== Test Suite %i: '%s' started\n", - suiteCounter, - currentSuiteName); + suiteCounter++; - // Loop over all test cases - testCounter = 0; - while(testSuite->testCases[testCounter]) - { - testCase=(SDLTest_TestCaseReference *)testSuite->testCases[testCounter]; - testCounter++; - - // Take time - test start - testStartSeconds = GetClock(); - - // Log test started - currentTestName = (char *)((testCase->name) ? testCase->name : SDLTest_InvalidNameFormat); - SDLTest_Log("----- Test Case %i.%i: '%s' started", - suiteCounter, - testCounter, - currentTestName); - if (testCase->description != NULL && strlen(testCase->description)>0) { - SDLTest_Log("Test Description: '%s'", - (testCase->description) ? testCase->description : SDLTest_InvalidNameFormat); - } - - // Loop over all iterations - iterationCounter = 0; - while(iterationCounter < testIterations) + // Filter suite if flag set and we have a name + if (suiteFilter == 1 && suiteFilterName != NULL && testSuite->name != NULL && + SDL_strcmp(suiteFilterName, testSuite->name) != 0) { + // Skip suite + SDLTest_Log("===== Test Suite %i: '%s' skipped\n", + suiteCounter, + currentSuiteName); + } else { + + // Reset per-suite counters + testFailedCount = 0; + testPassedCount = 0; + testSkippedCount = 0; + + // Take time - suite start + suiteStartSeconds = GetClock(); + + // Log suite started + SDLTest_Log("===== Test Suite %i: '%s' started\n", + suiteCounter, + currentSuiteName); + + // Loop over all test cases + testCounter = 0; + while(testSuite->testCases[testCounter]) { - iterationCounter++; - - if (userExecKey != 0) { - execKey = userExecKey; + testCase=(SDLTest_TestCaseReference *)testSuite->testCases[testCounter]; + currentTestName = (char *)((testCase->name) ? testCase->name : SDLTest_InvalidNameFormat); + testCounter++; + + // Filter tests if flag set and we have a name + if (testFilter == 1 && testFilterName != NULL && testCase->name != NULL && + SDL_strcmp(testFilterName, testCase->name) != 0) { + // Skip test + SDLTest_Log("===== Test Case %i.%i: '%s' skipped\n", + suiteCounter, + testCounter, + currentTestName); } else { - execKey = SDLTest_GenerateExecKey(runSeed, testSuite->name, testCase->name, iterationCounter); - } - SDLTest_Log("Test Iteration %i: execKey %llu", iterationCounter, execKey); - testResult = SDLTest_RunTest(testSuite, testCase, execKey); + // Take time - test start + testStartSeconds = GetClock(); + + // Log test started + SDLTest_Log("----- Test Case %i.%i: '%s' started", + suiteCounter, + testCounter, + currentTestName); + if (testCase->description != NULL && strlen(testCase->description)>0) { + SDLTest_Log("Test Description: '%s'", + (testCase->description) ? testCase->description : SDLTest_InvalidNameFormat); + } + + // Loop over all iterations + iterationCounter = 0; + while(iterationCounter < testIterations) + { + iterationCounter++; + + if (userExecKey != 0) { + execKey = userExecKey; + } else { + execKey = SDLTest_GenerateExecKey(runSeed, testSuite->name, testCase->name, iterationCounter); + } + + SDLTest_Log("Test Iteration %i: execKey %llu", iterationCounter, execKey); + testResult = SDLTest_RunTest(testSuite, testCase, execKey); + + if (testResult == TEST_RESULT_PASSED) { + testPassedCount++; + totalTestPassedCount++; + } else if (testResult == TEST_RESULT_SKIPPED) { + testSkippedCount++; + totalTestSkippedCount++; + } else { + testFailedCount++; + totalTestFailedCount++; + } + } + + // Take time - test end + testEndSeconds = GetClock(); + runtime = testEndSeconds - testStartSeconds; + if (runtime < 0.0f) runtime = 0.0f; + + if (testIterations > 1) { + // Log test runtime + SDLTest_Log("Runtime of %i iterations: %.1f sec", testIterations, runtime); + SDLTest_Log("Average Test runtime: %.5f sec", runtime / (float)testIterations); + } else { + // Log test runtime + SDLTest_Log("Total Test runtime: %.1f sec", runtime); + } + + // Log final test result + switch (testResult) { + case TEST_RESULT_PASSED: + SDLTest_Log((char *)SDLTest_FinalResultFormat, "Test", currentTestName, "Passed"); + break; + case TEST_RESULT_FAILED: + SDLTest_LogError((char *)SDLTest_FinalResultFormat, "Test", currentTestName, "Failed"); + break; + case TEST_RESULT_NO_ASSERT: + SDLTest_LogError((char *)SDLTest_FinalResultFormat,"Test", currentTestName, "No Asserts"); + break; + } - if (testResult == TEST_RESULT_PASSED) { - testPassedCount++; - totalTestPassedCount++; - } else if (testResult == TEST_RESULT_SKIPPED) { - testSkippedCount++; - totalTestSkippedCount++; - } else { - testFailedCount++; - totalTestFailedCount++; } } - // Take time - test end - testEndSeconds = GetClock(); - runtime = testEndSeconds - testStartSeconds; + // Take time - suite end + suiteEndSeconds = GetClock(); + runtime = suiteEndSeconds - suiteStartSeconds; if (runtime < 0.0f) runtime = 0.0f; - if (testIterations > 1) { - // Log test runtime - SDLTest_Log("Runtime of %i iterations: %.1f sec", testIterations, runtime); - SDLTest_Log("Test runtime: %.5f sec", runtime / (float)testIterations); - } else { - // Log test runtime - SDLTest_Log("Test runtime: %.1f sec", runtime); - } - - // Log final test result - switch (testResult) { - case TEST_RESULT_PASSED: - SDLTest_Log((char *)SDLTest_FinalResultFormat, "Test", currentTestName, "Passed"); - break; - case TEST_RESULT_FAILED: - SDLTest_LogError((char *)SDLTest_FinalResultFormat, "Test", currentTestName, "Failed"); - break; - case TEST_RESULT_NO_ASSERT: - SDLTest_LogError((char *)SDLTest_FinalResultFormat,"Test", currentTestName, "No Asserts"); - break; - } - } - - // Take time - suite end - suiteEndSeconds = GetClock(); - runtime = suiteEndSeconds - suiteStartSeconds; - if (runtime < 0.0f) runtime = 0.0f; + // Log suite runtime + SDLTest_Log("Total Suite runtime: %.1f sec", runtime); - // Log suite runtime - SDLTest_Log("Suite runtime: %.1f sec", runtime); + // Log summary and final Suite result + countSum = testPassedCount + testFailedCount + testSkippedCount; + if (testFailedCount == 0) + { + SDLTest_Log(logFormat, "Suite", countSum, testPassedCount, testFailedCount, testSkippedCount); + SDLTest_Log((char *)SDLTest_FinalResultFormat, "Suite", currentSuiteName, "Passed"); + } + else + { + SDLTest_LogError(logFormat, "Suite", countSum, testPassedCount, testFailedCount, testSkippedCount); + SDLTest_LogError((char *)SDLTest_FinalResultFormat, "Suite", currentSuiteName, "Failed"); + } - // Log summary and final Suite result - countSum = testPassedCount + testFailedCount + testSkippedCount; - if (testFailedCount == 0) - { - SDLTest_Log(logFormat, "Suite", countSum, testPassedCount, testFailedCount, testSkippedCount); - SDLTest_Log((char *)SDLTest_FinalResultFormat, "Suite", currentSuiteName, "Passed"); - } - else - { - SDLTest_LogError(logFormat, "Suite", countSum, testPassedCount, testFailedCount, testSkippedCount); - SDLTest_LogError((char *)SDLTest_FinalResultFormat, "Suite", currentSuiteName, "Failed"); } } @@ -505,11 +581,11 @@ SDLTest_RunSuites(SDLTest_TestSuiteReference *testSuites[], char *userRunSeed, U if (runtime < 0.0f) runtime = 0.0f; // Log total runtime - SDLTest_Log("Total runtime: %.1f sec", runtime); + SDLTest_Log("Total Run runtime: %.1f sec", runtime); // Log summary and final run result countSum = totalTestPassedCount + totalTestFailedCount + totalTestSkippedCount; - if (testFailedCount == 0) + if (totalTestFailedCount == 0) { runResult = 0; SDLTest_Log(logFormat, "Run", countSum, totalTestPassedCount, totalTestFailedCount, totalTestSkippedCount); diff --git a/src/test/SDL_test_imageBlit.c b/src/test/SDL_test_imageBlit.c index 27a7313aa..e2abaa06a 100644 --- a/src/test/SDL_test_imageBlit.c +++ b/src/test/SDL_test_imageBlit.c @@ -535,6 +535,32 @@ const SDLTest_SurfaceImage_t SDLTest_imageBlit = { "\0\0", }; +/** + * \brief Returns the Blit test image as SDL_Surface. + */ +SDL_Surface *SDLTest_ImageBlit() +{ + SDL_Surface *surface = SDL_CreateRGBSurfaceFrom( + (void*)SDLTest_imageBlit.pixel_data, + SDLTest_imageBlit.width, + SDLTest_imageBlit.height, + SDLTest_imageBlit.bytes_per_pixel * 8, + SDLTest_imageBlit.width * SDLTest_imageBlit.bytes_per_pixel, +#if (SDL_BYTEORDER == SDL_BIG_ENDIAN) + 0xff000000, /* Red bit mask. */ + 0x00ff0000, /* Green bit mask. */ + 0x0000ff00, /* Blue bit mask. */ + 0x000000ff /* Alpha bit mask. */ +#else + 0x000000ff, /* Red bit mask. */ + 0x0000ff00, /* Green bit mask. */ + 0x00ff0000, /* Blue bit mask. */ + 0xff000000 /* Alpha bit mask. */ +#endif + ); + return surface; +} + const SDLTest_SurfaceImage_t SDLTest_imageBlitColor = { 80, 60, 3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" @@ -992,6 +1018,32 @@ const SDLTest_SurfaceImage_t SDLTest_imageBlitColor = { "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", }; +/** + * \brief Returns the BlitColor test image as SDL_Surface. + */ +SDL_Surface *SDLTest_ImageBlitColor() +{ + SDL_Surface *surface = SDL_CreateRGBSurfaceFrom( + (void*)SDLTest_imageBlitColor.pixel_data, + SDLTest_imageBlitColor.width, + SDLTest_imageBlitColor.height, + SDLTest_imageBlitColor.bytes_per_pixel * 8, + SDLTest_imageBlitColor.width * SDLTest_imageBlitColor.bytes_per_pixel, +#if (SDL_BYTEORDER == SDL_BIG_ENDIAN) + 0xff000000, /* Red bit mask. */ + 0x00ff0000, /* Green bit mask. */ + 0x0000ff00, /* Blue bit mask. */ + 0x000000ff /* Alpha bit mask. */ +#else + 0x000000ff, /* Red bit mask. */ + 0x0000ff00, /* Green bit mask. */ + 0x00ff0000, /* Blue bit mask. */ + 0xff000000 /* Alpha bit mask. */ +#endif + ); + return surface; +} + const SDLTest_SurfaceImage_t SDLTest_imageBlitAlpha = { 80, 60, 3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" @@ -1478,3 +1530,28 @@ const SDLTest_SurfaceImage_t SDLTest_imageBlitAlpha = { "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", }; +/** + * \brief Returns the BlitAlpha test image as SDL_Surface. + */ +SDL_Surface *SDLTest_ImageBlitAlpha() +{ + SDL_Surface *surface = SDL_CreateRGBSurfaceFrom( + (void*)SDLTest_imageBlitAlpha.pixel_data, + SDLTest_imageBlitAlpha.width, + SDLTest_imageBlitAlpha.height, + SDLTest_imageBlitAlpha.bytes_per_pixel * 8, + SDLTest_imageBlitAlpha.width * SDLTest_imageBlitAlpha.bytes_per_pixel, +#if (SDL_BYTEORDER == SDL_BIG_ENDIAN) + 0xff000000, /* Red bit mask. */ + 0x00ff0000, /* Green bit mask. */ + 0x0000ff00, /* Blue bit mask. */ + 0x000000ff /* Alpha bit mask. */ +#else + 0x000000ff, /* Red bit mask. */ + 0x0000ff00, /* Green bit mask. */ + 0x00ff0000, /* Blue bit mask. */ + 0xff000000 /* Alpha bit mask. */ +#endif + ); + return surface; +} diff --git a/src/test/SDL_test_imageBlitBlend.c b/src/test/SDL_test_imageBlitBlend.c index 179eb20af..617687652 100644 --- a/src/test/SDL_test_imageBlitBlend.c +++ b/src/test/SDL_test_imageBlitBlend.c @@ -575,6 +575,32 @@ const SDLTest_SurfaceImage_t SDLTest_imageBlitBlendAdd = { "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", }; +/** + * \brief Returns the BlitBlendAdd test image as SDL_Surface. + */ +SDL_Surface *SDLTest_ImageBlitBlendAdd() +{ + SDL_Surface *surface = SDL_CreateRGBSurfaceFrom( + (void*)SDLTest_imageBlitBlendAdd.pixel_data, + SDLTest_imageBlitBlendAdd.width, + SDLTest_imageBlitBlendAdd.height, + SDLTest_imageBlitBlendAdd.bytes_per_pixel * 8, + SDLTest_imageBlitBlendAdd.width * SDLTest_imageBlitBlendAdd.bytes_per_pixel, +#if (SDL_BYTEORDER == SDL_BIG_ENDIAN) + 0xff000000, /* Red bit mask. */ + 0x00ff0000, /* Green bit mask. */ + 0x0000ff00, /* Blue bit mask. */ + 0x000000ff /* Alpha bit mask. */ +#else + 0x000000ff, /* Red bit mask. */ + 0x0000ff00, /* Green bit mask. */ + 0x00ff0000, /* Blue bit mask. */ + 0xff000000 /* Alpha bit mask. */ +#endif + ); + return surface; +} + const SDLTest_SurfaceImage_t SDLTest_imageBlitBlend = { 80, 60, 3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" @@ -1079,6 +1105,32 @@ const SDLTest_SurfaceImage_t SDLTest_imageBlitBlend = { "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", }; +/** + * \brief Returns the BlitBlend test image as SDL_Surface. + */ +SDL_Surface *SDLTest_ImageBlitBlend() +{ + SDL_Surface *surface = SDL_CreateRGBSurfaceFrom( + (void*)SDLTest_imageBlitBlend.pixel_data, + SDLTest_imageBlitBlend.width, + SDLTest_imageBlitBlend.height, + SDLTest_imageBlitBlend.bytes_per_pixel * 8, + SDLTest_imageBlitBlend.width * SDLTest_imageBlitBlend.bytes_per_pixel, +#if (SDL_BYTEORDER == SDL_BIG_ENDIAN) + 0xff000000, /* Red bit mask. */ + 0x00ff0000, /* Green bit mask. */ + 0x0000ff00, /* Blue bit mask. */ + 0x000000ff /* Alpha bit mask. */ +#else + 0x000000ff, /* Red bit mask. */ + 0x0000ff00, /* Green bit mask. */ + 0x00ff0000, /* Blue bit mask. */ + 0xff000000 /* Alpha bit mask. */ +#endif + ); + return surface; +} + const SDLTest_SurfaceImage_t SDLTest_imageBlitBlendMod = { 80, 60, 3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" @@ -1483,6 +1535,32 @@ const SDLTest_SurfaceImage_t SDLTest_imageBlitBlendMod = { "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", }; +/** + * \brief Returns the BlitBlendMod test image as SDL_Surface. + */ +SDL_Surface *SDLTest_ImageBlitBlendMod() +{ + SDL_Surface *surface = SDL_CreateRGBSurfaceFrom( + (void*)SDLTest_imageBlitBlendMod.pixel_data, + SDLTest_imageBlitBlendMod.width, + SDLTest_imageBlitBlendMod.height, + SDLTest_imageBlitBlendMod.bytes_per_pixel * 8, + SDLTest_imageBlitBlendMod.width * SDLTest_imageBlitBlendMod.bytes_per_pixel, +#if (SDL_BYTEORDER == SDL_BIG_ENDIAN) + 0xff000000, /* Red bit mask. */ + 0x00ff0000, /* Green bit mask. */ + 0x0000ff00, /* Blue bit mask. */ + 0x000000ff /* Alpha bit mask. */ +#else + 0x000000ff, /* Red bit mask. */ + 0x0000ff00, /* Green bit mask. */ + 0x00ff0000, /* Blue bit mask. */ + 0xff000000 /* Alpha bit mask. */ +#endif + ); + return surface; +} + const SDLTest_SurfaceImage_t SDLTest_imageBlitBlendNone = { 80, 60, 3, "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377" @@ -2270,6 +2348,32 @@ const SDLTest_SurfaceImage_t SDLTest_imageBlitBlendNone = { "\377\377\377\377\377\377\377\377", }; +/** + * \brief Returns the BlitBlendNone test image as SDL_Surface. + */ +SDL_Surface *SDLTest_ImageBlitBlendNone() +{ + SDL_Surface *surface = SDL_CreateRGBSurfaceFrom( + (void*)SDLTest_imageBlitBlendNone.pixel_data, + SDLTest_imageBlitBlendNone.width, + SDLTest_imageBlitBlendNone.height, + SDLTest_imageBlitBlendNone.bytes_per_pixel * 8, + SDLTest_imageBlitBlendNone.width * SDLTest_imageBlitBlendNone.bytes_per_pixel, +#if (SDL_BYTEORDER == SDL_BIG_ENDIAN) + 0xff000000, /* Red bit mask. */ + 0x00ff0000, /* Green bit mask. */ + 0x0000ff00, /* Blue bit mask. */ + 0x000000ff /* Alpha bit mask. */ +#else + 0x000000ff, /* Red bit mask. */ + 0x0000ff00, /* Green bit mask. */ + 0x00ff0000, /* Blue bit mask. */ + 0xff000000 /* Alpha bit mask. */ +#endif + ); + return surface; +} + const SDLTest_SurfaceImage_t SDLTest_imageBlitBlendAll = { 80, 60, 3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" @@ -2712,3 +2816,28 @@ const SDLTest_SurfaceImage_t SDLTest_imageBlitBlendAll = { "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", }; +/** + * \brief Returns the BlitBlendAll test image as SDL_Surface. + */ +SDL_Surface *SDLTest_ImageBlitBlendAll() +{ + SDL_Surface *surface = SDL_CreateRGBSurfaceFrom( + (void*)SDLTest_imageBlitBlendAll.pixel_data, + SDLTest_imageBlitBlendAll.width, + SDLTest_imageBlitBlendAll.height, + SDLTest_imageBlitBlendAll.bytes_per_pixel * 8, + SDLTest_imageBlitBlendAll.width * SDLTest_imageBlitBlendAll.bytes_per_pixel, +#if (SDL_BYTEORDER == SDL_BIG_ENDIAN) + 0xff000000, /* Red bit mask. */ + 0x00ff0000, /* Green bit mask. */ + 0x0000ff00, /* Blue bit mask. */ + 0x000000ff /* Alpha bit mask. */ +#else + 0x000000ff, /* Red bit mask. */ + 0x0000ff00, /* Green bit mask. */ + 0x00ff0000, /* Blue bit mask. */ + 0xff000000 /* Alpha bit mask. */ +#endif + ); + return surface; +} diff --git a/src/test/SDL_test_imageFace.c b/src/test/SDL_test_imageFace.c index bb10080e5..f43b11fe9 100644 --- a/src/test/SDL_test_imageFace.c +++ b/src/test/SDL_test_imageFace.c @@ -24,7 +24,7 @@ /* GIMP RGBA C-Source image dump (face.c) */ -const SDLTest_SurfaceImage_t SDLTest_ImageFace = { +const SDLTest_SurfaceImage_t SDLTest_imageFace = { 32, 32, 4, "\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377" "\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377\377\0\377\377" @@ -218,3 +218,29 @@ const SDLTest_SurfaceImage_t SDLTest_ImageFace = { "\377\377\0\377\377\377\0", }; +/** + * \brief Returns the Face test image as SDL_Surface. + */ +SDL_Surface *SDLTest_ImageFace() +{ + SDL_Surface *surface = SDL_CreateRGBSurfaceFrom( + (void*)SDLTest_imageFace.pixel_data, + SDLTest_imageFace.width, + SDLTest_imageFace.height, + SDLTest_imageFace.bytes_per_pixel * 8, + SDLTest_imageFace.width * SDLTest_imageFace.bytes_per_pixel, +#if (SDL_BYTEORDER == SDL_BIG_ENDIAN) + 0xff000000, /* Red bit mask. */ + 0x00ff0000, /* Green bit mask. */ + 0x0000ff00, /* Blue bit mask. */ + 0x000000ff /* Alpha bit mask. */ +#else + 0x000000ff, /* Red bit mask. */ + 0x0000ff00, /* Green bit mask. */ + 0x00ff0000, /* Blue bit mask. */ + 0xff000000 /* Alpha bit mask. */ +#endif + ); + return surface; +} + diff --git a/src/test/SDL_test_imagePrimitives.c b/src/test/SDL_test_imagePrimitives.c index 46233ed13..3fb539787 100644 --- a/src/test/SDL_test_imagePrimitives.c +++ b/src/test/SDL_test_imagePrimitives.c @@ -485,3 +485,28 @@ const SDLTest_SurfaceImage_t SDLTest_imagePrimitives = { "\310\15I\310\15I\310\15I\310\15I\310\5ii", }; +/** + * \brief Returns the Primitives test image as SDL_Surface. + */ +SDL_Surface *SDLTest_ImagePrimitives() +{ + SDL_Surface *surface = SDL_CreateRGBSurfaceFrom( + (void*)SDLTest_imagePrimitives.pixel_data, + SDLTest_imagePrimitives.width, + SDLTest_imagePrimitives.height, + SDLTest_imagePrimitives.bytes_per_pixel * 8, + SDLTest_imagePrimitives.width * SDLTest_imagePrimitives.bytes_per_pixel, +#if (SDL_BYTEORDER == SDL_BIG_ENDIAN) + 0xff000000, /* Red bit mask. */ + 0x00ff0000, /* Green bit mask. */ + 0x0000ff00, /* Blue bit mask. */ + 0x000000ff /* Alpha bit mask. */ +#else + 0x000000ff, /* Red bit mask. */ + 0x0000ff00, /* Green bit mask. */ + 0x00ff0000, /* Blue bit mask. */ + 0xff000000 /* Alpha bit mask. */ +#endif + ); + return surface; +} diff --git a/src/test/SDL_test_imagePrimitivesBlend.c b/src/test/SDL_test_imagePrimitivesBlend.c index 3e41a7fe1..b00cd287d 100644 --- a/src/test/SDL_test_imagePrimitivesBlend.c +++ b/src/test/SDL_test_imagePrimitivesBlend.c @@ -667,3 +667,28 @@ const SDLTest_SurfaceImage_t SDLTest_imagePrimitivesBlend = { "\377\377\377\377\377\377\377\377\324X2\377\377\377\333bB\377\377\377", }; +/** + * \brief Returns the PrimitivesBlend test image as SDL_Surface. + */ +SDL_Surface *SDLTest_ImagePrimitivesBlend() +{ + SDL_Surface *surface = SDL_CreateRGBSurfaceFrom( + (void*)SDLTest_imagePrimitivesBlend.pixel_data, + SDLTest_imagePrimitivesBlend.width, + SDLTest_imagePrimitivesBlend.height, + SDLTest_imagePrimitivesBlend.bytes_per_pixel * 8, + SDLTest_imagePrimitivesBlend.width * SDLTest_imagePrimitivesBlend.bytes_per_pixel, +#if (SDL_BYTEORDER == SDL_BIG_ENDIAN) + 0xff000000, /* Red bit mask. */ + 0x00ff0000, /* Green bit mask. */ + 0x0000ff00, /* Blue bit mask. */ + 0x000000ff /* Alpha bit mask. */ +#else + 0x000000ff, /* Red bit mask. */ + 0x0000ff00, /* Green bit mask. */ + 0x00ff0000, /* Blue bit mask. */ + 0xff000000 /* Alpha bit mask. */ +#endif + ); + return surface; +} diff --git a/test/testautomation.c b/test/testautomation.c index eba8029a3..5c1d68186 100644 --- a/test/testautomation.c +++ b/test/testautomation.c @@ -37,6 +37,7 @@ main(int argc, char *argv[]) int testIterations = 1; Uint64 userExecKey = 0; char *userRunSeed = NULL; + char *filter = NULL; int i; /* Initialize test framework */ @@ -74,6 +75,12 @@ main(int argc, char *argv[]) consumed = 2; } } + else if (SDL_strcasecmp(argv[i], "--filter") == 0) { + if (argv[i + 1]) { + filter = SDL_strdup(argv[i + 1]); + consumed = 2; + } + } } if (consumed < 0) { fprintf(stderr, @@ -98,12 +105,15 @@ main(int argc, char *argv[]) } /* Call Harness */ - result = SDLTest_RunSuites(testSuites, userRunSeed, userExecKey, testIterations); + result = SDLTest_RunSuites(testSuites, userRunSeed, userExecKey, filter, testIterations); /* Clean up */ if (userRunSeed != NULL) { SDL_free(userRunSeed); } + if (filter != NULL) { + SDL_free(filter); + } /* Shutdown everything */ quit(result); diff --git a/test/tests/testrender.c b/test/tests/testrender.c new file mode 100644 index 000000000..665c3f36e --- /dev/null +++ b/test/tests/testrender.c @@ -0,0 +1,1025 @@ +/** + * Original code: automated SDL platform test written by Edgar Simo "bobbens" + * Extended and extensively updated by aschiffler at ferzkopp dot net + */ + +#include + +#include "SDL.h" +#include "SDL_test.h" + +/* ================= Test Case Implementation ================== */ + +#define TESTRENDER_SCREEN_W 80 +#define TESTRENDER_SCREEN_H 60 + +#define RENDER_COMPARE_FORMAT SDL_PIXELFORMAT_ARGB8888 +#define RENDER_COMPARE_AMASK 0xff000000 /**< Alpha bit mask. */ +#define RENDER_COMPARE_RMASK 0x00ff0000 /**< Red bit mask. */ +#define RENDER_COMPARE_GMASK 0x0000ff00 /**< Green bit mask. */ +#define RENDER_COMPARE_BMASK 0x000000ff /**< Blue bit mask. */ + +#define ALLOWABLE_ERROR_OPAQUE 0 +#define ALLOWABLE_ERROR_BLENDED 64 + +SDL_Window *window = NULL; +SDL_Renderer *renderer = NULL; + +/* Prototypes for helper functions */ + +static int _clearScreen (void); +static void _compare(const char *msg, SDL_Surface *s, int allowable_error); +static int _hasTexAlpha(void); +static int _hasTexColor(void); +static SDL_Texture *_loadTestFace(void); +static int _hasBlendModes(void); +static int _hasDrawColor(void); +static int _isSupported(int code); + +/** + * Create software renderer for tests + */ +void InitCreateRenderer(void *arg) +{ + int posX = 100, posY = 100, width = 320, height = 240; + renderer = NULL; + window = SDL_CreateWindow("render_testCreateRenderer", posX, posY, width, height, 0); + SDLTest_AssertPass("SDL_CreateWindow()"); + SDLTest_AssertCheck(window != NULL, "Check SDL_CreateWindow result"); + if (window == NULL) { + return; + } + + renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); + SDLTest_AssertPass("SDL_CreateRenderer()"); + SDLTest_AssertCheck(renderer != 0, "Check SDL_CreateRenderer result"); + if (renderer == 0) { + SDL_DestroyWindow(window); + return; + } +} + +/* + * Destroy renderer for tests + */ +void CleanupDestroyRenderer(void *arg) +{ + if (renderer != NULL) { + SDL_DestroyRenderer(renderer); + SDLTest_AssertPass("SDL_DestroyRenderer()"); + } + + if (window != NULL) { + SDL_DestroyWindow(window); + SDLTest_AssertPass("SDL_DestroyWindow"); + } +} + + +/** + * @brief Tests call to SDL_GetNumRenderDrivers + * + * \sa + * http://wiki.libsdl.org/moin.cgi/SDL_GetNumRenderDrivers + */ +int +render_testGetNumRenderDrivers(void *arg) +{ + int n; + n = SDL_GetNumRenderDrivers(); + SDLTest_AssertCheck(n >= 1, "Number of renderers >= 1, reported as %i", n); + return TEST_COMPLETED; +} + + +/** + * @brief Tests the SDL primitives for rendering. + * + * \sa + * http://wiki.libsdl.org/moin.cgi/SDL_SetRenderDrawColor + * http://wiki.libsdl.org/moin.cgi/SDL_RenderFillRect + * http://wiki.libsdl.org/moin.cgi/SDL_RenderDrawLine + * + */ +int render_testPrimitives (void *arg) +{ + int ret; + int x, y; + SDL_Rect rect; + int checkFailCount1; + int checkFailCount2; + + /* Need drawcolour or just skip test. */ + SDLTest_AssertCheck(_hasDrawColor(), "_hasDrawColor"); + + /* Draw a rectangle. */ + rect.x = 40; + rect.y = 0; + rect.w = 40; + rect.h = 80; + + ret = SDL_SetRenderDrawColor(renderer, 13, 73, 200, SDL_ALPHA_OPAQUE ); + SDLTest_AssertCheck(ret == 0, "Validate result from SDL_SetRenderDrawColor, expected: 0, got: %i", ret); + + ret = SDL_RenderFillRect(renderer, &rect ); + SDLTest_AssertCheck(ret == 0, "Validate result from SDL_RenderFillRect, expected: 0, got: %i", ret); + + /* Draw a rectangle. */ + rect.x = 10; + rect.y = 10; + rect.w = 60; + rect.h = 40; + ret = SDL_SetRenderDrawColor(renderer, 200, 0, 100, SDL_ALPHA_OPAQUE ); + SDLTest_AssertCheck(ret == 0, "Validate result from SDL_SetRenderDrawColor, expected: 0, got: %i", ret); + + ret = SDL_RenderFillRect(renderer, &rect ); + SDLTest_AssertCheck(ret == 0, "Validate result from SDL_RenderFillRect, expected: 0, got: %i", ret); + + /* Draw some points like so: + * X.X.X.X.. + * .X.X.X.X. + * X.X.X.X.. */ + checkFailCount1 = 0; + checkFailCount2 = 0; + for (y=0; y<3; y++) { + for (x = y % 2; x