ZFFramework
 
Loading...
Searching...
No Matches
ZFTestCase.h
Go to the documentation of this file.
1
5
6#ifndef _ZFI_ZFTestCase_h_
7#define _ZFI_ZFTestCase_h_
8
9#include "ZFUtilityDef.h"
11
12zfclassFwd _ZFP_ZFTestCasePrivate;
25zfabstract ZFLIB_ZFUtility ZFTestCase : zfextend ZFObject, zfimplement ZFTaskId {
27 ZFIMPLEMENT_DECLARE(ZFTaskId)
28
29public:
36 ZFEVENT(TestCaseOnOutput)
42 ZFEVENT(TestCaseOnStart)
48 ZFEVENT(TestCaseOnProgress)
54 ZFEVENT(TestCaseOnStop)
55
56protected:
58 virtual void objectOnDeallocPrepare(void);
59
60protected:
62 virtual inline void testCaseOnOutput(ZF_IN const zfchar *info) {
65 }
66 }
67
68 virtual inline void testCaseOnStart(void) {
70 }
71
72 virtual inline void testCaseOnProgress(ZF_IN ZFObject *progress) {
74 }
75
76 virtual inline void testCaseOnStop(ZF_IN ZFResultType testCaseResult) {
78 zfRelease(this);
79 }
80
81public:
86
87
91 zffinal void output(ZF_IN const zfchar *info);
105 , ZFMP_IN_OPT(ZFObject *, progress, zfnull)
108 virtual void stop(void) {
110 }
111
117 ZFMETHOD_DECLARE_1(void, stop
118 , ZFMP_IN(ZFResultType, testCaseResult)
120
121private:
122 zfbool _started;
123protected:
124 ZFTestCase(void) : _started(zffalse) {}
125};
126
132#define ZFTestCaseAssert(cond) \
133 ZFTestCaseAssertWithMessage(cond, "test failed: %s", #cond)
134
135#define ZFTestCaseAssertTrim(cond) \
136 ZFTestCaseAssertTrimWithMessage(cond, "test failed: %s", #cond)
137
138#define ZFTestCaseAssertDetail(cond, callerInfo) \
139 ZFTestCaseAssertDetailWithMessage(cond, callerInfo, "test failed: %s", #cond)
140
142#define ZFTestCaseAssertWithMessage(cond, fmt, ...) \
143 do { \
144 if(!(cond)) { \
145 this->output(zfstr("%s " fmt, ZFCallerInfoCreate(), ##__VA_ARGS__)); \
146 this->stop(v_ZFResultType::e_Fail); \
147 return; \
148 } \
149 } while(zffalse)
150
151#define ZFTestCaseAssertWithMessageTrim(cond, fmt, ...) \
152 do { \
153 if(!(cond)) { \
154 this->output(zfstr(fmt, ##__VA_ARGS__)); \
155 this->stop(v_ZFResultType::e_Fail); \
156 return; \
157 } \
158 } while(zffalse)
159
160#define ZFTestCaseAssertWithMessageDetail(cond, callerInfo, fmt, ...) \
161 do { \
162 if(!(cond)) { \
163 this->output(zfstr("%s " fmt, callerInfo, fmt, ##__VA_ARGS__)); \
164 this->stop(v_ZFResultType::e_Fail); \
165 return; \
166 } \
167 } while(zffalse)
168
170#endif // #ifndef _ZFI_ZFTestCase_h_
171
_ZFT_t_zfchar zfchar
char wrapper
Definition ZFCoreTypeDef_CharType.h:17
#define zffinal
dummy macro shows that a method or class is designed must not to be overrided
Definition ZFCoreTypeDef_ClassType.h:63
#define zfextend
dummy macro shows class inherit from another
Definition ZFCoreTypeDef_ClassType.h:53
#define zfoverride
dummy macro shows that method override parent's method
Definition ZFCoreTypeDef_ClassType.h:58
#define ZF_IN
dummy macro that shows the param used as required input
Definition ZFCoreTypeDef_ClassType.h:180
#define zfclassFwd
forward declaration of a class type
Definition ZFCoreTypeDef_ClassType.h:31
_ZFT_t_zfbool zfbool
bool type
Definition ZFCoreTypeDef_CoreType.h:103
#define zffalse
bool false type
Definition ZFCoreTypeDef_CoreType.h:111
#define zfnull
same as NULL, defined for future use
Definition ZFCoreTypeDef_CoreType.h:88
#define ZFMP_IN_OPT(ParamType, paramName, DefaultValue)
see ZFMP_IN
Definition ZFMethod.h:108
#define ZFMP_IN(ParamType, paramName)
macro to wrap param types for ZFMETHOD_INLINE_0 series
Definition ZFMethod.h:105
#define ZFMETHOD_DECLARE_0(ReturnType, MethodName)
see ZFMethod
Definition ZFMethodDeclare.h:693
#define ZFMETHOD_DECLARE_1(ReturnType, MethodName, ZFMP_0)
see ZFMethod
Definition ZFMethodDeclare.h:854
#define ZF_NAMESPACE_GLOBAL_BEGIN
begin namespace ZFFramework
Definition ZFNamespace.h:97
#define ZF_NAMESPACE_GLOBAL_END
end namespace ZFFramework
Definition ZFNamespace.h:98
#define zfabstract
typename for class showing that its abstract
Definition ZFObjectClassTypeFwd.h:42
#define ZFOBJECT_DECLARE_ABSTRACT_WITH_CUSTOM_CTOR(ChildClass, SuperClass,...)
see ZFOBJECT_DECLARE_WITH_CUSTOM_CTOR
Definition ZFObjectDeclare.h:160
#define ZFIMPLEMENT_DECLARE(ImplementedInterfaces,...)
see ZFINTERFACE_DECLARE
Definition ZFObjectInterface.h:169
#define zfimplement
shows class implement from interface, see ZFInterface
Definition ZFObjectInterface.h:24
#define ZFEVENT(YourEvent)
see ZFObject::observerNotify
Definition ZFObjectObserver.h:328
#define zfRelease(obj)
release an object, see ZFObject
Definition ZFObjectRetain.h:148
v_ZFResultType::ZFEnumType ZFResultType
see v_ZFResultType
Definition ZFResultType.h:23
global header for ZFUtility module
#define ZFLIB_ZFUtility
used to export symbols
Definition ZFUtilityDef.h:15
zfbool observerHasAdd(void)
true if any observer has been added
void observerNotify(zfidentity eventId, ZFObject *param0=zft_zfnull, ZFObject *param1=zft_zfnull)
notify the observer with eventId
virtual void start()
manually start a test case
virtual void testCaseOnProgress(ZFObject *progress)
see E_TestCaseOnProgress
Definition ZFTestCase.h:72
virtual void testCaseOnStop(ZFResultType testCaseResult)
see E_TestCaseOnStop
Definition ZFTestCase.h:76
virtual void testCaseOnStart(void)
see E_TestCaseOnStart
Definition ZFTestCase.h:68
virtual void testCaseOnOutput(const zfchar *info)
see E_TestCaseOnOutput
Definition ZFTestCase.h:62
virtual zfbool started()
whether test is running
static zfidentity E_TestCaseOnOutput(void)
called when output something
static zfidentity E_TestCaseOnStart(void)
called when test started
virtual void stop(void)
stop task
Definition ZFTestCase.h:108
static zfidentity E_TestCaseOnStop(void)
called when test stopped
virtual void objectOnDeallocPrepare(void)
called before objectOnDealloc, safe to call virtual functions here
static zfidentity E_TestCaseOnProgress(void)
called when test progress
virtual void notifyProgress(ZFObject *progress=(zft_zfnull))
called to notify progress, do nothing if not running
void output(const zfchar *info)
output something for the test case, used to debug
@ e_Success
Definition ZFResultType.h:16
util class to alloc and hold ZFObject type
Definition ZFObjectAutoPtr.h:157