File: outside.cpp

package info (click to toggle)
libtut 0.0.20070706-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,148 kB
  • sloc: cpp: 3,588; xml: 137; makefile: 18; ansic: 9
file content (107 lines) | stat: -rw-r--r-- 1,370 bytes parent folder | download | duplicates (4)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include <tut/tut.hpp>
#include <string>

using std::string;

static void foo(const std::string& s)
{
    tut::ensure(s!="");
    tut::ensure_equals(s,"foo");
}

static void foo(float f)
{
    tut::ensure(f > 0.0f);
    tut::ensure_distance(f,1.0f,0.1f);
}

static void foo(int i)
{
    tut::ensure(i == 1);
    tut::ensure_equals(i,1);
}

static void foo()
{
    tut::fail();
}

namespace tut
{

static void foo(const std::string& s)
{
    ensure(s != "");
    ensure_equals(s, "foo");
}

static void foo(float f)
{
    ensure(f > 0.0f);
    ensure_distance(f, 1.0f, 0.1f);
}

static void foo(int i)
{
    ensure(i == 1);
    ensure_equals(i, 1);
}

static void foo()
{
    fail();
}

/**
 * Testing ensure*() and fail() outside test object.
 */
struct outside_test
{
};

typedef test_group<outside_test> tf;
typedef tf::object object;
tf ensure_outside("ensure/fail outside test object");

/**
 * Checks functions in namespace.
 */
template<>
template<>
void object::test<1>()
{
    tut::foo(string("foo"));
    tut::foo(1.05f);
    tut::foo(1);

    try
    {
        tut::foo();
    }
    catch (const failure&)
    {
    }
}

/**
 * Checks functions outside the namespace.
 */
template<>
template<>
void object::test<2>()
{
    ::foo(string("foo"));
    ::foo(1.05f);
    ::foo(1);

    try
    {
        ::foo();
    }
    catch (const failure&)
    {
    }
}

}