32 #include "gtest/internal/gtest-tuple.h" 34 #include "gtest/gtest.h" 40 using ::std::tr1::tuple;
41 using ::std::tr1::tuple_element;
42 using ::std::tr1::tuple_size;
46 TEST(tuple_element_Test, ReturnsElementType) {
47 StaticAssertTypeEq<int, tuple_element<0, tuple<int, char> >::type>();
48 StaticAssertTypeEq<int&, tuple_element<1, tuple<double, int&> >::type>();
49 StaticAssertTypeEq<bool, tuple_element<2, tuple<double, int, bool> >::type>();
54 TEST(tuple_size_Test, ReturnsNumberOfFields) {
55 EXPECT_EQ(0, +tuple_size<tuple<> >::value);
56 EXPECT_EQ(1, +tuple_size<tuple<void*> >::value);
57 EXPECT_EQ(1, +tuple_size<tuple<char> >::value);
58 EXPECT_EQ(1, +(tuple_size<tuple<tuple<int, double> > >::value));
59 EXPECT_EQ(2, +(tuple_size<tuple<int&, const char> >::value));
60 EXPECT_EQ(3, +(tuple_size<tuple<char*, void, const bool&> >::value));
64 TEST(ComparisonTest, ComparesWithSelf) {
65 const tuple<int, char, bool> a(5,
'a',
false);
72 TEST(ComparisonTest, ComparesEqualTuples) {
73 const tuple<int, bool> a(5,
true), b(5,
true);
80 TEST(ComparisonTest, ComparesUnequalTuplesWithoutReferenceFields) {
81 typedef tuple<const int, char> FooTuple;
83 const FooTuple a(0,
'x');
84 const FooTuple b(1,
'a');
89 const FooTuple
c(1,
'b');
96 TEST(ComparisonTest, ComparesUnequalTuplesWithReferenceFields) {
97 typedef tuple<int&, const char&> FooTuple;
101 const FooTuple a(i, ch);
104 const FooTuple b(j, ch);
110 const char ch2 =
'b';
111 const FooTuple
c(j, ch2);
119 TEST(ReferenceFieldTest, IsAliasOfReferencedVariable) {
121 tuple<bool, int&> t(
true, n);
125 <<
"Changing a underlying variable should update the reference field.";
130 <<
"The address of a reference field should equal the address of " 131 <<
"the underlying variable.";
135 <<
"Changing a reference field should update the underlying variable.";
140 TEST(TupleConstructorTest, DefaultConstructorDefaultInitializesEachField) {
153 tuple<int, double> a2, b2;
158 tuple<double, char, bool*> a3, b3;
164 tuple<int, int, int, int, int, int, int, int, int, int> a10, b10;
179 TEST(TupleConstructorTest, ConstructsFromFields) {
186 tuple<int, char> b(5,
'a');
192 tuple<bool, const int&>
c(
true, m);
198 TEST(TupleConstructorTest, CopyConstructor) {
199 tuple<double, bool> a(0.0,
true);
200 tuple<double, bool> b(a);
208 TEST(TupleConstructorTest, ConstructsFromDifferentTupleType) {
209 tuple<int, int, char> a(0, 1,
'a');
210 tuple<double, long, int> b(a);
218 TEST(TupleConstructorTest, ConstructsFromPair) {
219 ::std::pair<int, char> a(1,
'a');
220 tuple<int, char> b(a);
221 tuple<int, const char&>
c(a);
225 TEST(TupleAssignmentTest, AssignsToSameTupleType) {
226 const tuple<int, long> a(5, 7L);
235 TEST(TupleAssignmentTest, AssignsToDifferentTupleType) {
236 const tuple<int, long, bool> a(1, 7L,
true);
237 tuple<long, int, bool> b;
245 TEST(TupleAssignmentTest, AssignsFromPair) {
246 const ::std::pair<int, bool> a(5,
true);
261 typedef tuple<int, int, int, int, int, int, int, int, int, int> BigTuple;
264 a_(1, 0, 0, 0, 0, 0, 0, 0, 0, 2),
265 b_(1, 0, 0, 0, 0, 0, 0, 0, 0, 3) {}
271 TEST_F(BigTupleTest, Construction) {
277 TEST_F(BigTupleTest,
get) {
282 const BigTuple a(a_);
288 TEST_F(BigTupleTest, Comparisons) {
296 TEST(MakeTupleTest, WorksForScalarTypes) {
302 tuple<char, int, long> b;
309 TEST(MakeTupleTest, WorksForPointers) {
310 int a[] = { 1, 2, 3, 4 };
311 const char*
const str =
"hi";
314 tuple<const char*, int*> t;
TEST_F(TestInfoTest, Names)
#define EXPECT_TRUE(condition)
#define EXPECT_DOUBLE_EQ(expected, actual)
#define EXPECT_FALSE(condition)
TEST(GTestEnvVarTest, Dummy)
#define TEST(test_case_name, test_name)
bool StaticAssertTypeEq()
#define EXPECT_EQ(expected, actual)