-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestFramework1.cpp
89 lines (76 loc) · 1.96 KB
/
TestFramework1.cpp
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
* Vending Machine Project
* CSE-40477
*
* TestFramework.cpp
* YOU MUST NOT CHANGE THIS FILE.
*/
#include <iostream>
using std::endl;
#include <sstream>
using std::stringstream;
#include <string>
using std::string;
#include "TestFramework.h"
// Initialize static members
ostream *TestFramework::pos = 0;
string TestFramework::name = "";
vector<string> TestFramework::assertionResults = vector<string>();
bool TestFramework::passed = true;
unsigned TestFramework::totalTestsPassed = 0;
unsigned TestFramework::totalTestsFailed = 0;
void
TestFramework::Initialize(ostream *pos)
{
TestFramework::pos = pos;
}
void
TestFramework::BeginTest(string name)
{
*TestFramework::pos << ">>>>>> Beginning test '" << name << "'" << endl;
TestFramework::name = name;
TestFramework::assertionResults.clear();
TestFramework::passed = true;
}
bool
TestFramework::Assert(bool condition, string file, unsigned line)
{
if (!condition)
{
stringstream ss;
TestFramework::passed = false;
ss << "Assertion failed: file " << file << ", line " << line;
TestFramework::assertionResults.push_back(ss.str());
}
return condition;
}
void
TestFramework::EndTest()
{
if (TestFramework::passed)
{
++TestFramework::totalTestsPassed;
}
else
{
++TestFramework::totalTestsFailed;
}
// Display assertionResults
for (size_t i = 0; i < TestFramework::assertionResults.size(); ++i)
{
*TestFramework::pos << "\t" << TestFramework::assertionResults[i]
<< endl;
}
// Display test result
*TestFramework::pos << "<<<<<< Ending test '" << TestFramework::name
<< "' ";
*TestFramework::pos << "---> "
<< (TestFramework::passed ? "Passed" : "FAILED") << endl << endl;
}
void
TestFramework::DisplaySummary()
{
*TestFramework::pos << TestFramework::totalTestsPassed
<< " tests passed, " << TestFramework::totalTestsFailed
<< " tests failed" << endl << endl;
}