cipra: tests.hpp Source File

| cipra 1.2.1 A C++11 Unit Testing Framework based on Test::More

- Main Page
- Related Pages
- Namespaces
- Classes

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
cipra::counter< int >
cipra::fixture::plan
void plan(int total)
Sets the number of tests you plan to have run by the end of this fixture.
cipra::fixture::fixture
fixture()
Construct a new test fixture with no plan.
cipra::fixture::skip_all
static const skip_all_t skip_all
The constant of the type to skip all test cases.
Definition: tests.hpp:142
cipra::fixture::pass
void pass(std::string name=std::string(""))
Say that some test has passed.
cipra::fixture::run
int run()
Run this test fixture and produce output from the user-defined test() method.
cipra::fixture::is
void is(T got, U expected, std::string name=std::string(""))
Assert that some value is the same as another value.
cipra::fixture::explain
void explain(T object)
Pretty-print an object to the test output using the object&#39;s operator&lt;&lt;().
cipra::equals_trait
A type trait that users can specialize to tell how to equality compare two different types...
Definition: tests.hpp:64
cipra::fixture::ok
void ok(funcT expr, std::string name=std::string(""))
Assert that some expression returns a value that when converted to a bool will be true...
cipra::fixture::diag
void diag(std::string message)
Print a diagnostic message to the test output.
cipra::fixture::no_plan
static const no_plan_t no_plan
The constant of the type to have no plan in the test.
Definition: tests.hpp:144
cipra::fixture::fail
void fail(std::string name=std::string(""))
Say that some test has failed.
cipra::fixture::new_ok
T new_ok(argsT &&...args)
Assert that the constructor of an object can be constructed without throwing an exception of any type...
cipra::print_trait
A type trait that users can specialize to tell how to stream an object to a std::ostream.
Definition: tests.hpp:90
cipra::print_trait::print
static std::ostream & print(std::ostream &, const T &)
Pretty-prints an object to a std::ostream.
cipra::fixture::isnt
void isnt(T got, U expected, std::string name=std::string(""))
Assert that some value is not the same as another value.
cipra::fixture
The base class for any test fixtures.
Definition: tests.hpp:127
cipra::fixture::note
void note(std::string message)
Print out a non-diagnostic note to the test output.
cipra::fixture::nothrows
void nothrows(funcT expr, std::string name=std::string(""))
Assert that some expression does not throw an exception of any type.
cipra::equals_trait::equals
static bool equals(const T &, const U &)
Returns whether the left hand side equals the right hand side.