![]() |
User Manual, Developers Guide and API Documentation |
![]() |
00001 /******************************************************************************* 00002 * This file is part of openWNS (open Wireless Network Simulator) 00003 * _____________________________________________________________________________ 00004 * 00005 * Copyright (C) 2004-2007 00006 * Chair of Communication Networks (ComNets) 00007 * Kopernikusstr. 16, D-52074 Aachen, Germany 00008 * phone: ++49-241-80-27910, 00009 * fax: ++49-241-80-22242 00010 * email: info@openwns.org 00011 * www: http://www.openwns.org 00012 * _____________________________________________________________________________ 00013 * 00014 * openWNS is free software; you can redistribute it and/or modify it under the 00015 * terms of the GNU Lesser General Public License version 2 as published by the 00016 * Free Software Foundation; 00017 * 00018 * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY 00019 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 00020 * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00021 * details. 00022 * 00023 * You should have received a copy of the GNU Lesser General Public License 00024 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00025 * 00026 ******************************************************************************/ 00027 00028 #ifndef WNS_TESTFIXTURE_HPP 00029 #define WNS_TESTFIXTURE_HPP 00030 00031 #include <WNS/Assure.hpp> 00032 #include <WNS/Conversion.hpp> 00033 00034 #include <WNS/events/scheduler/Interface.hpp> 00035 #include <WNS/rng/RNGen.hpp> 00036 00037 #include <cppunit/TestAssert.h> 00038 #include <cppunit/TestFixture.h> 00039 #include <cppunit/extensions/HelperMacros.h> 00040 00041 #include <cmath> 00042 00043 // Helper macros and functions for CPPUNIT 00044 00045 namespace wns { 00072 class TestFixture : 00073 public CppUnit::TestFixture 00074 { 00075 public: 00086 virtual void 00087 setUp(); 00088 00099 virtual void 00100 tearDown(); 00101 00102 protected: 00107 virtual void 00108 prepare() = 0; 00109 00114 virtual void 00115 cleanup() = 0; 00116 }; 00117 00118 00123 std::string 00124 failureMessage( 00125 const std::string& sourceFile, 00126 const std::string& sourceLine, 00127 const std::string& expected, 00128 const std::string& actual); 00129 00136 template <typename T> 00137 void assertMaxRelError( 00138 const T& expected, 00139 const T& actual, 00140 double maxRelativeError, 00141 const std::string sourceFile, 00142 const std::string sourceLine) 00143 { 00144 CPPUNIT_ASSERT_MESSAGE( failureMessage(sourceFile, 00145 sourceLine, 00146 wns::to<std::string>(expected), 00147 wns::to<std::string>(actual)), 00148 std::fabs(expected - actual) <= std::abs(expected * maxRelativeError) ); 00149 } 00150 00151 00166 namespace testsuite 00167 { 00171 std::string 00172 Default(); 00173 00177 std::string 00178 Disabled(); 00179 00183 std::string 00184 Performance(); 00185 00189 std::string 00190 Spike(); 00191 } 00192 00193 } 00194 00205 #define WNS_ASSERT_MAX_REL_ERROR(expected, actual, maxRelativeError) wns::assertMaxRelError((expected), (actual), (maxRelativeError), __FILE__, ::wns::to<std::string>(__LINE__)) 00206 00207 #endif // NOT defined WNS_CPPUNIT_HPP 00208 00209 #ifdef WNS_ASSURE_THROWS_EXCEPTION 00210 00218 #define WNS_ASSERT_ASSURE_EXCEPTION(expression) CPPUNIT_ASSERT_THROW(expression, wns::Assure::Exception) 00219 00229 #define WNS_ASSERT_ASSURE_NOT_NULL_EXCEPTION(expression) CPPUNIT_ASSERT_THROW(expression, wns::NullException) 00230 00231 #else 00232 00233 #define WNS_ASSERT_ASSURE_EXCEPTION(expression) 00234 #define WNS_ASSERT_ASSURE_NOT_NULL_EXCEPTION(expression) 00235 00236 #endif // NOT defined WNS_TESTFIXTURE_HPP
1.5.5