00001 // See the end of this file for license information. 00002 00003 #ifndef TORSION_TEST_H 00004 #define TORSION_TEST_H 00005 00006 #include "screen.h" 00007 00008 #define FAIL(check) \ 00009 if (!test_name) \ 00010 test_name = (char*)__PRETTY_FUNCTION__; \ 00011 check_name = check; \ 00012 success = false; \ 00013 return; \ 00014 00015 #define ENSURE(check, condition) \ 00016 if (!test_name) \ 00017 test_name = (char*)__PRETTY_FUNCTION__; \ 00018 if (!condition) { \ 00019 check_name = check; \ 00020 success = false; \ 00021 return; \ 00022 } 00023 00030 class Test_case { 00031 protected: 00032 bool success; 00033 00034 public: 00035 char* test_name; 00036 char* check_name; 00037 00039 virtual void 00040 init() { } 00041 00043 virtual void 00044 deinit() { } 00045 00046 inline bool 00047 get_success() { return success; } 00048 00049 inline void 00050 set_success(bool successful) { success = successful; } 00051 }; 00052 00054 template <class Test_case_type> 00055 class Test_suite { 00056 protected: 00057 typedef void (Test_case_type::*Test_func)(); 00058 00061 void 00062 run(Test_func test_function); 00063 00064 public: 00067 virtual void 00068 start() = 0; 00069 }; 00070 00071 template <class Test_case_type> 00072 void 00073 Test_suite<Test_case_type>::run(Test_func test_function) { 00074 Test_case_type test_case; 00075 test_case.init(); 00076 test_case.set_success(true); 00077 test_case.test_name = NULL; 00078 00079 (test_case.*test_function)(); 00080 00081 if (test_case.get_success()) { 00082 screen.print(test_case.test_name, false); 00083 screen.print(": OK"); 00084 } else { 00085 screen.print(test_case.test_name, false); 00086 screen.print(" ", false); 00087 screen.print(test_case.check_name, false); 00088 screen.print(": failed"); 00089 } 00090 test_case.deinit(); 00091 } 00092 00093 #endif 00094 00095 /* Torsion Operating System, Copyright (C) 2000-2004 Dan Helfman 00096 * 00097 * This program is free software; you can redistribute it and/or modify it 00098 * under the terms of the GNU General Public License as published by the 00099 * Free Software Foundation; either version 2 of the License, or (at your 00100 * option) any later version. 00101 * 00102 * This program is distributed in the hope that it will be useful, but 00103 * WITHOUT ANY WARRANTY; without even the implied warranty of 00104 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00105 * General Public License for more details (in the COPYING file). 00106 * 00107 * You should have received a copy of the GNU General Public License along 00108 * with this program; if not, write to the Free Software Foundation, Inc., 00109 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00110 */
Torsion Operating System, Copyright (C) 2000-2004 Dan Helfman