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

Side by Side Diff: ppapi/shared_impl/thread_aware_callback_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/thread_aware_callback.cc ('k') | ppapi/shared_impl/time_conversion.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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ppapi/shared_impl/thread_aware_callback.h" 5 #include "ppapi/shared_impl/thread_aware_callback.h"
6 6
7 #include "base/bind_helpers.h" 7 #include "base/bind_helpers.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "ppapi/c/pp_errors.h" 11 #include "ppapi/c/pp_errors.h"
12 #include "ppapi/proxy/ppapi_proxy_test.h" 12 #include "ppapi/proxy/ppapi_proxy_test.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 namespace ppapi { 15 namespace ppapi {
16 16
17 namespace { 17 namespace {
18 18
19 class TestParameter { 19 class TestParameter {
20 public: 20 public:
21 TestParameter() : value_(0) { 21 TestParameter() : value_(0) {}
22 }
23 22
24 int value_; 23 int value_;
25 }; 24 };
26 25
27 int called_num = 0; 26 int called_num = 0;
28 27
29 void TestCallback_0() { 28 void TestCallback_0() { ++called_num; }
30 ++called_num;
31 }
32 29
33 void TestCallback_1(int p1) { 30 void TestCallback_1(int p1) { ++called_num; }
34 ++called_num;
35 }
36 31
37 void TestCallback_2(int p1, const double* p2) { 32 void TestCallback_2(int p1, const double* p2) { ++called_num; }
38 ++called_num;
39 }
40 33
41 void TestCallback_3(int p1, const double* p2, bool* p3) { 34 void TestCallback_3(int p1, const double* p2, bool* p3) { ++called_num; }
42 ++called_num;
43 }
44 35
45 void TestCallback_4(int p1, const double* p2, bool* p3, TestParameter p4) { 36 void TestCallback_4(int p1, const double* p2, bool* p3, TestParameter p4) {
46 ++called_num; 37 ++called_num;
47 } 38 }
48 39
49 void TestCallback_5(int p1, 40 void TestCallback_5(int p1,
50 const double* p2, 41 const double* p2,
51 bool* p3, 42 bool* p3,
52 TestParameter p4, 43 TestParameter p4,
53 const TestParameter& p5) { 44 const TestParameter& p5) {
54 ++called_num; 45 ++called_num;
55 } 46 }
56 47
57 typedef proxy::PluginProxyTest ThreadAwareCallbackTest; 48 typedef proxy::PluginProxyTest ThreadAwareCallbackTest;
58 49
59 // Test that a callback created on the main thread will run on the main thread, 50 // Test that a callback created on the main thread will run on the main thread,
60 // even when requested from a different thread. 51 // even when requested from a different thread.
61 class ThreadAwareCallbackMultiThreadTest 52 class ThreadAwareCallbackMultiThreadTest
62 : public proxy::PluginProxyMultiThreadTest { 53 : public proxy::PluginProxyMultiThreadTest {
63 public: 54 public:
64 ThreadAwareCallbackMultiThreadTest() : main_thread_callback_called_(false) { 55 ThreadAwareCallbackMultiThreadTest() : main_thread_callback_called_(false) {}
65 }
66 virtual ~ThreadAwareCallbackMultiThreadTest() { 56 virtual ~ThreadAwareCallbackMultiThreadTest() {
67 CHECK(main_thread_callback_called_); 57 CHECK(main_thread_callback_called_);
68 } 58 }
69 59
70 // proxy::PluginProxyMultiThreadTest implementation. 60 // proxy::PluginProxyMultiThreadTest implementation.
71 virtual void SetUpTestOnMainThread() OVERRIDE { 61 virtual void SetUpTestOnMainThread() OVERRIDE {
72 ProxyAutoLock auto_lock; 62 ProxyAutoLock auto_lock;
73 63
74 main_thread_callback_.reset( 64 main_thread_callback_.reset(
75 ThreadAwareCallback<CallbackFunc>::Create(&MainThreadCallbackBody)); 65 ThreadAwareCallback<CallbackFunc>::Create(&MainThreadCallbackBody));
(...skipping 26 matching lines...) Expand all
102 } 92 }
103 93
104 scoped_ptr<ThreadAwareCallback<CallbackFunc> > main_thread_callback_; 94 scoped_ptr<ThreadAwareCallback<CallbackFunc> > main_thread_callback_;
105 bool main_thread_callback_called_; 95 bool main_thread_callback_called_;
106 }; 96 };
107 97
108 // Test that when a ThreadAwareCallback instance is destroyed, pending tasks to 98 // Test that when a ThreadAwareCallback instance is destroyed, pending tasks to
109 // run the callback will be ignored. 99 // run the callback will be ignored.
110 class ThreadAwareCallbackAbortTest : public proxy::PluginProxyMultiThreadTest { 100 class ThreadAwareCallbackAbortTest : public proxy::PluginProxyMultiThreadTest {
111 public: 101 public:
112 ThreadAwareCallbackAbortTest() { 102 ThreadAwareCallbackAbortTest() {}
113 } 103 virtual ~ThreadAwareCallbackAbortTest() {}
114 virtual ~ThreadAwareCallbackAbortTest() {
115 }
116 104
117 // proxy::PluginProxyMultiThreadTest implementation. 105 // proxy::PluginProxyMultiThreadTest implementation.
118 virtual void SetUpTestOnMainThread() OVERRIDE { 106 virtual void SetUpTestOnMainThread() OVERRIDE {
119 ProxyAutoLock auto_lock; 107 ProxyAutoLock auto_lock;
120 108
121 main_thread_callback_.reset( 109 main_thread_callback_.reset(
122 ThreadAwareCallback<CallbackFunc>::Create(&MainThreadCallbackBody)); 110 ThreadAwareCallback<CallbackFunc>::Create(&MainThreadCallbackBody));
123 } 111 }
124 112
125 virtual void SetUpTestOnSecondaryThread() OVERRIDE { 113 virtual void SetUpTestOnSecondaryThread() OVERRIDE {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 typedef void (*FuncType_3)(int, const double*, bool*); 175 typedef void (*FuncType_3)(int, const double*, bool*);
188 scoped_ptr<ThreadAwareCallback<FuncType_3> > callback_3( 176 scoped_ptr<ThreadAwareCallback<FuncType_3> > callback_3(
189 ThreadAwareCallback<FuncType_3>::Create(TestCallback_3)); 177 ThreadAwareCallback<FuncType_3>::Create(TestCallback_3));
190 callback_3->RunOnTargetThread(1, &double_arg, &bool_arg); 178 callback_3->RunOnTargetThread(1, &double_arg, &bool_arg);
191 179
192 typedef void (*FuncType_4)(int, const double*, bool*, TestParameter); 180 typedef void (*FuncType_4)(int, const double*, bool*, TestParameter);
193 scoped_ptr<ThreadAwareCallback<FuncType_4> > callback_4( 181 scoped_ptr<ThreadAwareCallback<FuncType_4> > callback_4(
194 ThreadAwareCallback<FuncType_4>::Create(TestCallback_4)); 182 ThreadAwareCallback<FuncType_4>::Create(TestCallback_4));
195 callback_4->RunOnTargetThread(1, &double_arg, &bool_arg, object_arg); 183 callback_4->RunOnTargetThread(1, &double_arg, &bool_arg, object_arg);
196 184
197 typedef void (*FuncType_5)(int, 185 typedef void (*FuncType_5)(
198 const double*, 186 int, const double*, bool*, TestParameter, const TestParameter&);
199 bool*,
200 TestParameter,
201 const TestParameter&);
202 scoped_ptr<ThreadAwareCallback<FuncType_5> > callback_5( 187 scoped_ptr<ThreadAwareCallback<FuncType_5> > callback_5(
203 ThreadAwareCallback<FuncType_5>::Create(TestCallback_5)); 188 ThreadAwareCallback<FuncType_5>::Create(TestCallback_5));
204 callback_5->RunOnTargetThread(1, &double_arg, &bool_arg, object_arg, 189 callback_5->RunOnTargetThread(
205 object_arg); 190 1, &double_arg, &bool_arg, object_arg, object_arg);
206 191
207 EXPECT_EQ(6, called_num); 192 EXPECT_EQ(6, called_num);
208 } 193 }
209 194
210 TEST_F(ThreadAwareCallbackMultiThreadTest, RunOnTargetThread) { 195 TEST_F(ThreadAwareCallbackMultiThreadTest, RunOnTargetThread) { RunTest(); }
211 RunTest();
212 }
213 196
214 TEST_F(ThreadAwareCallbackAbortTest, NotRunIfAborted) { 197 TEST_F(ThreadAwareCallbackAbortTest, NotRunIfAborted) { RunTest(); }
215 RunTest();
216 }
217 198
218 } // namespace ppapi 199 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/shared_impl/thread_aware_callback.cc ('k') | ppapi/shared_impl/time_conversion.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698