Mudbox/UnitTest.h Source File

UnitTest.h
Go to the documentation of this file.
1 //**************************************************************************/
2 // Copyright (c) 2008 Autodesk, Inc.
3 // All rights reserved.
4 //
5 // Use of this software is subject to the terms of the Autodesk license
6 // agreement provided at the time of installation or download, or which
7 // otherwise accompanies this software in either electronic or hard copy form.
8 //
9 //**************************************************************************/
10 // DESCRIPTION:
11 // CREATED: October 2008
12 //**************************************************************************/
13 #ifndef UNITTEST_H
14 #define UNITTEST_H
15 
16 namespace mudbox
17 {
18 
24 class MBDLL_DECL UnitTest : public Node
25 {
27 public:
28  virtual void RunAllTests();
29  virtual void Go( bool , const QString& );
30 };
31 
32 };
33 
61 #define MB_START_TEST_OBJECT( testObjName ) \
62  class testObjName : public UnitTest \
63  { \
64  static testObjName* s_pThis; \
65  DECLARE_CLASS; \
66  astring m_sCommand; \
67  testObjName() : m_sCommand(this, "cmd") { \
68  m_sCommand.Connect(Kernel()->NextCommand); \
69  Go(true,""); \
70  s_pThis = this; \
71  }; \
72  virtual ~testObjName() { \
73  if( s_pThis == this ) \
74  s_pThis = 0; \
75  }; \
76  void OnNodeEvent( const Attribute &cAttribute, NodeEventType eType ) { \
77  if( cAttribute == m_sCommand && eType == etValueChanged ) { \
78  QString sOp = m_sCommand.Value().section( ' ', 0, 0 ); \
79  if( sOp == "PluginTest" ) \
80  Go(false, m_sCommand.Value().section( ' ', 1, 1 )); \
81  }; \
82  }; \
83  static void RunAll() { \
84  if( s_pThis ) \
85  s_pThis->Go( false, "" ); \
86  }; \
87  static QString ClassName() { \
88  return #testObjName; \
89  };
90 
91 #define MB_END_TEST_OBJECT( testObjName ) \
92  }; IMPLEMENT_CLASS( testObjName, UnitTest, #testObjName ); \
93  testObjName* testObjName::s_pThis = 0;
94 
95 #define MB_START_DEF_TESTS \
96  virtual void Go(bool bInit, const QString& sTest) { \
97  if( bInit ) \
98  { \
99  Kernel()->Interface()->AddCallbackMenuItem( NTR("UnitTest"), ClassName(), NTR("Run all tests"), RunAll ); \
100  };
101 
102 #define MB_END_DEF_TESTS \
103  };
104 
105 // declare a test with the given name and category
106 // name should be valid for method names
107 #define MB_DECL_TEST(name) \
108  static void name() \
109  { \
110  Kernel()->RecordCommand( NTRQ("PluginTest %1%2").arg(ClassName()).arg(#name) ); \
111  if( s_pThis ) \
112  s_pThis->Go(false, ClassName() + QString(#name)); \
113  QString sMsg = NTRQ("Completed Test: %1").arg(ClassName() + QString(#name)); \
114  Kernel()->Log( sMsg ); \
115  Kernel()->Interface()->SetStatus( mudbox::Interface::stNormal, sMsg ); \
116  };
117 
118 // define a test with the given name and category
119 // name should be valid for method names
120 // you need both this and MB_DECL_TEST to add a unit test.
121 #define MB_DEF_TEST(name) \
122  if( bInit ) \
123  Kernel()->Interface()->AddCallbackMenuItem( NTR("UnitTest"), ClassName(), #name, name); \
124  else if ( sTest == ClassName() + QString(#name) || sTest.isEmpty() ) \
125 
126 #define MB_CHECK(condition) \
127  if( !(condition) ) { \
128  MB_ASSERT(false); \
129  Kernel()->Log( NTRQ("UnitTest assert failed: %1").arg( #condition ) ); \
130  MB_ERROR( NTRQ("UnitTest assert failed: %1").arg( #condition ) ); \
131  };
132 
133 #endif
Base class for unit test objects.
Definition: UnitTest.h:24
This is the base class for most classes in the Mudbox SDK.
Definition: node.h:740
Class: ConvolutionKernel.
Definition: array.h:15
#define DECLARE_CLASS
This macro should be used in declaration of classes which are inherited from the Node class (or any d...
Definition: node.h:91
#define MBDLL_DECL
Definition: dllinterface.h:35