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

Side by Side Diff: base/tuple_unittest.cc

Issue 1612: Implement "iframe shim" behavior for windowed plugins.... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 12 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « base/tuple.h ('k') | chrome/browser/drag_utils.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "testing/gtest/include/gtest/gtest.h" 6 #include "testing/gtest/include/gtest/gtest.h"
7 7
8 namespace { 8 namespace {
9 9
10 void DoAdd(int a, int b, int c, int* res) { 10 void DoAdd(int a, int b, int c, int* res) {
11 *res = a + b + c; 11 *res = a + b + c;
12 } 12 }
13 13
14 struct Addy { 14 struct Addy {
15 Addy() { } 15 Addy() { }
16 void DoAdd(int a, int b, int c, int d, int* res) { 16 void DoAdd(int a, int b, int c, int d, int* res) {
17 *res = a + b + c + d; 17 *res = a + b + c + d;
18 } 18 }
19 }; 19 };
20 20
21 struct Addz {
22 Addz() { }
23 void DoAdd(int a, int b, int c, int d, int e, int* res) {
24 *res = a + b + c + d + e;
25 }
26 };
27
21 } // namespace 28 } // namespace
22 29
23 TEST(TupleTest, Basic) { 30 TEST(TupleTest, Basic) {
24 Tuple0 t0 = MakeTuple(); 31 Tuple0 t0 = MakeTuple();
25 Tuple1<int> t1(1); 32 Tuple1<int> t1(1);
26 Tuple2<int, const char*> t2 = MakeTuple(1, static_cast<const char*>("wee")); 33 Tuple2<int, const char*> t2 = MakeTuple(1, static_cast<const char*>("wee"));
27 Tuple3<int, int, int> t3(1, 2, 3); 34 Tuple3<int, int, int> t3(1, 2, 3);
28 Tuple4<int, int, int, int*> t4(1, 2, 3, &t1.a); 35 Tuple4<int, int, int, int*> t4(1, 2, 3, &t1.a);
29 Tuple5<int, int, int, int, int*> t5(1, 2, 3, 4, &t4.a); 36 Tuple5<int, int, int, int, int*> t5(1, 2, 3, 4, &t4.a);
37 Tuple6<int, int, int, int, int, int*> t6(1, 2, 3, 4, 5, &t4.a);
30 38
31 EXPECT_EQ(1, t1.a); 39 EXPECT_EQ(1, t1.a);
32 EXPECT_EQ(1, t2.a); 40 EXPECT_EQ(1, t2.a);
33 EXPECT_EQ(1, t3.a); 41 EXPECT_EQ(1, t3.a);
34 EXPECT_EQ(2, t3.b); 42 EXPECT_EQ(2, t3.b);
35 EXPECT_EQ(3, t3.c); 43 EXPECT_EQ(3, t3.c);
36 EXPECT_EQ(1, t4.a); 44 EXPECT_EQ(1, t4.a);
37 EXPECT_EQ(2, t4.b); 45 EXPECT_EQ(2, t4.b);
38 EXPECT_EQ(3, t4.c); 46 EXPECT_EQ(3, t4.c);
39 EXPECT_EQ(1, t5.a); 47 EXPECT_EQ(1, t5.a);
40 EXPECT_EQ(2, t5.b); 48 EXPECT_EQ(2, t5.b);
41 EXPECT_EQ(3, t5.c); 49 EXPECT_EQ(3, t5.c);
42 EXPECT_EQ(4, t5.d); 50 EXPECT_EQ(4, t5.d);
43 51 EXPECT_EQ(1, t6.a);
52 EXPECT_EQ(2, t6.b);
53 EXPECT_EQ(3, t6.c);
54 EXPECT_EQ(4, t6.d);
55 EXPECT_EQ(5, t6.e);
44 56
45 EXPECT_EQ(1, t1.a); 57 EXPECT_EQ(1, t1.a);
46 DispatchToFunction(&DoAdd, t4); 58 DispatchToFunction(&DoAdd, t4);
47 EXPECT_EQ(6, t1.a); 59 EXPECT_EQ(6, t1.a);
48 60
49 int res = 0; 61 int res = 0;
50 DispatchToFunction(&DoAdd, MakeTuple(9, 8, 7, &res)); 62 DispatchToFunction(&DoAdd, MakeTuple(9, 8, 7, &res));
51 EXPECT_EQ(24, res); 63 EXPECT_EQ(24, res);
52 64
53 Addy addy; 65 Addy addy;
54 EXPECT_EQ(1, t4.a); 66 EXPECT_EQ(1, t4.a);
55 DispatchToMethod(&addy, &Addy::DoAdd, t5); 67 DispatchToMethod(&addy, &Addy::DoAdd, t5);
56 EXPECT_EQ(10, t4.a); 68 EXPECT_EQ(10, t4.a);
69
70 Addz addz;
71 EXPECT_EQ(10, t4.a);
72 DispatchToMethod(&addz, &Addz::DoAdd, t6);
73 EXPECT_EQ(15, t4.a);
57 } 74 }
58 75
59 namespace { 76 namespace {
60 77
61 struct CopyLogger { 78 struct CopyLogger {
62 CopyLogger() { ++TimesConstructed; } 79 CopyLogger() { ++TimesConstructed; }
63 CopyLogger(const CopyLogger& tocopy) { ++TimesConstructed; ++TimesCopied; } 80 CopyLogger(const CopyLogger& tocopy) { ++TimesConstructed; ++TimesCopied; }
64 ~CopyLogger() { } 81 ~CopyLogger() { }
65 82
66 static int TimesCopied; 83 static int TimesCopied;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 EXPECT_EQ(2, CopyLogger::TimesConstructed); 117 EXPECT_EQ(2, CopyLogger::TimesConstructed);
101 EXPECT_EQ(1, CopyLogger::TimesCopied); 118 EXPECT_EQ(1, CopyLogger::TimesCopied);
102 119
103 // Now they should be different, since the function call will make a copy. 120 // Now they should be different, since the function call will make a copy.
104 res = false; 121 res = false;
105 DispatchToFunction(&SomeLoggerMethCopy, tuple); 122 DispatchToFunction(&SomeLoggerMethCopy, tuple);
106 EXPECT_FALSE(res); 123 EXPECT_FALSE(res);
107 EXPECT_EQ(3, CopyLogger::TimesConstructed); 124 EXPECT_EQ(3, CopyLogger::TimesConstructed);
108 EXPECT_EQ(2, CopyLogger::TimesCopied); 125 EXPECT_EQ(2, CopyLogger::TimesCopied);
109 } 126 }
OLDNEW
« no previous file with comments | « base/tuple.h ('k') | chrome/browser/drag_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698