Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
91 lines (76 loc) · 2.53 KB

SDL_test_assert.c

File metadata and controls

91 lines (76 loc) · 2.53 KB
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
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.
*/
/*
Used by the test framework and test cases.
*/
#include "SDL_config.h"
#include "SDL_test.h"
/* Assert check message format */
Dec 5, 2012
Dec 5, 2012
33
const char *SDLTest_AssertCheckFmt = "Assert '%s': %s";
34
35
36
37
38
39
40
41
42
/* Assert summary message format */
const char *SDLTest_AssertSummaryFmt = "Assert Summary: Total=%d Passed=%d Failed=%d";
/*
* Assert that logs and break execution flow on failures (i.e. for harness errors).
*/
void SDLTest_Assert(int assertCondition, char *assertDescription)
{
Dec 1, 2012
Dec 1, 2012
43
SDL_assert((SDLTest_AssertCheck(assertCondition, assertDescription)));
44
45
46
47
48
}
/*
* Assert that logs but does not break execution flow on failures (i.e. for test cases).
*/
Dec 1, 2012
Dec 1, 2012
49
int SDLTest_AssertCheck(int assertCondition, char *assertDescription)
50
51
{
char *fmt = (char *)SDLTest_AssertCheckFmt;
Dec 1, 2012
Dec 1, 2012
52
if (assertCondition == ASSERT_FAIL)
Dec 1, 2012
Dec 1, 2012
54
SDLTest_AssertsFailed++;
Dec 5, 2012
Dec 5, 2012
55
SDLTest_LogError(fmt, assertDescription, "Failed");
56
57
58
}
else
{
Dec 1, 2012
Dec 1, 2012
59
SDLTest_AssertsPassed++;
Dec 5, 2012
Dec 5, 2012
60
SDLTest_Log(fmt, assertDescription, "Passed");
Dec 1, 2012
Dec 1, 2012
62
63
return assertCondition;
64
65
66
67
68
69
70
}
/*
* Resets the assert summary counters to zero.
*/
void SDLTest_ResetAssertSummary()
{
Dec 1, 2012
Dec 1, 2012
71
72
SDLTest_AssertsPassed = 0;
SDLTest_AssertsFailed = 0;
73
74
75
76
77
78
79
80
81
}
/*
* Logs summary of all assertions (total, pass, fail) since last reset
* as INFO (failed==0) or ERROR (failed > 0).
*/
void SDLTest_LogAssertSummary()
{
char *fmt = (char *)SDLTest_AssertSummaryFmt;
Dec 1, 2012
Dec 1, 2012
82
83
Uint32 totalAsserts = SDLTest_AssertsPassed + SDLTest_AssertsFailed;
if (SDLTest_AssertsFailed == 0)
Dec 1, 2012
Dec 1, 2012
85
SDLTest_Log(fmt, totalAsserts, SDLTest_AssertsPassed, SDLTest_AssertsFailed);
86
87
88
}
else
{
Dec 1, 2012
Dec 1, 2012
89
SDLTest_LogError(fmt, totalAsserts, SDLTest_AssertsPassed, SDLTest_AssertsFailed);