OpenWalnut
1.4.0
|
00001 //--------------------------------------------------------------------------- 00002 // 00003 // Project: OpenWalnut ( http://www.openwalnut.org ) 00004 // 00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS 00006 // For more information see http://www.openwalnut.org/copying 00007 // 00008 // This file is part of OpenWalnut. 00009 // 00010 // OpenWalnut is free software: you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as published by 00012 // the Free Software Foundation, either version 3 of the License, or 00013 // (at your option) any later version. 00014 // 00015 // OpenWalnut is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 // GNU Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public License 00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>. 00022 // 00023 //--------------------------------------------------------------------------- 00024 00025 #ifndef WPROTOTYPED_TEST_H 00026 #define WPROTOTYPED_TEST_H 00027 00028 #include <string> 00029 00030 #include <cxxtest/TestSuite.h> 00031 00032 #include "../WPrototyped.h" 00033 00034 /** 00035 * Helper class derived from WPrototyped to check WPrototypes functionality. 00036 */ 00037 class SomePrototypeClass1: public WPrototyped 00038 { 00039 public: 00040 /** 00041 * Gets the name of this prototype. 00042 * 00043 * \return the name. 00044 */ 00045 virtual const std::string getName() const 00046 { 00047 return "test1"; 00048 }; 00049 00050 /** 00051 * Gets the description for this prototype. 00052 * 00053 * \return the description 00054 */ 00055 virtual const std::string getDescription() const 00056 { 00057 return "test1"; 00058 }; 00059 }; 00060 00061 00062 /** 00063 * Another helper class derived from WPrototyped. Used to check against \ref SomePrototypeClass1. 00064 */ 00065 class SomePrototypeClass2: public WPrototyped 00066 { 00067 public: 00068 /** 00069 * Gets the name of this prototype. 00070 * 00071 * \return the name. 00072 */ 00073 virtual const std::string getName() const 00074 { 00075 return "test2"; 00076 }; 00077 00078 /** 00079 * Gets the description for this prototype. 00080 * 00081 * \return the description 00082 */ 00083 virtual const std::string getDescription() const 00084 { 00085 return "test2"; 00086 }; 00087 }; 00088 00089 /** 00090 * Test WPrototyped 00091 */ 00092 class WPrototypedTest : public CxxTest::TestSuite 00093 { 00094 public: 00095 /** 00096 * Test the runtime type check 00097 */ 00098 void testType( void ) 00099 { 00100 SomePrototypeClass1 a; 00101 SomePrototypeClass2 b; 00102 00103 // check the type checking mechanism in WPrototyped 00104 00105 // these should be true 00106 TS_ASSERT( a.isA< WPrototyped >() ); 00107 TS_ASSERT( a.isA< SomePrototypeClass1 >() ); 00108 00109 TS_ASSERT( b.isA< WPrototyped >() ); 00110 TS_ASSERT( b.isA< SomePrototypeClass2 >() ); 00111 00112 // check against other types not in polymorphic relation to each other (except the base class) 00113 TS_ASSERT( !a.isA< SomePrototypeClass2 >() ); 00114 TS_ASSERT( !b.isA< SomePrototypeClass1 >() ); 00115 } 00116 }; 00117 00118 #endif // WPROTOTYPED_TEST_H 00119 00120