Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libSDL
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PocketInsanity
libSDL
Commits
6d3454e1
Commit
6d3454e1
authored
Jul 11, 2011
by
Markus Kauppila
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
If any assert in SetUp function fails that test will be skipped.
parent
3efe0fed
Changes
11
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
377 additions
and
293 deletions
+377
-293
SDL_test.c
test/test-automation/SDL_test.c
+7
-2
SDL_test.h
test/test-automation/SDL_test.h
+16
-6
logger.h
test/test-automation/logger.h
+1
-1
plain_logger.c
test/test-automation/plain_logger.c
+7
-3
plain_logger.h
test/test-automation/plain_logger.h
+1
-1
runner.c
test/test-automation/runner.c
+289
-241
style.xsl
test/test-automation/style.xsl
+5
-0
testdummy.c
test/test-automation/testdummy/testdummy.c
+3
-0
testsurface.c
test/test-automation/testsurface/testsurface.c
+31
-36
xml_logger.c
test/test-automation/xml_logger.c
+16
-2
xml_logger.h
test/test-automation/xml_logger.h
+1
-1
No files found.
test/test-automation/SDL_test.c
View file @
6d3454e1
...
...
@@ -36,7 +36,7 @@ int _testAssertsFailed;
int
_testAssertsPassed
;
void
_InitTestEnvironment
()
// InitTestEnvironment
_InitTestEnvironment
()
{
_testReturnValue
=
0
;
_testAssertsFailed
=
0
;
...
...
@@ -56,8 +56,13 @@ _QuitTestEnvironment()
return
_testReturnValue
;
}
int
_CountFailedAsserts
()
{
return
_testAssertsFailed
;
}
void
AssertEquals
(
const
int
expected
,
const
int
actual
,
char
*
message
,
...)
AssertEquals
(
int
expected
,
int
actual
,
char
*
message
,
...)
{
va_list
args
;
char
buf
[
256
];
...
...
test/test-automation/SDL_test.h
View file @
6d3454e1
...
...
@@ -69,13 +69,19 @@ void _InitTestEnvironment();
*/
int
_QuitTestEnvironment
();
/*!
* Can be used to query the number of failed asserts
* \return Returns the failed assert count.
*/
int
_CountFailedAsserts
();
/*!
* Assert function. Tests if the expected value equals the actual value, then
* the test assert succeeds, otherwise it fails and warns about it.
*
* \param expected Value user expects to have
* \param actual The actual value of tested variable
* \param message Message that will be printed
if assert fails
* \param message Message that will be printed
*/
void
AssertEquals
(
const
int
expected
,
const
int
actual
,
char
*
message
,
...);
...
...
@@ -85,18 +91,22 @@ void AssertEquals(const int expected, const int actual, char *message, ...);
* assert passes, otherwise it fails.
*
* \param condition Condition which will be evaluated
* \param message Message that will be printed
if assert fails
* \param message Message that will be printed
*/
void
AssertTrue
(
int
condition
,
char
*
message
,
...);
/*!
\todo add markup
*/
* Assert function which will always fail
*
* \param message Message that will be printed
*/
void
AssertFail
(
char
*
message
,
...);
/*!
\todo add markup
*/
* Assert function which will always pass
*
* \param message Message that will be printed
*/
void
AssertPass
(
char
*
message
,
...);
#endif
test/test-automation/logger.h
View file @
6d3454e1
...
...
@@ -30,7 +30,7 @@
*/
typedef
void
(
*
RunStartedFp
)(
int
parameterCount
,
char
*
runnerParameters
[],
time_t
eventTime
,
void
*
data
);
typedef
void
(
*
RunEndedFp
)(
int
testCount
,
int
suiteCount
,
int
testPassCount
,
int
testFailCount
,
time_t
endTime
,
double
totalRuntime
);
int
testSkippedCount
,
time_t
endTime
,
double
totalRuntime
);
typedef
void
(
*
SuiteStartedFp
)(
const
char
*
suiteName
,
time_t
eventTime
);
typedef
void
(
*
SuiteEndedFp
)(
int
testsPassed
,
int
testsFailed
,
int
testsSkipped
,
...
...
test/test-automation/plain_logger.c
View file @
6d3454e1
...
...
@@ -54,13 +54,14 @@ PlainRunStarted(int parameterCount, char *runnerParameters[], time_t eventTime,
void
PlainRunEnded
(
int
testCount
,
int
suiteCount
,
int
testPassCount
,
int
testFailCount
,
time_t
endTime
,
double
totalRuntime
)
int
testSkippedCount
,
time_t
endTime
,
double
totalRuntime
)
{
Output
(
indentLevel
,
"Ran %d tests in %0.5f seconds from %d suites."
,
testCount
,
totalRuntime
,
suiteCount
);
Output
(
indentLevel
,
"%d tests passed"
,
testPassCount
);
Output
(
indentLevel
,
"%d tests failed"
,
testFailCount
);
Output
(
indentLevel
,
"%d tests skipped"
,
testSkippedCount
);
}
void
...
...
@@ -91,6 +92,9 @@ PlainTestEnded(const char *testName, const char *suiteName,
if
(
testResult
)
{
if
(
testResult
==
2
)
{
Output
(
--
indentLevel
,
"%s: failed -> no assert"
,
testName
);
}
else
if
(
testResult
==
3
)
{
Output
(
--
indentLevel
,
"%s: skipped"
,
testName
);
}
else
{
Output
(
--
indentLevel
,
"%s: failed"
,
testName
);
}
...
...
@@ -104,7 +108,7 @@ PlainAssert(const char *assertName, int assertResult, const char *assertMessage,
time_t
eventTime
)
{
const
char
*
result
=
(
assertResult
)
?
"passed"
:
"failed"
;
Output
(
indentLevel
,
"%s: %s
;
%s"
,
assertName
,
result
,
assertMessage
);
Output
(
indentLevel
,
"%s: %s
-
%s"
,
assertName
,
result
,
assertMessage
);
}
void
...
...
@@ -112,7 +116,7 @@ PlainAssertWithValues(const char *assertName, int assertResult, const char *asse
int
actualValue
,
int
expected
,
time_t
eventTime
)
{
const
char
*
result
=
(
assertResult
)
?
"passed"
:
"failed"
;
Output
(
indentLevel
,
"%s
%s (expected %d, actualValue &d):
%s"
,
Output
(
indentLevel
,
"%s
: %s (expected %d, actualValue &d) -
%s"
,
assertName
,
result
,
expected
,
actualValue
,
assertMessage
);
}
...
...
test/test-automation/plain_logger.h
View file @
6d3454e1
...
...
@@ -26,7 +26,7 @@ void PlainRunStarted(int parameterCount, char *runnerParameters[], time_t eventT
* \param totalRuntime How long the execution took
*/
void
PlainRunEnded
(
int
testCount
,
int
suiteCount
,
int
testPassCount
,
int
testFailCount
,
time_t
endTime
,
double
totalRuntime
);
int
testSkippedCount
,
time_t
endTime
,
double
totalRuntime
);
/*!
* Prints the data about the test suite that'll be executed next
...
...
test/test-automation/runner.c
View file @
6d3454e1
This diff is collapsed.
Click to expand it.
test/test-automation/style.xsl
View file @
6d3454e1
...
...
@@ -104,6 +104,7 @@ $(document).ready(function() {
/* Color the tests based on the result */
$("span.testResult[result='passed']").addClass('passed');
$("span.testResult[result='failed']").addClass('failed');
$("span.testResult[result='skipped']").addClass('skipped');
/* Color the asserts based on the result */
$("span.assertResult[result='pass']").addClass('passed');
...
...
@@ -157,6 +158,10 @@ div, h1 {
color: red;
}
.skipped {
color: gray;
}
</style>
</head>
...
...
test/test-automation/testdummy/testdummy.c
View file @
6d3454e1
...
...
@@ -56,6 +56,9 @@ TestCaseReference **QueryTestSuite() {
* SetUp function can be used to create a test fixture for test cases.
* The function will be called right before executing the test case.
*
* Note: If any assert in the function fails then the test will be skipped.
* In practice, the entire suite will be skipped if assert failure happens.
*
* Note: this function is optional.
*
* \param arg parameters given to test. Usually NULL
...
...
test/test-automation/testsurface/testsurface.c
View file @
6d3454e1
...
...
@@ -32,11 +32,39 @@ TestCaseReference **QueryTestSuite() {
return
(
TestCaseReference
**
)
testSuite
;
}
/* Function prototypes */
SDL_Surface
*
_CreateTestSurface
();
/* Create test fixture */
static
SDL_Surface
*
testsur
=
NULL
;
void
SetUp
(
void
*
arg
)
{
int
ret
=
SDL_Init
(
SDL_INIT_VIDEO
);
AssertTrue
(
ret
==
0
,
"SDL_Init(SDL_INIT_VIDEO)"
);
testsur
=
_CreateTestSurface
();
AssertTrue
(
testsur
!=
NULL
,
"SDL_Init(SDL_INIT_VIDEO)"
);
}
void
TearDown
(
void
*
arg
)
{
SDL_FreeSurface
(
testsur
);
SDL_Quit
();
}
/* Helper functions for the test cases */
#define TEST_SURFACE_WIDTH 80
#define TEST_SURFACE_HEIGHT 60
/*!
* Creates test surface
*/
...
...
@@ -66,7 +94,7 @@ _CreateTestSurface()
/**
* @brief Tests a blend mode.
*/
int
_testBlitBlendMode
(
SDL_Surface
*
testsur
,
SDL_Surface
*
face
,
int
mode
)
void
_testBlitBlendMode
(
SDL_Surface
*
testsur
,
SDL_Surface
*
face
,
int
mode
)
{
int
ret
;
int
i
,
j
,
ni
,
nj
;
...
...
@@ -102,8 +130,6 @@ int _testBlitBlendMode(SDL_Surface *testsur, SDL_Surface *face, int mode)
ret
=
SDL_BlitSurface
(
face
,
NULL
,
testsur
,
&
rect
);
AssertTrue
(
ret
!=
0
,
"SDL_BlitSurface"
);
}
}
return
0
;
}
/* Test case functions */
...
...
@@ -115,11 +141,6 @@ void surface_testLoad(void *arg)
int
ret
;
SDL_Surface
*
face
,
*
rface
;
ret
=
SDL_Init
(
SDL_INIT_VIDEO
);
AssertTrue
(
ret
==
0
,
"SDL_Init(SDL_INIT_VIDEO)"
);
SDL_Surface
*
testsur
=
_CreateTestSurface
();
/* Clear surface. */
ret
=
SDL_FillRect
(
testsur
,
NULL
,
SDL_MapRGB
(
testsur
->
format
,
0
,
0
,
0
)
);
...
...
@@ -151,10 +172,6 @@ void surface_testLoad(void *arg)
/* Clean up. */
SDL_FreeSurface
(
rface
);
SDL_FreeSurface
(
face
);
SDL_FreeSurface
(
testsur
);
SDL_Quit
();
}
...
...
@@ -163,14 +180,8 @@ void surface_testLoad(void *arg)
*/
void
surface_testLoadFailure
(
void
*
arg
)
{
int
ret
=
SDL_Init
(
SDL_INIT_VIDEO
);
AssertTrue
(
ret
==
0
,
"SDL_Init(SDL_INIT_VIDEO)"
);
SDL_Surface
*
face
=
SDL_LoadBMP
(
"nonexistant.bmp"
);
AssertTrue
(
face
==
NULL
,
"SDL_CreateLoadBmp"
);
SDL_Quit
();
}
...
...
@@ -184,11 +195,6 @@ void surface_testBlit(void *arg)
SDL_Surface
*
face
;
int
i
,
j
,
ni
,
nj
;
ret
=
SDL_Init
(
SDL_INIT_VIDEO
);
AssertTrue
(
ret
==
0
,
"SDL_Init(SDL_INIT_VIDEO)"
);
SDL_Surface
*
testsur
=
_CreateTestSurface
();
/* Clear surface. */
ret
=
SDL_FillRect
(
testsur
,
NULL
,
SDL_MapRGB
(
testsur
->
format
,
0
,
0
,
0
)
);
...
...
@@ -292,9 +298,6 @@ void surface_testBlit(void *arg)
/* Clean up. */
SDL_FreeSurface
(
face
);
SDL_FreeSurface
(
testsur
);
SDL_Quit
();
}
/**
...
...
@@ -308,11 +311,6 @@ void surface_testBlitBlend(void *arg)
int
i
,
j
,
ni
,
nj
;
int
mode
;
ret
=
SDL_Init
(
SDL_INIT_VIDEO
);
AssertTrue
(
ret
==
0
,
"SDL_Init(SDL_INIT_VIDEO)"
);
SDL_Surface
*
testsur
=
_CreateTestSurface
();
/* Clear surface. */
ret
=
SDL_FillRect
(
testsur
,
NULL
,
SDL_MapRGB
(
testsur
->
format
,
0
,
0
,
0
)
);
...
...
@@ -415,7 +413,4 @@ void surface_testBlitBlend(void *arg)
/* Clean up. */
SDL_FreeSurface
(
face
);
SDL_FreeSurface
(
testsur
);
SDL_Quit
();
}
test/test-automation/xml_logger.c
View file @
6d3454e1
...
...
@@ -38,6 +38,7 @@ const char *numSuitesElementName = "numSuites";
const
char
*
numTestElementName
=
"numTests"
;
const
char
*
numPassedTestsElementName
=
"numPassedTests"
;
const
char
*
numFailedTestsElementName
=
"numFailedTests"
;
const
char
*
numSkippedTestsElementName
=
"numSkippedTests"
;
const
char
*
endTimeElementName
=
"endTime"
;
const
char
*
totalRuntimeElementName
=
"totalRuntime"
;
const
char
*
suiteElementName
=
"suite"
;
...
...
@@ -145,7 +146,7 @@ XMLRunStarted(int parameterCount, char *runnerParameters[], time_t eventTime,
void
XMLRunEnded
(
int
testCount
,
int
suiteCount
,
int
testPassCount
,
int
testFailCount
,
time_t
endTime
,
double
totalRuntime
)
int
testSkippedCount
,
time_t
endTime
,
double
totalRuntime
)
{
// log suite count
char
*
output
=
XMLOpenElement
(
numSuitesElementName
);
...
...
@@ -187,7 +188,17 @@ XMLRunEnded(int testCount, int suiteCount, int testPassCount, int testFailCount,
output
=
XMLCloseElement
(
numFailedTestsElementName
);
XMLOutputter
(
--
indentLevel
,
YES
,
output
);
// log end timte
// log skipped test count
output
=
XMLOpenElement
(
numSkippedTestsElementName
);
XMLOutputter
(
indentLevel
++
,
NO
,
output
);
output
=
XMLAddContent
(
IntToString
(
testSkippedCount
));
XMLOutputter
(
indentLevel
,
NO
,
output
);
output
=
XMLCloseElement
(
numSkippedTestsElementName
);
XMLOutputter
(
--
indentLevel
,
YES
,
output
);
// log end tite
output
=
XMLOpenElement
(
endTimeElementName
);
XMLOutputter
(
indentLevel
++
,
NO
,
output
);
...
...
@@ -342,6 +353,9 @@ XMLTestEnded(const char *testName, const char *suiteName,
if
(
testResult
)
{
if
(
testResult
==
2
)
{
output
=
XMLAddContent
(
"failed. No assert"
);
}
else
if
(
testResult
==
3
)
{
output
=
XMLAddContent
(
"skipped"
);
}
else
{
output
=
XMLAddContent
(
"failed"
);
}
...
...
test/test-automation/xml_logger.h
View file @
6d3454e1
...
...
@@ -24,7 +24,7 @@ void XMLRunStarted(int parameterCount, char *runnerParameters[], time_t eventTim
* \param totalRuntime How long the execution took
*/
void
XMLRunEnded
(
int
testCount
,
int
suiteCount
,
int
testPassCount
,
int
testFailCount
,
time_t
endTime
,
double
totalRuntime
);
int
testSkippedCount
,
time_t
endTime
,
double
totalRuntime
);
/*!
* Prints the data about the test suite that'll be executed next in XML
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment