monotone

monotone Mtn Source Tree

Root/unit_tests.hh

1#ifndef __UNIT_TESTS__
2#define __UNIT_TESTS__
3
4// Copyright (C) 2002 Graydon Hoare <graydon@pobox.com>
5//
6// This program is made available under the GNU GPL version 2.0 or
7// greater. See the accompanying file COPYING for details.
8//
9// This program is distributed WITHOUT ANY WARRANTY; without even the
10// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11// PURPOSE.
12
13#include <boost/test/test_tools.hpp>
14
15// strangely this was left out. perhaps it'll arrive later?
16#ifndef BOOST_CHECK_NOT_THROW
17#define BOOST_CHECK_NOT_THROW(statement, exception) \
18 do \
19 { \
20 try \
21 { \
22 statement; \
23 BOOST_CHECK_MESSAGE(true, "exception "#exception" did not occur"); \
24 } \
25 catch(exception const &) \
26 { \
27 BOOST_ERROR("exception "#exception" occurred"); \
28 } \
29 } while (0)
30#endif
31
32// Declarative mechanism for specifying unit tests, similar to
33// auto_unit_test in boost, but more suited to our needs.
34namespace unit_test {
35 struct unit_test_case
36 {
37 unit_test_case(char const * group,
38 char const *test,
39 void (*func)());
40
41 };
42}
43
44// The names of the test functions must not collide with each other or with
45// names of symbols in the code being tested, despite their being in a
46// separate namespace, so that references _from_ the test functions _to_ the
47// code under test resolve correctly.
48#define UNIT_TEST(GROUP, TEST) \
49 namespace unit_test { \
50 static void t_##GROUP##_##TEST(); \
51 static unit_test_case r_##GROUP##_##TEST \
52 (#GROUP, #TEST, t_##GROUP##_##TEST); \
53 } \
54 static void unit_test::t_##GROUP##_##TEST()
55
56// Local Variables:
57// mode: C++
58// fill-column: 76
59// c-file-style: "gnu"
60// indent-tabs-mode: nil
61// End:
62// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:
63
64#endif

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status