Go to the
documentation of this file.
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef UNITTEST_H
00014 #define UNITTEST_H
00015
00016 namespace mudbox
00017 {
00018
00024 class MBDLL_DECL UnitTest : public Node
00025 {
00026 DECLARE_CLASS;
00027 public:
00028 virtual void RunAllTests();
00029 virtual void Go( bool , const QString& );
00030 };
00031
00032 };
00033
00060 #define MB_START_TEST_OBJECT( testObjName ) \
00061 class testObjName : public UnitTest \
00062 { \
00063 static testObjName* s_pThis; \
00064 DECLARE_CLASS; \
00065 astring m_sCommand; \
00066 testObjName() : m_sCommand(this, "cmd") { \
00067 m_sCommand.Connect(Kernel()->NextCommand); \
00068 Go(true,""); \
00069 s_pThis = this; \
00070 }; \
00071 virtual ~testObjName() { \
00072 if( s_pThis == this ) \
00073 s_pThis = 0; \
00074 }; \
00075 void OnNodeEvent( const Attribute &cAttribute, NodeEventType eType ) { \
00076 if( cAttribute == m_sCommand && eType == etValueChanged ) { \
00077 QString sOp = m_sCommand.Value().section( ' ', 0, 0 ); \
00078 if( sOp == "PluginTest" ) \
00079 Go(false, m_sCommand.Value().section( ' ', 1, 1 )); \
00080 }; \
00081 };
00082
00083 #define MB_END_TEST_OBJECT( testObjName ) \
00084 }; IMPLEMENT_CLASS( testObjName, UnitTest, #testObjName ); \
00085 testObjName* testObjName::s_pThis = 0;
00086
00087 #define MB_START_DEF_TESTS \
00088 virtual void Go(bool bInit, const QString& sTest) {
00089
00090 #define MB_END_DEF_TESTS \
00091 };
00092
00093
00094
00095 #define MB_DECL_TEST(category, name) \
00096 static void name() \
00097 { \
00098 Kernel()->RecordCommand( NTRQ("PluginTest %1%2").arg(category).arg(#name) ); \
00099 if( s_pThis ) \
00100 s_pThis->Go(false, QString(category) + QString(#name)); \
00101 QString sMsg = NTRQ("Completed Test: %1").arg(QString(category) + QString(#name)); \
00102 Kernel()->Log( sMsg ); \
00103 Kernel()->SetStatus( Kernel::stNormal, sMsg ); \
00104 };
00105
00106
00107
00108
00109 #define MB_DEF_TEST(category, name) \
00110 if( bInit ) \
00111 Kernel()->AddCallbackMenuItem("UnitTest", category, #name, name); \
00112 else if ( sTest == QString(category) + QString(#name) ) \
00113
00114 #define MB_CHECK(condition) \
00115 if( !(condition) ) { \
00116 Kernel()->Log( NTRQ("UnitTest assert failed: %1").arg( #condition ) ); \
00117 MB_ERROR( NTRQ("UnitTest assert failed: %1").arg( #condition ) ); \
00118 };
00119
00120 #endif