Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: base/tuple_unittest.cc

Issue 2023243002: Remove base::Tuple (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: IWYU Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/tuple.h" 5 #include "base/tuple.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace base { 10 namespace base {
(...skipping 14 matching lines...) Expand all
25 struct Addz { 25 struct Addz {
26 Addz() { } 26 Addz() { }
27 void DoAdd(int a, int b, int c, int d, int e, int* res) { 27 void DoAdd(int a, int b, int c, int d, int e, int* res) {
28 *res = a + b + c + d + e; 28 *res = a + b + c + d + e;
29 } 29 }
30 }; 30 };
31 31
32 } // namespace 32 } // namespace
33 33
34 TEST(TupleTest, Basic) { 34 TEST(TupleTest, Basic) {
35 base::Tuple<> t0 = base::MakeTuple(); 35 std::tuple<> t0 = std::make_tuple();
36 ALLOW_UNUSED_LOCAL(t0); 36 ALLOW_UNUSED_LOCAL(t0);
37 base::Tuple<int> t1(1); 37 std::tuple<int> t1(1);
38 base::Tuple<int, const char*> t2 = 38 std::tuple<int, const char*> t2 =
39 base::MakeTuple(1, static_cast<const char*>("wee")); 39 std::make_tuple(1, static_cast<const char*>("wee"));
40 base::Tuple<int, int, int> t3(1, 2, 3); 40 std::tuple<int, int, int> t3(1, 2, 3);
41 base::Tuple<int, int, int, int*> t4(1, 2, 3, &get<0>(t1)); 41 std::tuple<int, int, int, int*> t4(1, 2, 3, &std::get<0>(t1));
42 base::Tuple<int, int, int, int, int*> t5(1, 2, 3, 4, &get<0>(t4)); 42 std::tuple<int, int, int, int, int*> t5(1, 2, 3, 4, &std::get<0>(t4));
43 base::Tuple<int, int, int, int, int, int*> t6(1, 2, 3, 4, 5, &get<0>(t4)); 43 std::tuple<int, int, int, int, int, int*> t6(1, 2, 3, 4, 5, &std::get<0>(t4));
44 44
45 EXPECT_EQ(1, get<0>(t1)); 45 EXPECT_EQ(1, std::get<0>(t1));
46 EXPECT_EQ(1, get<0>(t2)); 46 EXPECT_EQ(1, std::get<0>(t2));
47 EXPECT_EQ(1, get<0>(t3)); 47 EXPECT_EQ(1, std::get<0>(t3));
48 EXPECT_EQ(2, get<1>(t3)); 48 EXPECT_EQ(2, std::get<1>(t3));
Nico 2016/06/02 16:56:18 hm, do we need to test std::tuple and std::get?
tzik 2016/06/03 04:44:19 Let me remove this part.
49 EXPECT_EQ(3, get<2>(t3)); 49 EXPECT_EQ(3, std::get<2>(t3));
50 EXPECT_EQ(1, get<0>(t4)); 50 EXPECT_EQ(1, std::get<0>(t4));
51 EXPECT_EQ(2, get<1>(t4)); 51 EXPECT_EQ(2, std::get<1>(t4));
52 EXPECT_EQ(3, get<2>(t4)); 52 EXPECT_EQ(3, std::get<2>(t4));
53 EXPECT_EQ(1, get<0>(t5)); 53 EXPECT_EQ(1, std::get<0>(t5));
54 EXPECT_EQ(2, get<1>(t5)); 54 EXPECT_EQ(2, std::get<1>(t5));
55 EXPECT_EQ(3, get<2>(t5)); 55 EXPECT_EQ(3, std::get<2>(t5));
56 EXPECT_EQ(4, get<3>(t5)); 56 EXPECT_EQ(4, std::get<3>(t5));
57 EXPECT_EQ(1, get<0>(t6)); 57 EXPECT_EQ(1, std::get<0>(t6));
58 EXPECT_EQ(2, get<1>(t6)); 58 EXPECT_EQ(2, std::get<1>(t6));
59 EXPECT_EQ(3, get<2>(t6)); 59 EXPECT_EQ(3, std::get<2>(t6));
60 EXPECT_EQ(4, get<3>(t6)); 60 EXPECT_EQ(4, std::get<3>(t6));
61 EXPECT_EQ(5, get<4>(t6)); 61 EXPECT_EQ(5, std::get<4>(t6));
62 62
63 EXPECT_EQ(1, get<0>(t1)); 63 EXPECT_EQ(1, std::get<0>(t1));
64 DispatchToFunction(&DoAdd, t4); 64 DispatchToFunction(&DoAdd, t4);
65 EXPECT_EQ(6, get<0>(t1)); 65 EXPECT_EQ(6, std::get<0>(t1));
66 66
67 int res = 0; 67 int res = 0;
68 DispatchToFunction(&DoAdd, base::MakeTuple(9, 8, 7, &res)); 68 DispatchToFunction(&DoAdd, std::make_tuple(9, 8, 7, &res));
69 EXPECT_EQ(24, res); 69 EXPECT_EQ(24, res);
70 70
71 Addy addy; 71 Addy addy;
72 EXPECT_EQ(1, get<0>(t4)); 72 EXPECT_EQ(1, std::get<0>(t4));
73 DispatchToMethod(&addy, &Addy::DoAdd, t5); 73 DispatchToMethod(&addy, &Addy::DoAdd, t5);
74 EXPECT_EQ(10, get<0>(t4)); 74 EXPECT_EQ(10, std::get<0>(t4));
75 75
76 Addz addz; 76 Addz addz;
77 EXPECT_EQ(10, get<0>(t4)); 77 EXPECT_EQ(10, std::get<0>(t4));
78 DispatchToMethod(&addz, &Addz::DoAdd, t6); 78 DispatchToMethod(&addz, &Addz::DoAdd, t6);
79 EXPECT_EQ(15, get<0>(t4)); 79 EXPECT_EQ(15, std::get<0>(t4));
80 } 80 }
81 81
82 namespace { 82 namespace {
83 83
84 struct CopyLogger { 84 struct CopyLogger {
85 CopyLogger() { ++TimesConstructed; } 85 CopyLogger() { ++TimesConstructed; }
86 CopyLogger(const CopyLogger& tocopy) { ++TimesConstructed; ++TimesCopied; } 86 CopyLogger(const CopyLogger& tocopy) { ++TimesConstructed; ++TimesCopied; }
87 ~CopyLogger() { } 87 ~CopyLogger() { }
88 88
89 static int TimesCopied; 89 static int TimesCopied;
(...skipping 14 matching lines...) Expand all
104 } // namespace 104 } // namespace
105 105
106 TEST(TupleTest, Copying) { 106 TEST(TupleTest, Copying) {
107 CopyLogger logger; 107 CopyLogger logger;
108 EXPECT_EQ(0, CopyLogger::TimesCopied); 108 EXPECT_EQ(0, CopyLogger::TimesCopied);
109 EXPECT_EQ(1, CopyLogger::TimesConstructed); 109 EXPECT_EQ(1, CopyLogger::TimesConstructed);
110 110
111 bool res = false; 111 bool res = false;
112 112
113 // Creating the tuple should copy the class to store internally in the tuple. 113 // Creating the tuple should copy the class to store internally in the tuple.
114 base::Tuple<CopyLogger, CopyLogger*, bool*> tuple(logger, &logger, &res); 114 std::tuple<CopyLogger, CopyLogger*, bool*> tuple(logger, &logger, &res);
115 get<1>(tuple) = &get<0>(tuple); 115 std::get<1>(tuple) = &std::get<0>(tuple);
116 EXPECT_EQ(2, CopyLogger::TimesConstructed); 116 EXPECT_EQ(2, CopyLogger::TimesConstructed);
117 EXPECT_EQ(1, CopyLogger::TimesCopied); 117 EXPECT_EQ(1, CopyLogger::TimesCopied);
118 118
119 // Our internal Logger and the one passed to the function should be the same. 119 // Our internal Logger and the one passed to the function should be the same.
120 res = false; 120 res = false;
121 DispatchToFunction(&SomeLoggerMethRef, tuple); 121 DispatchToFunction(&SomeLoggerMethRef, tuple);
122 EXPECT_TRUE(res); 122 EXPECT_TRUE(res);
123 EXPECT_EQ(2, CopyLogger::TimesConstructed); 123 EXPECT_EQ(2, CopyLogger::TimesConstructed);
124 EXPECT_EQ(1, CopyLogger::TimesCopied); 124 EXPECT_EQ(1, CopyLogger::TimesCopied);
125 125
126 // Now they should be different, since the function call will make a copy. 126 // Now they should be different, since the function call will make a copy.
127 res = false; 127 res = false;
128 DispatchToFunction(&SomeLoggerMethCopy, tuple); 128 DispatchToFunction(&SomeLoggerMethCopy, tuple);
129 EXPECT_FALSE(res); 129 EXPECT_FALSE(res);
130 EXPECT_EQ(3, CopyLogger::TimesConstructed); 130 EXPECT_EQ(3, CopyLogger::TimesConstructed);
131 EXPECT_EQ(2, CopyLogger::TimesCopied); 131 EXPECT_EQ(2, CopyLogger::TimesCopied);
132 } 132 }
133 133
134 } // namespace base 134 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698