1/*
2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef TEST_SUITE_H
6#define TEST_SUITE_H
7
8
9#include <new>
10
11#include "Test.h"
12
13
14class TestSuite : public Test {
15public:
16								TestSuite(const char* name);
17	virtual						~TestSuite();
18
19			int32				CountTests() const;
20			Test*				TestAt(int32 index) const;
21			Test*				FindTest(const char* name,
22									int32 nameLength = -1) const;
23
24			bool				AddTest(Test* test);
25
26	virtual	bool				IsLeafTest() const;
27
28	virtual	bool				Run(TestContext& context);
29	virtual	bool				Run(TestContext& context, const char* name);
30
31	virtual	Test*				Visit(TestVisitor& visitor);
32
33private:
34			bool				_Run(TestContext& context, Test* test,
35									const char* name);
36
37private:
38			Test**				fTests;
39			int32				fTestCount;
40};
41
42
43#define ADD_TEST(suite, test)			\
44	do {								\
45		if (!suite->AddTest(test)) {	\
46			delete test;				\
47			delete suite;				\
48			return NULL;				\
49		}								\
50	} while (false)
51
52#define ADD_STANDARD_TEST(suite, type, method)								\
53	do {																	\
54		type* object = new(std::nothrow) type;								\
55		if (object == NULL)													\
56			return NULL;													\
57																			\
58		StandardTest<type>* test = new(std::nothrow) StandardTest<type>(	\
59			#method, object, &type::method);								\
60		if (test == NULL) {													\
61			delete object;													\
62			return NULL;													\
63		}																	\
64		ADD_TEST(suite, test);												\
65	} while (false)
66
67
68#endif	// TEST_SUITE_H
69