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

Side by Side Diff: ppapi/shared_impl/proxy_lock_unittest.cc

Issue 174213003: PPAPI: Use clang-format on ppapi/shared_impl (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: remove DEPS Created 6 years, 10 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
« no previous file with comments | « ppapi/shared_impl/proxy_lock.cc ('k') | ppapi/shared_impl/resource.h » ('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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 <string> 5 #include <string>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 16 matching lines...) Expand all
27 ProxyAutoLock lock; 27 ProxyAutoLock lock;
28 } 28 }
29 } 29 }
30 30
31 int called_num = 0; 31 int called_num = 0;
32 32
33 class CheckLockStateInDestructor 33 class CheckLockStateInDestructor
34 : public base::RefCounted<CheckLockStateInDestructor> { 34 : public base::RefCounted<CheckLockStateInDestructor> {
35 public: 35 public:
36 CheckLockStateInDestructor() {} 36 CheckLockStateInDestructor() {}
37 void Method() { 37 void Method() { ++called_num; }
38 ++called_num; 38
39 }
40 private: 39 private:
41 friend class base::RefCounted<CheckLockStateInDestructor>; 40 friend class base::RefCounted<CheckLockStateInDestructor>;
42 ~CheckLockStateInDestructor() { 41 ~CheckLockStateInDestructor() { CheckLockState(); }
43 CheckLockState();
44 }
45 DISALLOW_COPY_AND_ASSIGN(CheckLockStateInDestructor); 42 DISALLOW_COPY_AND_ASSIGN(CheckLockStateInDestructor);
46 }; 43 };
47 44
48 void TestCallback_0() { 45 void TestCallback_0() {
49 CheckLockState(); 46 CheckLockState();
50 ++called_num; 47 ++called_num;
51 } 48 }
52 49
53 void TestCallback_1(int p1) { 50 void TestCallback_1(int p1) {
54 CheckLockState(); 51 CheckLockState();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 cb0 = RunWhileLocked(base::Bind(TestCallback_1, 123)); 83 cb0 = RunWhileLocked(base::Bind(TestCallback_1, 123));
87 } 84 }
88 cb0.Run(); 85 cb0.Run();
89 ASSERT_EQ(1, called_num); 86 ASSERT_EQ(1, called_num);
90 called_num = 0; 87 called_num = 0;
91 88
92 { 89 {
93 ProxyAutoLock lock; 90 ProxyAutoLock lock;
94 scoped_refptr<CheckLockStateInDestructor> object = 91 scoped_refptr<CheckLockStateInDestructor> object =
95 new CheckLockStateInDestructor(); 92 new CheckLockStateInDestructor();
96 cb0 = RunWhileLocked( 93 cb0 =
97 base::Bind(&CheckLockStateInDestructor::Method, 94 RunWhileLocked(base::Bind(&CheckLockStateInDestructor::Method, object));
98 object));
99 // Note after this scope, the Callback owns the only reference. 95 // Note after this scope, the Callback owns the only reference.
100 } 96 }
101 cb0.Run(); 97 cb0.Run();
102 ASSERT_EQ(1, called_num); 98 ASSERT_EQ(1, called_num);
103 called_num = 0; 99 called_num = 0;
104 100
105 base::Callback<void(int)> cb1; 101 base::Callback<void(int)> cb1;
106 { 102 {
107 ProxyAutoLock lock; 103 ProxyAutoLock lock;
108 cb1 = RunWhileLocked(base::Bind(TestCallback_1)); 104 cb1 = RunWhileLocked(base::Bind(TestCallback_1));
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 TestGlobals globals; 147 TestGlobals globals;
152 expect_to_be_locked = false; 148 expect_to_be_locked = false;
153 // These calls should all try to _unlock_, so we must be locked before 149 // These calls should all try to _unlock_, so we must be locked before
154 // entering them. 150 // entering them.
155 ProxyAutoLock auto_lock; 151 ProxyAutoLock auto_lock;
156 152
157 { 153 {
158 CallWhileUnlocked(TestCallback_0); 154 CallWhileUnlocked(TestCallback_0);
159 ASSERT_EQ(1, called_num); 155 ASSERT_EQ(1, called_num);
160 called_num = 0; 156 called_num = 0;
161 } { 157 }
158 {
162 CallWhileUnlocked(TestCallback_1, 123); 159 CallWhileUnlocked(TestCallback_1, 123);
163 ASSERT_EQ(1, called_num); 160 ASSERT_EQ(1, called_num);
164 called_num = 0; 161 called_num = 0;
165 } { 162 }
163 {
166 // TODO(dmichael): Make const-ref arguments work properly with type 164 // TODO(dmichael): Make const-ref arguments work properly with type
167 // deduction. 165 // deduction.
168 CallWhileUnlocked<void, int, const std::string&>( 166 CallWhileUnlocked<void, int, const std::string&>(
169 TestCallback_2, 123, std::string("yo")); 167 TestCallback_2, 123, std::string("yo"));
170 ASSERT_EQ(1, called_num); 168 ASSERT_EQ(1, called_num);
171 called_num = 0; 169 called_num = 0;
172 } { 170 }
171 {
173 base::Callback<void()> callback(base::Bind(TestCallback_0)); 172 base::Callback<void()> callback(base::Bind(TestCallback_0));
174 CallWhileUnlocked(callback); 173 CallWhileUnlocked(callback);
175 ASSERT_EQ(1, called_num); 174 ASSERT_EQ(1, called_num);
176 called_num = 0; 175 called_num = 0;
177 } 176 }
178 } 177 }
179 178
180 } // namespace ppapi 179 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/shared_impl/proxy_lock.cc ('k') | ppapi/shared_impl/resource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698