Teuchos - Trilinos Tools Package  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Teuchos_UnitTestHelpers.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Teuchos: Common Tools Package
5 // Copyright (2004) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #ifndef TEUCHOS_UNIT_TEST_HELPERS_HPP
43 #define TEUCHOS_UNIT_TEST_HELPERS_HPP
44 
45 
57 #include "Teuchos_UnitTestBase.hpp"
58 #include "Teuchos_StaticSetupMacro.hpp"
59 
60 
83 #define TEUCHOS_UNIT_TEST(TEST_GROUP, TEST_NAME) \
84  class TEST_GROUP##_##TEST_NAME##_UnitTest : public Teuchos::UnitTestBase \
85  { \
86  public: \
87  TEST_GROUP##_##TEST_NAME##_UnitTest() \
88  : Teuchos::UnitTestBase( #TEST_GROUP, #TEST_NAME ) \
89  {} \
90  virtual void runUnitTestImpl( Teuchos::FancyOStream &out, bool &success ) const; \
91  virtual std::string unitTestFile() const { return __FILE__; } \
92  virtual long int unitTestFileLineNumber() const { return __LINE__; } \
93  }; \
94  \
95  TEST_GROUP##_##TEST_NAME##_UnitTest \
96  instance_##TEST_GROUP##_##TEST_NAME##_UnitTest; \
97  \
98  void TEST_GROUP##_##TEST_NAME##_UnitTest::runUnitTestImpl( \
99  Teuchos::FancyOStream &out, bool &success ) const \
100 
101 
160 #define TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL(TEST_GROUP, TEST_NAME, TYPE) \
161  template<class TYPE> \
162  class TEST_GROUP##_##TEST_NAME##_UnitTest : public Teuchos::UnitTestBase \
163  { \
164  public: \
165  TEST_GROUP##_##TEST_NAME##_UnitTest(const std::string& typeName) \
166  : Teuchos::UnitTestBase( std::string(#TEST_GROUP)+"_"+typeName, #TEST_NAME ) \
167  {} \
168  void runUnitTestImpl( Teuchos::FancyOStream &out, bool &success ) const; \
169  virtual std::string unitTestFile() const { return __FILE__; } \
170  virtual long int unitTestFileLineNumber() const { return __LINE__; } \
171  }; \
172  \
173  template<class TYPE> \
174  void TEST_GROUP##_##TEST_NAME##_UnitTest<TYPE>::runUnitTestImpl( \
175  Teuchos::FancyOStream &out, bool &success ) const \
176 
177 
187 #define TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT(TEST_GROUP, TEST_NAME, TYPE) \
188  \
189  template class TEST_GROUP##_##TEST_NAME##_UnitTest<TYPE>; \
190  TEST_GROUP##_##TEST_NAME##_UnitTest<TYPE> \
191  instance_##TEST_GROUP##_##TYPE##_##TEST_NAME##_UnitTest(#TYPE);
192 
193 
194 #ifdef HAVE_TEUCHOS_FLOAT
195 # define TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT_FLOAT(TEST_GROUP, TEST_NAME)\
196  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT(TEST_GROUP, TEST_NAME, float)
197 #else
198 # define TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT_FLOAT(TEST_GROUP, TEST_NAME)
199 #endif
200 
201 #define TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT_DOUBLE(TEST_GROUP, TEST_NAME)\
202  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT(TEST_GROUP, TEST_NAME, double)
203 
204 #if defined(HAVE_TEUCHOS_COMPLEX) && defined(HAVE_TEUCHOS_FLOAT)
205 # define TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT_COMPLEX_FLOAT(TEST_GROUP, TEST_NAME)\
206  typedef std::complex<float> ComplexFloat; \
207  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT(TEST_GROUP, TEST_NAME, ComplexFloat)
208 #else
209 # define TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT_COMPLEX_FLOAT(TEST_GROUP, TEST_NAME)
210 #endif
211 
212 #ifdef HAVE_TEUCHOS_COMPLEX
213 # define TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT_COMPLEX_DOUBLE(TEST_GROUP, TEST_NAME)\
214  typedef std::complex<double> ComplexDouble; \
215  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT(TEST_GROUP, TEST_NAME, ComplexDouble)
216 #else
217 # define TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT_COMPLEX_DOUBLE(TEST_GROUP, TEST_NAME)
218 #endif
219 
220 
226 #define TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT_REAL_SCALAR_TYPES(TEST_GROUP, TEST_NAME)\
227  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT_FLOAT(TEST_GROUP, TEST_NAME) \
228  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT_DOUBLE(TEST_GROUP, TEST_NAME)
229 
230 
235 #define TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT_SCALAR_TYPES(TEST_GROUP, TEST_NAME)\
236  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT_FLOAT(TEST_GROUP, TEST_NAME) \
237  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT_DOUBLE(TEST_GROUP, TEST_NAME) \
238  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT_COMPLEX_FLOAT(TEST_GROUP, TEST_NAME) \
239  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT_COMPLEX_DOUBLE(TEST_GROUP, TEST_NAME)
240 
241 
302 #define TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL(TEST_GROUP, TEST_NAME, TYPE1, TYPE2) \
303  template<class TYPE1, class TYPE2> \
304  class TEST_GROUP##_##TEST_NAME##_UnitTest : public Teuchos::UnitTestBase \
305  { \
306  public: \
307  TEST_GROUP##_##TEST_NAME##_UnitTest( \
308  const std::string& type1Name, \
309  const std::string& type2Name \
310  ) \
311  :Teuchos::UnitTestBase( \
312  std::string(#TEST_GROUP)+"_"+type1Name+"_"+type2Name, #TEST_NAME ) \
313  {} \
314  void runUnitTestImpl( Teuchos::FancyOStream &out, bool &success ) const; \
315  virtual std::string unitTestFile() const { return __FILE__; } \
316  virtual long int unitTestFileLineNumber() const { return __LINE__; } \
317  }; \
318  \
319  template<class TYPE1, class TYPE2> \
320  void TEST_GROUP##_##TEST_NAME##_UnitTest<TYPE1,TYPE2>::runUnitTestImpl( \
321  Teuchos::FancyOStream &out, bool &success ) const \
322 
323 
333 #define TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT(TEST_GROUP, TEST_NAME, TYPE1, TYPE2) \
334  \
335  template class TEST_GROUP##_##TEST_NAME##_UnitTest<TYPE1, TYPE2 >; \
336  TEST_GROUP##_##TEST_NAME##_UnitTest<TYPE1, TYPE2 > \
337  instance_##TEST_GROUP##_##TYPE1##_##TYPE2##_##TEST_NAME##_UnitTest(#TYPE1,#TYPE2);
338 
339 
344 #define TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL(TEST_GROUP, TEST_NAME, TYPE1, TYPE2, TYPE3) \
345  template<class TYPE1, class TYPE2, class TYPE3> \
346  class TEST_GROUP##_##TEST_NAME##_UnitTest : public Teuchos::UnitTestBase \
347  { \
348  public: \
349  TEST_GROUP##_##TEST_NAME##_UnitTest( \
350  const std::string& type1Name, \
351  const std::string& type2Name, \
352  const std::string& type3Name \
353  ) \
354  :Teuchos::UnitTestBase( \
355  std::string(#TEST_GROUP)+"_"+type1Name+"_"+type2Name+"_"+type3Name, #TEST_NAME ) \
356  {} \
357  void runUnitTestImpl( Teuchos::FancyOStream &out, bool &success ) const; \
358  virtual std::string unitTestFile() const { return __FILE__; } \
359  virtual long int unitTestFileLineNumber() const { return __LINE__; } \
360  }; \
361  \
362  template<class TYPE1, class TYPE2, class TYPE3> \
363  void TEST_GROUP##_##TEST_NAME##_UnitTest<TYPE1,TYPE2,TYPE3>::runUnitTestImpl( \
364  Teuchos::FancyOStream &out, bool &success ) const \
365 
366 
371 #define TEUCHOS_UNIT_TEST_TEMPLATE_3_INSTANT(TEST_GROUP, TEST_NAME, TYPE1, TYPE2, TYPE3) \
372  \
373  template class TEST_GROUP##_##TEST_NAME##_UnitTest<TYPE1, TYPE2, TYPE3 >; \
374  TEST_GROUP##_##TEST_NAME##_UnitTest<TYPE1, TYPE2, TYPE3 > \
375  instance_##TEST_GROUP##_##TYPE1##_##TYPE2##_##TYPE3##_##TEST_NAME##_UnitTest(#TYPE1,#TYPE2,#TYPE3);
376 
377 
382 #define TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(TEST_GROUP, TEST_NAME, TYPE1, TYPE2, TYPE3, TYPE4) \
383  template<class TYPE1, class TYPE2, class TYPE3, class TYPE4> \
384  class TEST_GROUP##_##TEST_NAME##_UnitTest : public Teuchos::UnitTestBase \
385  { \
386  public: \
387  TEST_GROUP##_##TEST_NAME##_UnitTest( \
388  const std::string& type1Name, \
389  const std::string& type2Name, \
390  const std::string& type3Name, \
391  const std::string& type4Name \
392  ) \
393  :Teuchos::UnitTestBase( \
394  std::string(#TEST_GROUP)+"_"+type1Name+"_"+type2Name+"_"+type3Name+"_"+type4Name, #TEST_NAME ) \
395  {} \
396  void runUnitTestImpl( Teuchos::FancyOStream &out, bool &success ) const; \
397  virtual std::string unitTestFile() const { return __FILE__; } \
398  virtual long int unitTestFileLineNumber() const { return __LINE__; } \
399  }; \
400  \
401  template<class TYPE1, class TYPE2, class TYPE3, class TYPE4> \
402  void TEST_GROUP##_##TEST_NAME##_UnitTest<TYPE1,TYPE2,TYPE3,TYPE4>::runUnitTestImpl( \
403  Teuchos::FancyOStream &out, bool &success ) const \
404 
405 
410 #define TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(TEST_GROUP, TEST_NAME, TYPE1, TYPE2, TYPE3, TYPE4) \
411  \
412  template class TEST_GROUP##_##TEST_NAME##_UnitTest<TYPE1, TYPE2, TYPE3, TYPE4 >; \
413  TEST_GROUP##_##TEST_NAME##_UnitTest<TYPE1, TYPE2, TYPE3, TYPE4 > \
414  instance_##TEST_GROUP##_##TYPE1##_##TYPE2##_##TYPE3##_##TYPE4##_##TEST_NAME##_UnitTest(#TYPE1,#TYPE2,#TYPE3,#TYPE4);
415 
416 
417 #endif // TEUCHOS_UNIT_TEST_HELPERS_HPP
Unit testing support.