OpenWalnut  1.5.0dev
WPrototyped_test.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WPROTOTYPED_TEST_H
26 #define WPROTOTYPED_TEST_H
27 
28 #include <string>
29 
30 #include <cxxtest/TestSuite.h>
31 
32 #include "../WPrototyped.h"
33 
34 /**
35  * Helper class derived from WPrototyped to check WPrototypes functionality.
36  */
38 {
39 public:
40  /**
41  * Gets the name of this prototype.
42  *
43  * \return the name.
44  */
45  virtual const std::string getName() const
46  {
47  return "test1";
48  };
49 
50  /**
51  * Gets the description for this prototype.
52  *
53  * \return the description
54  */
55  virtual const std::string getDescription() const
56  {
57  return "test1";
58  };
59 };
60 
61 
62 /**
63  * Another helper class derived from \ref SomePrototypeClass1. Used to check against \ref SomePrototypeClass1.
64  */
66 {
67 public:
68  /**
69  * Gets the name of this prototype.
70  *
71  * \return the name.
72  */
73  virtual const std::string getName() const
74  {
75  return "test2";
76  };
77 
78  /**
79  * Gets the description for this prototype.
80  *
81  * \return the description
82  */
83  virtual const std::string getDescription() const
84  {
85  return "test2";
86  };
87 };
88 
89 /**
90  * Another helper class derived from WPrototyped. Used to check against \ref SomePrototypeClass1.
91  */
93 {
94 public:
95  /**
96  * Gets the name of this prototype.
97  *
98  * \return the name.
99  */
100  virtual const std::string getName() const
101  {
102  return "test3";
103  };
104 
105  /**
106  * Gets the description for this prototype.
107  *
108  * \return the description
109  */
110  virtual const std::string getDescription() const
111  {
112  return "test3";
113  };
114 };
115 
116 /**
117  * Test WPrototyped
118  */
119 class WPrototypedTest : public CxxTest::TestSuite
120 {
121 public:
122  /**
123  * Test the runtime type check
124  */
125  void testType( void )
126  {
130 
131  // check the type checking mechanism in WPrototyped
132 
133  // these should be true
134  TS_ASSERT( a.isA< SomePrototypeClass1 >() );
135  TS_ASSERT( b.isA< SomePrototypeClass2 >() );
136  TS_ASSERT( b.isA< SomePrototypeClass1 >() );
137 
138  // The following lines would cause a warning
139  // "nonnull argument 'this' compared to NULL"
140  // because they would be always true,
141  // thus they are commented out.
142  //TS_ASSERT( a.isA< WPrototyped >() );
143  //TS_ASSERT( b.isA< WPrototyped >() );
144  //TS_ASSERT( c.isA< WPrototyped >() );
145 
146  // check against other types not in polymorphic relation to each other (except the base class)
147  TS_ASSERT( !a.isA< SomePrototypeClass2 >() );
148  TS_ASSERT( !a.isA< SomePrototypeClass3 >() );
149  TS_ASSERT( !b.isA< SomePrototypeClass3 >() );
150  TS_ASSERT( !c.isA< SomePrototypeClass1 >() );
151  TS_ASSERT( !c.isA< SomePrototypeClass2 >() );
152  }
153 };
154 
155 #endif // WPROTOTYPED_TEST_H
Helper class derived from WPrototyped to check WPrototypes functionality.
virtual const std::string getName() const
Gets the name of this prototype.
virtual const std::string getDescription() const
Gets the description for this prototype.
Another helper class derived from SomePrototypeClass1.
virtual const std::string getName() const
Gets the name of this prototype.
virtual const std::string getDescription() const
Gets the description for this prototype.
Another helper class derived from WPrototyped.
virtual const std::string getDescription() const
Gets the description for this prototype.
virtual const std::string getName() const
Gets the name of this prototype.
Test WPrototyped.
void testType(void)
Test the runtime type check.
Interface class for the concept "Prototype".
Definition: WPrototyped.h:38
bool isA()
Checks whether the actual prototype has the specified runtime type.
Definition: WPrototyped.h:77