-
Notifications
You must be signed in to change notification settings - Fork 67
/
references.cpp
86 lines (68 loc) · 2.05 KB
/
references.cpp
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
/**
* @file /src/test/references.cpp
*
* @brief Unit Test for reference wrappers and associated tools.
*
* @date July 2009
**/
/*****************************************************************************
** Includes
*****************************************************************************/
#include <gtest/gtest.h>
#include "../../include/ecl/utilities/references.hpp"
/**
* @cond DO_NOT_DOXYGEN
*/
/*****************************************************************************
** Classes
*****************************************************************************/
namespace ecl {
namespace utilities {
namespace tests {
class ReferenceDummy {
public:
int i;
};
}}}
/*****************************************************************************
** Using
*****************************************************************************/
using ecl::ReferenceWrapper;
using ecl::cref;
using ecl::ref;
using ecl::is_reference_wrapper;
using ecl::utilities::tests::ReferenceDummy;
/*****************************************************************************
** Tests
*****************************************************************************/
TEST(Reference,usage) {
int i = 3;
ReferenceWrapper<int> wrapper(i);
int &j = wrapper;
EXPECT_EQ(j,3);
}
TEST(Reference,traits) {
// Workaround for undefined reference error. Why it happens if used
// directly in the gtest macros, I haven't root caused.
bool result1 = is_reference_wrapper< ReferenceWrapper<int> >::value;
EXPECT_TRUE(result1);
bool result2 = is_reference_wrapper<int>::value;
EXPECT_FALSE(result2);
}
TEST(Reference,functions) {
int i = 3;
ReferenceWrapper<int> refd = ref(i);
ReferenceWrapper<int const> crefd = cref(i);
EXPECT_EQ(3,refd);
EXPECT_EQ(3,crefd);
}
/*****************************************************************************
** Main
*****************************************************************************/
int main(int argc, char **argv) {
testing::InitGoogleTest(&argc,argv);
return RUN_ALL_TESTS();
}
/**
* @endcond
*/