Classes | Namespaces | Defines

UnitTest.h File Reference

Go to the source code of this file.

Classes

class   UnitTest
  Base class for unit test objects. More...

Namespaces

namespace   mudbox
 

Class: ConvolutionKernel.


Defines

#define  MB_START_TEST_OBJECT(testObjName)
  These macros define a test object that contains unit tests.
#define  MB_END_TEST_OBJECT(testObjName)
#define  MB_START_DEF_TESTS   virtual void Go(bool bInit, const QString& sTest) {
#define  MB_END_DEF_TESTS   };
#define  MB_DECL_TEST(category, name)
#define  MB_DEF_TEST(category, name)
#define  MB_CHECK(condition)

Define Documentation

#define MB_START_TEST_OBJECT (   testObjName )
Value:
class testObjName : public UnitTest \
    {   \
        static testObjName* s_pThis; \
        DECLARE_CLASS;  \
        astring m_sCommand; \
        testObjName() : m_sCommand(this, "cmd") { \
            m_sCommand.Connect(Kernel()->NextCommand); \
            Go(true,""); \
            s_pThis = this; \
        }; \
        virtual ~testObjName() { \
            if( s_pThis == this )   \
                s_pThis = 0; \
        }; \
        void OnNodeEvent( const Attribute &cAttribute, NodeEventType eType )  { \
            if( cAttribute == m_sCommand && eType == etValueChanged ) { \
                QString sOp = m_sCommand.Value().section( ' ', 0, 0 ); \
                if( sOp == "PluginTest" ) \
                    Go(false, m_sCommand.Value().section( ' ', 1, 1 )); \
            }; \
        };

These macros define a test object that contains unit tests.

To add unit tests to your plugin, put the following boilerplate code in a new .cpp file that gets compiled with your plugin.

#include <UnitTest.h> MB_START_TEST_OBJECT

MB_DECL_TEST( "Your Category", TestName ) MB_DECL_TEST( "Your Category", TestName2 )

MB_START_DEF_TESTS MB_DEF_TEST( "Your Category", TestName ) { tests here } MB_DEF_TEST( "Your Category", TestName2 ) { tests here assert using MB_CHECK( some boolean expression ) to make sure your code is doing what you think its doing! } MB_END_DEF_TESTS

MB_END_TEST_OBJECT("MyPluginsTester")

Definition at line 60 of file UnitTest.h.

#define MB_END_TEST_OBJECT (   testObjName )
Value:
}; IMPLEMENT_CLASS( testObjName, UnitTest, #testObjName ); \
    testObjName* testObjName::s_pThis = 0;

Definition at line 83 of file UnitTest.h.

#define MB_START_DEF_TESTS   virtual void Go(bool bInit, const QString& sTest) {

Definition at line 87 of file UnitTest.h.

#define MB_END_DEF_TESTS   };

Definition at line 90 of file UnitTest.h.

#define MB_DECL_TEST (   category,
  name 
)
Value:
static void name() \
    {   \
        Kernel()->RecordCommand( NTRQ("PluginTest %1%2").arg(category).arg(#name) );    \
        if( s_pThis ) \
            s_pThis->Go(false, QString(category) + QString(#name)); \
        QString sMsg = NTRQ("Completed Test: %1").arg(QString(category) + QString(#name)); \
        Kernel()->Log( sMsg );  \
        Kernel()->SetStatus( Kernel::stNormal, sMsg ); \
    };

Definition at line 95 of file UnitTest.h.

#define MB_DEF_TEST (   category,
  name 
)
Value:
if( bInit ) \
        Kernel()->AddCallbackMenuItem("UnitTest", category, #name, name);   \
        else if ( sTest == QString(category) + QString(#name) ) \

Definition at line 109 of file UnitTest.h.

#define MB_CHECK (   condition )
Value:
if( !(condition) ) {    \
        Kernel()->Log( NTRQ("UnitTest assert failed: %1").arg( #condition ) );  \
        MB_ERROR( NTRQ("UnitTest assert failed: %1").arg( #condition ) );   \
    };

Definition at line 114 of file UnitTest.h.