This repository has been archived by the owner. It is now read-only.
Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
with
621 additions
and 3 deletions.
- +4 −2 include/SDL_log.h
- +3 −0 include/SDL_test.h
- +83 −0 include/SDL_test_assert.h
- +116 −0 include/SDL_test_harness.h
- +71 −0 include/SDL_test_log.h
- +6 −1 src/SDL_log.c
- +96 −0 src/test/SDL_test_assert.c
- +142 −0 src/test/SDL_test_harness.c
- +100 −0 src/test/SDL_test_log.c
@@ -0,0 +1,83 @@ | ||
/* | ||
Simple DirectMedia Layer | ||
Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org> | ||
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_assert.h | ||
* | ||
* Include file for SDL test framework. | ||
* | ||
* This code is a part of the SDL2_test library, not the main SDL library. | ||
*/ | ||
|
||
/* | ||
* | ||
* Assert API for test code and test cases | ||
* | ||
*/ | ||
|
||
#ifndef _SDL_test_assert_h | ||
#define _SDL_test_assert_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 Assert that logs and break execution flow on failures. | ||
* | ||
* \param assertCondition Evaluated condition or variable to assert; fail (==0) or pass (!=0). | ||
* \param assertDescription Message to log with the assert describing it. | ||
*/ | ||
void SDLTest_Assert(int assertCondition, char *assertDescription); | ||
|
||
/** | ||
* \brief Assert for test cases that logs but does not break execution flow on failures. | ||
* | ||
* \param assertCondition Evaluated condition or variable to assert; fail (==0) or pass (!=0). | ||
* \param assertDescription Message to log with the assert describing it. | ||
*/ | ||
void SDLTest_AssertCheck(int assertCondition, char *assertDescription); | ||
|
||
/** | ||
* \brief Resets the assert summary counters to zero. | ||
*/ | ||
void SDLTest_ResetAssertSummary(); | ||
|
||
/** | ||
* \brief Logs summary of all assertions (total, pass, fail) since last reset as INFO or ERROR. | ||
* | ||
*/ | ||
void SDLTest_LogAssertSummary(); | ||
|
||
#ifdef __cplusplus | ||
/* *INDENT-OFF* */ | ||
} | ||
/* *INDENT-ON* */ | ||
#endif | ||
#include "close_code.h" | ||
|
||
#endif /* _SDL_test_assert_h */ | ||
|
||
/* vi: set ts=4 sw=4 expandtab: */ |
@@ -0,0 +1,116 @@ | ||
/* | ||
Simple DirectMedia Layer | ||
Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org> | ||
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_harness.h | ||
* | ||
* Include file for SDL test framework. | ||
* | ||
* This code is a part of the SDL2_test library, not the main SDL library. | ||
*/ | ||
|
||
/* | ||
Defines types for test case definitions and the test execution harness API. | ||
Based on original GSOC code by Markus Kauppila <markus.kauppila@gmail.com> | ||
*/ | ||
|
||
#ifndef _SDL_test_harness_h | ||
#define _SDL_test_harness_h | ||
|
||
#include "begin_code.h" | ||
/* Set up for C function definitions, even when using C++ */ | ||
#ifdef __cplusplus | ||
/* *INDENT-OFF* */ | ||
extern "C" { | ||
/* *INDENT-ON* */ | ||
#endif | ||
|
||
|
||
//! Definitions for test case structures | ||
#define TEST_ENABLED 1 | ||
#define TEST_DISABLED 0 | ||
|
||
//! Definitions of assert results | ||
#define ASSERT_PASS 1 | ||
#define ASSERT_FAIL 0 | ||
|
||
//! Definition of all the possible test return values of the test case method | ||
#define TEST_ABORTED -1 | ||
#define TEST_COMPLETED 0 | ||
#define TEST_SKIPPED 1 | ||
|
||
//! Definition of all the possible test results for the harness | ||
#define TEST_RESULT_PASSED 0 | ||
#define TEST_RESULT_FAILED 1 | ||
#define TEST_RESULT_NO_ASSERT 2 | ||
#define TEST_RESULT_SKIPPED 3 | ||
#define TEST_RESULT_KILLED 4 | ||
#define TEST_RESULT_SETUP_FAILURE 5 | ||
|
||
//!< Function pointer to a test case setup function (run before every test) | ||
typedef void (*SDLTest_TestCaseSetUpFp)(void *arg); | ||
|
||
//!< Function pointer to a test case function | ||
typedef void (*SDLTest_TestCaseFp)(void *arg); | ||
|
||
//!< Function pointer to a test case teardown function (run after every test) | ||
typedef void (*SDLTest_TestCaseTearDownFp)(void *arg); | ||
|
||
/** | ||
* Holds information about a single test case. | ||
*/ | ||
typedef struct SDLTest_TestCaseReference { | ||
/*!< Func2Stress */ | ||
SDLTest_TestCaseFp testCase; | ||
/*!< Short name (or function name) "Func2Stress" */ | ||
char *name; | ||
/*!< Long name or full description "This test pushes func2() to the limit." */ | ||
char *description; | ||
/*!< Set to TEST_ENABLED or TEST_DISABLED (test won't be run) */ | ||
int enabled; | ||
} SDLTest_TestCaseReference; | ||
|
||
/** | ||
* Holds information about a test suite (multiple test cases). | ||
*/ | ||
typedef struct TestSuiteReference { | ||
/*!< "PlatformSuite" */ | ||
char *name; | ||
/*!< The function that is run before each test. NULL skips. */ | ||
SDLTest_TestCaseSetUpFp testSetUp; | ||
/*!< The test cases that are run as part of the suite. Last item should be NULL. */ | ||
const SDLTest_TestCaseReference **testCases; | ||
/*!< The function that is run after each test. NULL skips. */ | ||
SDLTest_TestCaseTearDownFp testTearDown; | ||
} TestSuiteReference; | ||
|
||
/* Ends C function definitions when using C++ */ | ||
#ifdef __cplusplus | ||
/* *INDENT-OFF* */ | ||
} | ||
/* *INDENT-ON* */ | ||
#endif | ||
#include "close_code.h" | ||
|
||
#endif /* _SDL_test_harness_h */ | ||
|
||
/* vi: set ts=4 sw=4 expandtab: */ |
@@ -0,0 +1,71 @@ | ||
/* | ||
Simple DirectMedia Layer | ||
Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org> | ||
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_log.h | ||
* | ||
* Include file for SDL test framework. | ||
* | ||
* This code is a part of the SDL2_test library, not the main SDL library. | ||
*/ | ||
|
||
/* | ||
* | ||
* Wrapper to log in the TEST category | ||
* | ||
*/ | ||
|
||
#ifndef _SDL_test_log_h | ||
#define _SDL_test_log_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 Prints given message with a timestamp in the TEST category and INFO priority. | ||
* | ||
* \param fmt Message to be logged | ||
*/ | ||
void SDLTest_Log(char *fmt, ...); | ||
|
||
/** | ||
* \brief Prints given message with a timestamp in the TEST category and the ERROR priority. | ||
* | ||
* \param fmt Message to be logged | ||
*/ | ||
void SDLTest_LogError(char *fmt, ...); | ||
|
||
/* Ends C function definitions when using C++ */ | ||
#ifdef __cplusplus | ||
/* *INDENT-OFF* */ | ||
} | ||
/* *INDENT-ON* */ | ||
#endif | ||
#include "close_code.h" | ||
|
||
#endif /* _SDL_test_log_h */ | ||
|
||
/* vi: set ts=4 sw=4 expandtab: */ |
Oops, something went wrong.