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

Side by Side Diff: mojo/system/shared_buffer_dispatcher_unittest.cc

Issue 502573006: Remove implicit conversions from scoped_refptr to T* in mojo/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "mojo/system/shared_buffer_dispatcher.h" 5 #include "mojo/system/shared_buffer_dispatcher.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 } 114 }
115 115
116 TEST_F(SharedBufferDispatcherTest, CreateAndMapBuffer) { 116 TEST_F(SharedBufferDispatcherTest, CreateAndMapBuffer) {
117 scoped_refptr<SharedBufferDispatcher> dispatcher; 117 scoped_refptr<SharedBufferDispatcher> dispatcher;
118 EXPECT_EQ(MOJO_RESULT_OK, 118 EXPECT_EQ(MOJO_RESULT_OK,
119 SharedBufferDispatcher::Create( 119 SharedBufferDispatcher::Create(
120 platform_support(), 120 platform_support(),
121 SharedBufferDispatcher::kDefaultCreateOptions, 121 SharedBufferDispatcher::kDefaultCreateOptions,
122 100, 122 100,
123 &dispatcher)); 123 &dispatcher));
124 ASSERT_TRUE(dispatcher); 124 ASSERT_TRUE(dispatcher.get());
125 EXPECT_EQ(Dispatcher::kTypeSharedBuffer, dispatcher->GetType()); 125 EXPECT_EQ(Dispatcher::kTypeSharedBuffer, dispatcher->GetType());
126 126
127 // Make a couple of mappings. 127 // Make a couple of mappings.
128 scoped_ptr<embedder::PlatformSharedBufferMapping> mapping1; 128 scoped_ptr<embedder::PlatformSharedBufferMapping> mapping1;
129 EXPECT_EQ( 129 EXPECT_EQ(
130 MOJO_RESULT_OK, 130 MOJO_RESULT_OK,
131 dispatcher->MapBuffer(0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping1)); 131 dispatcher->MapBuffer(0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping1));
132 ASSERT_TRUE(mapping1); 132 ASSERT_TRUE(mapping1);
133 ASSERT_TRUE(mapping1->GetBase()); 133 ASSERT_TRUE(mapping1->GetBase());
134 EXPECT_EQ(100u, mapping1->GetLength()); 134 EXPECT_EQ(100u, mapping1->GetLength());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 MOJO_RESULT_OK, 167 MOJO_RESULT_OK,
168 dispatcher1->MapBuffer(0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping)); 168 dispatcher1->MapBuffer(0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping));
169 static_cast<char*>(mapping->GetBase())[0] = 'x'; 169 static_cast<char*>(mapping->GetBase())[0] = 'x';
170 mapping.reset(); 170 mapping.reset();
171 171
172 // Duplicate |dispatcher1| and then close it. 172 // Duplicate |dispatcher1| and then close it.
173 scoped_refptr<Dispatcher> dispatcher2; 173 scoped_refptr<Dispatcher> dispatcher2;
174 EXPECT_EQ( 174 EXPECT_EQ(
175 MOJO_RESULT_OK, 175 MOJO_RESULT_OK,
176 dispatcher1->DuplicateBufferHandle(NullUserPointer(), &dispatcher2)); 176 dispatcher1->DuplicateBufferHandle(NullUserPointer(), &dispatcher2));
177 ASSERT_TRUE(dispatcher2); 177 ASSERT_TRUE(dispatcher2.get());
178 EXPECT_EQ(Dispatcher::kTypeSharedBuffer, dispatcher2->GetType()); 178 EXPECT_EQ(Dispatcher::kTypeSharedBuffer, dispatcher2->GetType());
179 179
180 EXPECT_EQ(MOJO_RESULT_OK, dispatcher1->Close()); 180 EXPECT_EQ(MOJO_RESULT_OK, dispatcher1->Close());
181 181
182 // Map |dispatcher2| and read something. 182 // Map |dispatcher2| and read something.
183 EXPECT_EQ( 183 EXPECT_EQ(
184 MOJO_RESULT_OK, 184 MOJO_RESULT_OK,
185 dispatcher2->MapBuffer(0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping)); 185 dispatcher2->MapBuffer(0, 100, MOJO_MAP_BUFFER_FLAG_NONE, &mapping));
186 EXPECT_EQ('x', static_cast<char*>(mapping->GetBase())[0]); 186 EXPECT_EQ('x', static_cast<char*>(mapping->GetBase())[0]);
187 187
(...skipping 11 matching lines...) Expand all
199 199
200 MojoDuplicateBufferHandleOptions options[] = { 200 MojoDuplicateBufferHandleOptions options[] = {
201 {sizeof(MojoDuplicateBufferHandleOptions), 201 {sizeof(MojoDuplicateBufferHandleOptions),
202 MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE}, 202 MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE},
203 {sizeof(MojoDuplicateBufferHandleOptionsFlags), ~0u}}; 203 {sizeof(MojoDuplicateBufferHandleOptionsFlags), ~0u}};
204 for (size_t i = 0; i < arraysize(options); i++) { 204 for (size_t i = 0; i < arraysize(options); i++) {
205 scoped_refptr<Dispatcher> dispatcher2; 205 scoped_refptr<Dispatcher> dispatcher2;
206 EXPECT_EQ(MOJO_RESULT_OK, 206 EXPECT_EQ(MOJO_RESULT_OK,
207 dispatcher1->DuplicateBufferHandle(MakeUserPointer(&options[i]), 207 dispatcher1->DuplicateBufferHandle(MakeUserPointer(&options[i]),
208 &dispatcher2)); 208 &dispatcher2));
209 ASSERT_TRUE(dispatcher2); 209 ASSERT_TRUE(dispatcher2.get());
210 EXPECT_EQ(Dispatcher::kTypeSharedBuffer, dispatcher2->GetType()); 210 EXPECT_EQ(Dispatcher::kTypeSharedBuffer, dispatcher2->GetType());
211 EXPECT_EQ(MOJO_RESULT_OK, dispatcher2->Close()); 211 EXPECT_EQ(MOJO_RESULT_OK, dispatcher2->Close());
212 } 212 }
213 213
214 EXPECT_EQ(MOJO_RESULT_OK, dispatcher1->Close()); 214 EXPECT_EQ(MOJO_RESULT_OK, dispatcher1->Close());
215 } 215 }
216 216
217 TEST_F(SharedBufferDispatcherTest, DuplicateBufferHandleOptionsInvalid) { 217 TEST_F(SharedBufferDispatcherTest, DuplicateBufferHandleOptionsInvalid) {
218 scoped_refptr<SharedBufferDispatcher> dispatcher1; 218 scoped_refptr<SharedBufferDispatcher> dispatcher1;
219 EXPECT_EQ(MOJO_RESULT_OK, 219 EXPECT_EQ(MOJO_RESULT_OK,
220 SharedBufferDispatcher::Create( 220 SharedBufferDispatcher::Create(
221 platform_support(), 221 platform_support(),
222 SharedBufferDispatcher::kDefaultCreateOptions, 222 SharedBufferDispatcher::kDefaultCreateOptions,
223 100, 223 100,
224 &dispatcher1)); 224 &dispatcher1));
225 225
226 // Invalid |struct_size|. 226 // Invalid |struct_size|.
227 { 227 {
228 MojoDuplicateBufferHandleOptions options = { 228 MojoDuplicateBufferHandleOptions options = {
229 1u, MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE}; 229 1u, MOJO_DUPLICATE_BUFFER_HANDLE_OPTIONS_FLAG_NONE};
230 scoped_refptr<Dispatcher> dispatcher2; 230 scoped_refptr<Dispatcher> dispatcher2;
231 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 231 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
232 dispatcher1->DuplicateBufferHandle(MakeUserPointer(&options), 232 dispatcher1->DuplicateBufferHandle(MakeUserPointer(&options),
233 &dispatcher2)); 233 &dispatcher2));
234 EXPECT_FALSE(dispatcher2); 234 EXPECT_FALSE(dispatcher2.get());
235 } 235 }
236 236
237 // Unknown |flags|. 237 // Unknown |flags|.
238 { 238 {
239 MojoDuplicateBufferHandleOptions options = { 239 MojoDuplicateBufferHandleOptions options = {
240 sizeof(MojoDuplicateBufferHandleOptions), ~0u}; 240 sizeof(MojoDuplicateBufferHandleOptions), ~0u};
241 scoped_refptr<Dispatcher> dispatcher2; 241 scoped_refptr<Dispatcher> dispatcher2;
242 EXPECT_EQ(MOJO_RESULT_UNIMPLEMENTED, 242 EXPECT_EQ(MOJO_RESULT_UNIMPLEMENTED,
243 dispatcher1->DuplicateBufferHandle(MakeUserPointer(&options), 243 dispatcher1->DuplicateBufferHandle(MakeUserPointer(&options),
244 &dispatcher2)); 244 &dispatcher2));
245 EXPECT_FALSE(dispatcher2); 245 EXPECT_FALSE(dispatcher2.get());
246 } 246 }
247 247
248 EXPECT_EQ(MOJO_RESULT_OK, dispatcher1->Close()); 248 EXPECT_EQ(MOJO_RESULT_OK, dispatcher1->Close());
249 } 249 }
250 250
251 TEST_F(SharedBufferDispatcherTest, CreateInvalidNumBytes) { 251 TEST_F(SharedBufferDispatcherTest, CreateInvalidNumBytes) {
252 // Size too big. 252 // Size too big.
253 scoped_refptr<SharedBufferDispatcher> dispatcher; 253 scoped_refptr<SharedBufferDispatcher> dispatcher;
254 EXPECT_EQ(MOJO_RESULT_RESOURCE_EXHAUSTED, 254 EXPECT_EQ(MOJO_RESULT_RESOURCE_EXHAUSTED,
255 SharedBufferDispatcher::Create( 255 SharedBufferDispatcher::Create(
256 platform_support(), 256 platform_support(),
257 SharedBufferDispatcher::kDefaultCreateOptions, 257 SharedBufferDispatcher::kDefaultCreateOptions,
258 std::numeric_limits<uint64_t>::max(), 258 std::numeric_limits<uint64_t>::max(),
259 &dispatcher)); 259 &dispatcher));
260 EXPECT_FALSE(dispatcher); 260 EXPECT_FALSE(dispatcher.get());
261 261
262 // Zero size. 262 // Zero size.
263 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 263 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
264 SharedBufferDispatcher::Create( 264 SharedBufferDispatcher::Create(
265 platform_support(), 265 platform_support(),
266 SharedBufferDispatcher::kDefaultCreateOptions, 266 SharedBufferDispatcher::kDefaultCreateOptions,
267 0, 267 0,
268 &dispatcher)); 268 &dispatcher));
269 EXPECT_FALSE(dispatcher); 269 EXPECT_FALSE(dispatcher.get());
270 } 270 }
271 271
272 TEST_F(SharedBufferDispatcherTest, MapBufferInvalidArguments) { 272 TEST_F(SharedBufferDispatcherTest, MapBufferInvalidArguments) {
273 scoped_refptr<SharedBufferDispatcher> dispatcher; 273 scoped_refptr<SharedBufferDispatcher> dispatcher;
274 EXPECT_EQ(MOJO_RESULT_OK, 274 EXPECT_EQ(MOJO_RESULT_OK,
275 SharedBufferDispatcher::Create( 275 SharedBufferDispatcher::Create(
276 platform_support(), 276 platform_support(),
277 SharedBufferDispatcher::kDefaultCreateOptions, 277 SharedBufferDispatcher::kDefaultCreateOptions,
278 100, 278 100,
279 &dispatcher)); 279 &dispatcher));
(...skipping 10 matching lines...) Expand all
290 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, 290 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT,
291 dispatcher->MapBuffer(0, 0, MOJO_MAP_BUFFER_FLAG_NONE, &mapping)); 291 dispatcher->MapBuffer(0, 0, MOJO_MAP_BUFFER_FLAG_NONE, &mapping));
292 EXPECT_FALSE(mapping); 292 EXPECT_FALSE(mapping);
293 293
294 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close()); 294 EXPECT_EQ(MOJO_RESULT_OK, dispatcher->Close());
295 } 295 }
296 296
297 } // namespace 297 } // namespace
298 } // namespace system 298 } // namespace system
299 } // namespace mojo 299 } // namespace mojo
OLDNEW
« mojo/system/channel.cc ('K') | « mojo/system/shared_buffer_dispatcher.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698