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

Side by Side Diff: mojo/public/platform/native/system_impl_private_unittest.cc

Issue 1778753002: Implement MojoGetBufferInformation(), part 3. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 9 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 // This file tests the C API, but using the explicit MojoSystemImpl parameter. 5 // This file tests the C API, but using the explicit MojoSystemImpl parameter.
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include "mojo/public/c/system/core.h" 9 #include "mojo/public/c/system/core.h"
10 #include "mojo/public/platform/native/system_impl_private.h" 10 #include "mojo/public/platform/native/system_impl_private.h"
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 255
256 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplClose(sys1, hc)); 256 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplClose(sys1, hc));
257 257
258 // TODO(vtl): Test the other way around -- closing the consumer should make 258 // TODO(vtl): Test the other way around -- closing the consumer should make
259 // the producer never-writable? 259 // the producer never-writable?
260 260
261 // 2 SystemImpls are leaked... 261 // 2 SystemImpls are leaked...
262 } 262 }
263 263
264 TEST(SystemImplTest, BasicSharedBuffer) { 264 TEST(SystemImplTest, BasicSharedBuffer) {
265 const uint64_t kSize = 100u;
266
265 MojoSystemImpl sys0 = MojoSystemImplCreateImpl(); 267 MojoSystemImpl sys0 = MojoSystemImplCreateImpl();
266 MojoSystemImpl sys1 = MojoSystemImplCreateImpl(); 268 MojoSystemImpl sys1 = MojoSystemImplCreateImpl();
267 EXPECT_NE(sys0, sys1); 269 EXPECT_NE(sys0, sys1);
268 270
269 MojoHandle h0, h1; 271 MojoHandle h0, h1;
270 void* pointer; 272 void* pointer;
271 273
272 // Create a shared buffer (|h0|). 274 // Create a shared buffer (|h0|).
273 h0 = MOJO_HANDLE_INVALID; 275 h0 = MOJO_HANDLE_INVALID;
274 EXPECT_EQ(MOJO_RESULT_OK, 276 EXPECT_EQ(MOJO_RESULT_OK,
275 MojoSystemImplCreateSharedBuffer(sys0, nullptr, 100, &h0)); 277 MojoSystemImplCreateSharedBuffer(sys0, nullptr, kSize, &h0));
276 EXPECT_NE(h0, MOJO_HANDLE_INVALID); 278 EXPECT_NE(h0, MOJO_HANDLE_INVALID);
277 279
280 // Check the buffer information.
281 {
282 MojoBufferInformation info = {};
283 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplGetBufferInformation(
284 sys0, h0, &info, sizeof(info)));
285 EXPECT_EQ(sizeof(info), info.struct_size);
286 EXPECT_EQ(MOJO_BUFFER_INFORMATION_FLAG_NONE, info.flags);
287 EXPECT_EQ(kSize, info.num_bytes);
288 }
289
278 // Map everything. 290 // Map everything.
279 pointer = nullptr; 291 pointer = nullptr;
280 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplMapBuffer(sys0, h0, 0, 100, &pointer, 292 EXPECT_EQ(MOJO_RESULT_OK,
281 MOJO_MAP_BUFFER_FLAG_NONE)); 293 MojoSystemImplMapBuffer(sys0, h0, 0u, kSize, &pointer,
294 MOJO_MAP_BUFFER_FLAG_NONE));
282 ASSERT_TRUE(pointer); 295 ASSERT_TRUE(pointer);
283 static_cast<char*>(pointer)[50] = 'x'; 296 static_cast<char*>(pointer)[kSize / 2] = 'x';
284 297
285 // Duplicate |h0| to |h1|. 298 // Duplicate |h0| to |h1|.
286 h1 = MOJO_HANDLE_INVALID; 299 h1 = MOJO_HANDLE_INVALID;
287 EXPECT_EQ(MOJO_RESULT_OK, 300 EXPECT_EQ(MOJO_RESULT_OK,
288 MojoSystemImplDuplicateBufferHandle(sys0, h0, nullptr, &h1)); 301 MojoSystemImplDuplicateBufferHandle(sys0, h0, nullptr, &h1));
289 EXPECT_NE(h1, MOJO_HANDLE_INVALID); 302 EXPECT_NE(h1, MOJO_HANDLE_INVALID);
290 303
291 // Move the other end of the pipe to a different SystemImpl. 304 // Move the other end of the pipe to a different SystemImpl.
292 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplTransferHandle(sys0, h1, sys1, &h1)); 305 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplTransferHandle(sys0, h1, sys1, &h1));
293 EXPECT_NE(h1, MOJO_HANDLE_INVALID); 306 EXPECT_NE(h1, MOJO_HANDLE_INVALID);
294 307
295 // Close |h0|. 308 // Close |h0|.
296 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplClose(sys0, h0)); 309 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplClose(sys0, h0));
297 310
298 // The mapping should still be good. 311 // The mapping should still be good.
299 static_cast<char*>(pointer)[51] = 'y'; 312 static_cast<char*>(pointer)[kSize / 2 + 1] = 'y';
300 313
301 // Unmap it. 314 // Unmap it.
302 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplUnmapBuffer(sys0, pointer)); 315 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplUnmapBuffer(sys0, pointer));
303 316
317 // Check the buffer information on |h1|.
318 {
319 MojoBufferInformation info = {};
320 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplGetBufferInformation(
321 sys1, h1, &info, sizeof(info)));
322 EXPECT_EQ(sizeof(info), info.struct_size);
323 EXPECT_EQ(MOJO_BUFFER_INFORMATION_FLAG_NONE, info.flags);
324 EXPECT_EQ(kSize, info.num_bytes);
325 }
326
304 // Map half of |h1|. 327 // Map half of |h1|.
305 pointer = nullptr; 328 pointer = nullptr;
306 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplMapBuffer(sys1, h1, 50, 50, &pointer, 329 EXPECT_EQ(MOJO_RESULT_OK,
307 MOJO_MAP_BUFFER_FLAG_NONE)); 330 MojoSystemImplMapBuffer(sys1, h1, kSize / 2, kSize / 2, &pointer,
331 MOJO_MAP_BUFFER_FLAG_NONE));
308 ASSERT_TRUE(pointer); 332 ASSERT_TRUE(pointer);
309 333
310 // It should have what we wrote. 334 // It should have what we wrote.
311 EXPECT_EQ('x', static_cast<char*>(pointer)[0]); 335 EXPECT_EQ('x', static_cast<char*>(pointer)[0]);
312 EXPECT_EQ('y', static_cast<char*>(pointer)[1]); 336 EXPECT_EQ('y', static_cast<char*>(pointer)[1]);
313 337
314 // Unmap it. 338 // Unmap it.
315 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplUnmapBuffer(sys1, pointer)); 339 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplUnmapBuffer(sys1, pointer));
316 340
317 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplClose(sys1, h1)); 341 EXPECT_EQ(MOJO_RESULT_OK, MojoSystemImplClose(sys1, h1));
318 342
319 // 2 SystemImpls are leaked... 343 // 2 SystemImpls are leaked...
320 } 344 }
321 345
322 } // namespace 346 } // namespace
323 } // namespace mojo 347 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698