00001 /* 00002 * PROPRIETARY INFORMATION. This software is proprietary to 00003 * Side Effects Software Inc., and is not to be reproduced, 00004 * transmitted, or disclosed in any way without written permission. 00005 * 00006 * Produced by: 00007 * Edward Lam 00008 * Side Effects Software Inc 00009 * 123 Front Street West, Suite 1401 00010 * Toronto, Ontario 00011 * Canada M5J 2M2 00012 * 416-504-9876 00013 * 00014 * NAME: UT_TestManager.h (C++) 00015 * 00016 * COMMENTS: This class provides a test harness framework. 00017 * 00018 * USAGE: 00019 * 1. Create a main() method for your test application like so: 00020 * int main(int argc, char *argv[]) 00021 * { 00022 * return UT_TestManager::get().run(argc, argv); 00023 * } 00024 * The return code will be the number of test failures. 00025 * To obtain the command line usage, use "testapp -h". 00026 * 00027 * 2. For each test case, use one of the TEST_REGISTER*() macros for 00028 * registering a test function. The function should return true if the 00029 * test passed. 00030 */ 00031 00032 #ifndef __UT_TESTMANAGER_H__ 00033 #define __UT_TESTMANAGER_H__ 00034 00035 #include "UT_API.h" 00036 00037 #include "UT_Functor.h" 00038 00039 class UT_API UT_TestManager 00040 { 00041 public: 00042 /// Access the global test manager 00043 static UT_TestManager & get(); 00044 00045 /// Determine if the test was interactively invoked 00046 virtual bool isInteractive() const = 0; 00047 00048 /// Called by main() to run the tests. Returns the number of test failures. 00049 virtual int run(int argc, char *argv[]) = 0; 00050 00051 /// Called by the TEST_REGISTER*() macros to automatically add a new test 00052 /// case 00053 virtual void addTest(const char *name, 00054 UT_Functor<bool> &callback) = 0; 00055 }; 00056 00057 /// Use this macro after your test function is declared. It will register 00058 /// your method with the test manager. Your method should return true if the 00059 /// test succeeded, false otherwise. The name is the label that will be used 00060 /// for invoking this specific test. 00061 #define TEST_REGISTER_FN(name, method) \ 00062 class method##Registrar \ 00063 { \ 00064 public: \ 00065 method##Registrar() \ 00066 { \ 00067 UT_Functor<bool> callback(&method); \ 00068 UT_TestManager::get().addTest(name, callback); \ 00069 } \ 00070 }; \ 00071 static method##Registrar the##method##Registrar; 00072 00073 /// Use this macro after your test class is declared. It will create a static 00074 /// instance of your class that then registers your 'bool classname::method()' 00075 /// with the test manager. Your method should return true if the test 00076 /// succeeded, false otherwise. The name is the label that will be used for 00077 /// invoking this specific test. 00078 #define TEST_REGISTER(name, classname, method) \ 00079 class classname##method##Registrar \ 00080 { \ 00081 public: \ 00082 classname##method##Registrar() \ 00083 { \ 00084 UT_Functor<bool> callback(&myTest, \ 00085 &classname::method); \ 00086 UT_TestManager::get().addTest(name, callback); \ 00087 } \ 00088 private: \ 00089 classname myTest; \ 00090 }; \ 00091 static classname##method##Registrar \ 00092 the##classname##method##Registrar; 00093 00094 #endif // __UT_TESTMANAGER_H__
1.5.9