source: liblaziness/test/test_base.h @ 25

Last change on this file since 25 was 4, checked in by artyom, 13 years ago

liblaziness

File size: 878 bytes
Line 
1#ifndef __TEST_BASE_H__
2#define __TEST_BASE_H__
3#include <exception>
4#include <string>
5#include <sstream>
6
7void assertTick();
8
9class TestFailed : public std::exception
10{
11        public:
12                TestFailed(const std::string& message) throw();
13                virtual ~TestFailed() throw();
14                virtual const char* what() const throw();
15        private:
16                std::string message;
17};
18
19template<typename T>
20void assertEq(T val1, T val2, const std::string& errorMessage)
21{
22        if (val1 != val2)
23        {
24                throw TestFailed(errorMessage);
25        }
26        assertTick();
27}
28
29class StringStream : public std::stringstream
30{
31        public:
32                StringStream& empty();
33};
34
35template<typename TException>
36class assertException
37{
38        public:
39                template<typename TFun>
40                static void thrown(TFun fun, const std::string& errorMessage)
41                {
42                        try
43                        {
44                                fun();
45                                throw TestFailed(errorMessage);
46                        }
47                        catch (TException& ex) {
48                                assertTick();
49                        }
50                }
51};
52#endif
Note: See TracBrowser for help on using the repository browser.