Debian Codegraph @

test/test.h

raw symbols SCIP
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2010-2011 Artyom Beilis (Tonkikh) <[email protected]>
4 //
5 // Distributed under:
6 //
7 // the Boost Software License, Version 1.0.
8 // (See accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
10 //
11 // or (at your opinion) under:
12 //
13 // The MIT License
14 // (See accompanying file MIT.txt or a copy at
15 // http://www.opensource.org/licenses/mit-license.php)
16 //
17 ///////////////////////////////////////////////////////////////////////////////
18 #ifndef CPPDB_TEST_H
19 #define CPPDB_TEST_H
20 #include <sstream>
21 #include <iostream>
22 #include <stdexcept>
23 #include <memory>
24 #include <stdlib.h>
25
26 int last_line = 0;
27 int passed = 0;
28 int failed = 0;
29
30 #define TEST(x) do { last_line = __LINE__; if(x) { passed ++; break; } failed++; std::cerr<<"Failed in " << __LINE__ <<' '<< #x << std::endl; } while(0)
31
32 #define THROWS(x,ex) do { last_line = __LINE__; try { x ; failed++; std::cerr << "Failed in " << __LINE__ <<' '<< #x << std::endl; }catch(ex const &/*un*/) { passed++; } } while(0)
33 #endif
34
35 #define CATCH_BLOCK() catch(std::exception const &e) { std::cerr << "Fail " << e.what() << std::endl; std::cerr << "Last tested line " << last_line << std::endl; failed++; }
36 #define SUMMARY() do {\
37 std::cout << "Tests: " << passed+failed << " failed: " << failed << std::endl; \
38 if(failed > 0) { std::cerr << "Fail!" << std::endl; return 1; } \
39 std::cout << "Ok" << std::endl; \
40 return 0; \
41 } while(0)
42