-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcpcc_SelfTest.h
132 lines (101 loc) · 3.69 KB
/
cpcc_SelfTest.h
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/* *****************************************
* File: cpcc_SelfTest.h
* Version: 1.1
* Purpose: Portable (cross-platform), light-weight, unit self-checking
* *****************************************
* Library: Cross Platform C++ Classes (cpcc)
* Copyright: 2019 StarMessage software.
* License: Free for opensource projects.
* Commercial license for closed source projects.
* Web: http://www.StarMessageSoftware.com
* Download: https://code.google.com/p/cpcc/
* https://github.com/starmessage/cpcc
* email: sales -at- starmessage.info
* *****************************************
*/
// ////////////////////////////
// deprecated by cpccTesting.h
// ////////////////////////////
#pragma once
#include "core.cpccIdeMacros.h"
#include "cpccUnicodeSupport.h"
#include <assert.h>
// Central switch to close all selfTests in your application
#ifdef cpccDEBUG
#define ENABLE_SELF_TESTS 1
#else
#define ENABLE_SELF_TESTS 0
#endif
#ifdef _WIN32
#include <Windows.h>
#include <sstream>
#elif defined(__APPLE__)
#include <iostream>
#endif
/**
How to use the self test macro:
1) Start with SELFTEST_BEGIN and a unique label
2) add the self test code (can be a static function of your class under test
2) Close with SELFTEST_END
Your testing code will run when your application starts
Example:
SELFTEST_BEGIN(cpccFileSystemMini_SelfTest)
// MessageBox(NULL, "selftest of cpccFileSystemMini" , NULL, NULL);
cpccFileSystemMini::selfTest();
SELFTEST_END
*/
/// consolePut() is used to allow console output inside visual studio.
/// In OSX, xcode, the command std::cout << "something"
/// send the text in the console window. This does not happen in visual studio (if creating a windows app)
/// This macro is used to fix this inconvenience, that is an annoying inconsistency when you develop cross platform applications
/// Usage example: consolePut( "Log filename:" << aFilename );
#ifdef _WIN32
/*
class consoleRedirect
{
public:
~consoleRedirect(void) { OutputDebugString(s.str().c_str());
// OutputDebugString("\n"); }
std::ostringstream s;
static std::ostringstream& put(void) { consoleRedirect a; return a.s; }
};
*/
#define consolePut(x) { cpcc_ostringstream s; s << x << std::endl; \
OutputDebugString(s.str().c_str()); \
}
#else
#define consolePut(x) std::cout << x << std::endl;
#endif
#if (ENABLE_SELF_TESTS==1)
#define SelftestVariableName aSelfTest
#else
#define SelftestVariableName
#endif
#define selfTest_STR(value) #value
#define selfTest_MAKESTRING(value) selfTest_STR(value)
#define SELFTEST_BEGIN(SelfTestUniqueName) \
namespace SelfTestUniqueName { \
class cpccSelfTest \
{ \
public: \
cpccSelfTest() \
{ std::cout << "/ Starting selftest:" << selfTest_MAKESTRING(SelfTestUniqueName) << std::endl; \
const char* tmpSelfTestNameA = selfTest_MAKESTRING(SelfTestUniqueName);
#define SELFTEST_END \
std::cout << "\\ Ending selftest:" << tmpSelfTestNameA << std::endl << std::endl; \
}; \
} SelftestVariableName; }
/*
#define SELFTEST_ATEXIT_BEGIN(SelfTestUniqueName) \
namespace SelfTestUniqueName { \
class cpccSelfTest \
{ \
public: \
~cpccSelfTest() \
{ std::cout << "/ Starting selftest at exit:" << selfTest_MAKESTRING(SelfTestUniqueName) << std::endl; \
const char* tmpSelfTestNameA = selfTest_MAKESTRING(SelfTestUniqueName);
#define SELFTEST_ATEXIT_END \
std::cout << "\\ Ending selftest at exit:" << tmpSelfTestNameA << std::endl << std::endl; \
}; \
} SelftestVariableName; }
*/