cipra  1.2.1
A C++11 Unit Testing Framework based on Test::More
 All Classes Namespaces Functions Variables Typedefs Pages
tests.hpp
1 // -*- c++ -*-
2 /* This file is a part of the cipra Unit Testing Framework.
3  * Copyright (C) 2012, Patrick M. Niedzielski.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  *
18  * 3. The names of its contributors may not be used to endorse or
19  * promote products derived from this software without specific
20  * prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
33  * OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 #ifndef CIPRA_TESTS_HPP
37 #define CIPRA_TESTS_HPP
38 
39 #include "tap13.hpp"
40 
41 #include <string>
42 #include <iosfwd>
43 #include <type_traits>
44 
45 #ifdef CIPRA_CXA_ABI
46 # include <cxxabi.h>
47 #endif
48 
49 namespace cipra {
50 
63  template <typename T, typename U>
64  struct equals_trait {
75  static inline bool equals(const T&, const U&);
76  };
77 
89  template <typename T>
90  struct print_trait {
101  static inline std::ostream& print(std::ostream&, const T&);
102  };
103 
127  class fixture {
129  struct skip_all_t {};
131  struct no_plan_t {};
132  protected:
140  static const skip_all_t skip_all;
144  static const no_plan_t no_plan;
146 
147  public:
164  inline int run();
165 
166  protected:
175  inline fixture();
183  inline fixture(const fixture &);
184 
196  inline void plan(int total);
206  inline void plan(skip_all_t,
207  std::string reason = std::string(""));
208 
217 
227  void diag(std::string message);
237  void note(std::string message);
251  template <typename T>
252  void explain(T object);
254 
267 
290  template<typename funcT>
291  void ok(funcT expr, std::string name = std::string(""));
315  template<typename T, typename U>
316  void is(T got, U expected, std::string name = std::string(""));
339  template<typename T, typename U>
340  void isnt(T got, U expected, std::string name = std::string(""));
361  template<typename funcT>
362  void throws(funcT expr, std::string name = std::string(""));
387  template<typename exceptionT, typename funcT>
388  void throws(funcT expr, std::string name = std::string(""));
410  template<typename funcT>
411  void nothrows(funcT expr, std::string name = std::string(""));
436  template<typename exceptionT, typename funcT>
437  void nothrows(funcT expr, std::string name = std::string(""));
463 #if _MSC_VER >= 1700 && _MSC_VER < 1800 // use implementation defined macros
464 #define NEW_OK(TEMPLATE_LIST, PADDING_LIST, LIST, COMMA, X1, X2, X3, X4) \
465  template<typename T COMMA LIST(_CLASS_TYPE)> \
466  T new_ok(LIST(_TYPE_REFREF_ARG));
467 
468  _VARIADIC_EXPAND_0X(NEW_OK, , , , )
469 #undef NEW_OK
470 #else
471  template<typename T, typename... argsT>
472  T new_ok(argsT&&... args);
473 #endif
474 
486  void pass(std::string name = std::string(""));
499  void fail(std::string name = std::string(""));
501 
502  private:
511  inline virtual void test();
512 
532  inline std::string current_exception_name();
533 
534  counter<int> test_counter;
535  };
536 }
537 
538 #include "tests.ipp"
539 
540 #endif // #ifdef CIPRA_TESTS_HPP