-
-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathUnitTest.cpp
More file actions
119 lines (106 loc) · 2.83 KB
/
UnitTest.cpp
File metadata and controls
119 lines (106 loc) · 2.83 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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// UnitTest.cpp
//
// Implements the basic unit testing framework. See UnitTest.h
// for usage details.
//
// (c) 2013 Xojo, Inc. -- All Rights Reserved
// (Based on code owned by Joe Strout -- used with permission.)
//
// Document Scope: hopefully all projects, targets, & platforms
// Document Author: Joe Strout
// Document Contributor(s):
//
// Revision History
// Jul 06 2001 -- JJS (1) Changed DeleteAllTests to not delete the test objects,
// since they are now static objects (not deletable).
#include "UnitTest.h"
#include "QA.h"
#include <stdio.h>
#include <iostream>
#include "SimpleString.h"
namespace MiniScript {
UnitTest *UnitTest::cTests = 0;
// UnitTest::RegisterUnitTest
//
// Add the given test case to our global list of test cases.
//
// Author: JJS
// Used in: TestCaseRegistrar constructor
// Gets: test -- test case to register
// Returns: <nothing>
// Comment: Jul 05 2001 -- JJS (1)
void UnitTest::RegisterTestCase(UnitTest *test)
{
if (cTests) {
test->mNext = cTests;
}
cTests = test;
}
// UnitTest::RunAllTests
//
// Run all tests in our global list of tests.
//
// Author: JJS
// Used in:
// Gets: <nothing>
// Returns: <nothing>
// Comment: Jul 05 2001 -- JJS (1)
void UnitTest::RunAllTests()
{
for (UnitTest *test = cTests; test; test = test->mNext) {
// std::cout << "Running " << test->name << std::endl;
test->SetUp();
test->Run();
test->TearDown();
// std::cout << "StringStorage instances left: " << StringStorage::instanceCount << std::endl;
// std::cout << "total RefCountedStorage instances left: " << RefCountedStorage::instanceCount << std::endl;
}
}
// UnitTest::DeleteAllTests
//
// This method is intended to delete all the tests from the global
// list of tests. However, since tests are now declared as static
// globals, we can't do that. So this just empties our list
// (without deleting the actual test objects).
//
// Author: JJS
// Used in:
// Gets: <nothing>
// Returns: <nothing>
// Comment: Jul 05 2001 -- JJS (1)
void UnitTest::DeleteAllTests()
{
UnitTest *next;
for (UnitTest *test = cTests; test; test = next) {
next = test->mNext;
// Jul 06 2001 -- JJS (1) -- commented out:
//delete test;
}
cTests = 0;
}
//--------------------------------------------------------------------------------
// MARK: -
// class TestCaseItself
//
// Here's a test case to test UnitTest itself.
//
class TestCaseItself : public UnitTest
{
public:
TestCaseItself() : UnitTest("TestCaseItself") {}
virtual void Run();
};
void TestCaseItself::Run()
{
ErrorIf(1==0);
Assert(2+2==4);
// NOTE: can't really test the actual error reporting, because if
// it works it'd look like an error!
}
RegisterUnitTest(TestCaseItself);
}
#ifdef UNIT_TEST_MAIN
int main(int, const char*[]) {
MiniScript::UnitTest::RunAllTests();
}
#endif