Welcome to mirror list, hosted at ThFree Co, Russian Federation.

testing.hpp « testing - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2f1ffa19086c20de5211c92600afc5656f94ca84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#pragma once
#include "testregister.hpp"
#include "../base/assert.hpp"
#include "../base/base.hpp"
#include "../base/exception.hpp"
#include "../base/math.hpp"
#include "../base/src_point.hpp"
#include "../std/iostream.hpp"
#include "../std/string.hpp"

#define UNIT_TEST(name) \
    void UnitTest_##name();	\
        TestRegister g_TestRegister_##name(#name, __FILE__, &UnitTest_##name); \
    void UnitTest_##name()

DECLARE_EXCEPTION(TestFailureException, RootException);

namespace my
{
  inline void OnTestFailed(SrcPoint const & srcPoint, string const & msg)
  {
    cerr << "FAILED" << endl << srcPoint.FileName() << ":" << srcPoint.Line() << " " << msg << endl;
    MYTHROW(TestFailureException, (srcPoint.FileName(), srcPoint.Line(), msg));
  }
}

#define TEST(X, msg) if (X) {} else { \
  ::my::OnTestFailed(SRC(), ::my::impl::MergeMsg("TEST("#X")", ::my::impl::Message msg));}
#define TEST_EQUAL(X, Y, msg) if ((X) == (Y)) {} else { \
  ::my::OnTestFailed(SRC(), ::my::impl::MergeMsg("TEST("#X" == "#Y")", \
                                                 ::my::impl::Message(X, Y), \
                                                 ::my::impl::Message msg));}
#define TEST_NOT_EQUAL(X, Y, msg) if ((X) != (Y)) {} else { \
  ::my::OnTestFailed(SRC(), ::my::impl::MergeMsg("TEST("#X" != "#Y")", \
                                                 ::my::impl::Message(X, Y), \
                                                 ::my::impl::Message msg));}
#define TEST_LESS(X, Y, msg) if ((X) < (Y)) {} else { \
  ::my::OnTestFailed(SRC(), ::my::impl::MergeMsg("TEST("#X" < "#Y")", \
                                                 ::my::impl::Message(X, Y), \
                                                 ::my::impl::Message msg));}
#define TEST_LESS_OR_EQUAL(X, Y, msg) if ((X) <= (Y)) {} else { \
  ::my::OnTestFailed(SRC(), ::my::impl::MergeMsg("TEST("#X" <= "#Y")", \
                                                 ::my::impl::Message(X, Y), \
                                                 ::my::impl::Message msg));}
#define TEST_GREATER(X, Y, msg) if ((X) > (Y)) {} else { \
  ::my::OnTestFailed(SRC(), ::my::impl::MergeMsg("TEST("#X" > "#Y")", \
                                                 ::my::impl::Message(X, Y), \
                                                 ::my::impl::Message msg));}
#define TEST_GREATER_OR_EQUAL(X, Y, msg) if ((X) >= (Y)) {} else { \
  ::my::OnTestFailed(SRC(), ::my::impl::MergeMsg("TEST("#X" >= "#Y")", \
                                                 ::my::impl::Message(X, Y), \
                                                 ::my::impl::Message msg));}
#define TEST_ALMOST_EQUAL(X, Y, msg) if (::my::AlmostEqual(X, Y)) {} else { \
  ::my::OnTestFailed(SRC(), ::my::impl::MergeMsg("TEST(my::AlmostEqual("#X", "#Y")", \
                                                 ::my::impl::Message(X, Y), \
                                                 ::my::impl::Message msg));}
#define TEST_NOT_ALMOST_EQUAL(X, Y, msg) if (!::my::AlmostEqual(X, Y)) {} else { \
  ::my::OnTestFailed(SRC(), ::my::impl::MergeMsg("TEST(!my::AlmostEqual("#X", "#Y")", \
                                                 ::my::impl::Message(X, Y), \
                                                 ::my::impl::Message msg));}