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
00061 #define MB_START_TEST_OBJECT( testObjName ) \
00062 class testObjName : public UnitTest \
00063 { \
00064 static testObjName* s_pThis; \
00065 DECLARE_CLASS; \
00066 astring m_sCommand; \
00067 testObjName() : m_sCommand(this, "cmd") { \
00068 m_sCommand.Connect(Kernel()->NextCommand); \
00069 Go(true,""); \
00070 s_pThis = this; \
00071 }; \
00072 virtual ~testObjName() { \
00073 if( s_pThis == this ) \
00074 s_pThis = 0; \
00075 }; \
00076 void OnNodeEvent( const Attribute &cAttribute, NodeEventType eType ) { \
00077 if( cAttribute == m_sCommand && eType == etValueChanged ) { \
00078 QString sOp = m_sCommand.Value().section( ' ', 0, 0 ); \
00079 if( sOp == "PluginTest" ) \
00080 Go(false, m_sCommand.Value().section( ' ', 1, 1 )); \
00081 }; \
00082 }; \
00083 static void RunAll() { \
00084 if( s_pThis ) \
00085 s_pThis->Go( false, "" ); \
00086 }; \
00087 static QString ClassName() { \
00088 return #testObjName; \
00089 };
00090
00091 #define MB_END_TEST_OBJECT( testObjName ) \
00092 }; IMPLEMENT_CLASS( testObjName, UnitTest, #testObjName ); \
00093 testObjName* testObjName::s_pThis = 0;
00094
00095 #define MB_START_DEF_TESTS \
00096 virtual void Go(bool bInit, const QString& sTest) { \
00097 if( bInit ) \
00098 { \
00099 Kernel()->Interface()->AddCallbackMenuItem( NTR("UnitTest"), ClassName(), NTR("Run all tests"), RunAll ); \
00100 };
00101
00102 #define MB_END_DEF_TESTS \
00103 };
00104
00105
00106
00107 #define MB_DECL_TEST(name) \
00108 static void name() \
00109 { \
00110 Kernel()->RecordCommand( NTRQ("PluginTest %1%2").arg(ClassName()).arg(#name) ); \
00111 if( s_pThis ) \
00112 s_pThis->Go(false, ClassName() + QString(#name)); \
00113 QString sMsg = NTRQ("Completed Test: %1").arg(ClassName() + QString(#name)); \
00114 Kernel()->Log( sMsg ); \
00115 Kernel()->Interface()->SetStatus( mudbox::Interface::stNormal, sMsg ); \
00116 };
00117
00118
00119
00120
00121 #define MB_DEF_TEST(name) \
00122 if( bInit ) \
00123 Kernel()->Interface()->AddCallbackMenuItem( NTR("UnitTest"), ClassName(), #name, name); \
00124 else if ( sTest == ClassName() + QString(#name) || sTest.isEmpty() ) \
00125
00126 #define MB_CHECK(condition) \
00127 if( !(condition) ) { \
00128 MB_ASSERT(false); \
00129 Kernel()->Log( NTRQ("UnitTest assert failed: %1").arg( #condition ) ); \
00130 MB_ERROR( NTRQ("UnitTest assert failed: %1").arg( #condition ) ); \
00131 };
00132
00133 #endif