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

Side by Side Diff: mojo/public/cpp/system/tests/core_unittest.cc

Issue 336313003: mojo: Don't leak handles when assigning to ScopedHandles. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: vtl suggestion Created 6 years, 6 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 | « mojo/public/cpp/system/core.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 // This file tests the C++ Mojo system core wrappers. 5 // This file tests the C++ Mojo system core wrappers.
6 // TODO(vtl): Maybe rename "CoreCppTest" -> "CoreTest" if/when this gets 6 // TODO(vtl): Maybe rename "CoreCppTest" -> "CoreTest" if/when this gets
7 // compiled into a different binary from the C API tests. 7 // compiled into a different binary from the C API tests.
8 8
9 #include "mojo/public/cpp/system/core.h" 9 #include "mojo/public/cpp/system/core.h"
10 10
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 MOJO_WRITE_MESSAGE_FLAG_NONE)); 379 MOJO_WRITE_MESSAGE_FLAG_NONE));
380 // |h3_value| should actually be invalid now. 380 // |h3_value| should actually be invalid now.
381 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, MojoClose(h3_value)); 381 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, MojoClose(h3_value));
382 382
383 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h2.release().value())); 383 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h2.release().value()));
384 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h0.release().value())); 384 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h0.release().value()));
385 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h1.release().value())); 385 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h1.release().value()));
386 } 386 }
387 } 387 }
388 388
389 TEST(CoreCppTest, ScopedHandleMoveCtor) {
390 ScopedSharedBufferHandle buffer1;
391 EXPECT_EQ(MOJO_RESULT_OK, CreateSharedBuffer(NULL, 1024, &buffer1));
392 EXPECT_TRUE(buffer1.is_valid());
393
394 ScopedSharedBufferHandle buffer2;
395 EXPECT_EQ(MOJO_RESULT_OK, CreateSharedBuffer(NULL, 1024, &buffer2));
396 EXPECT_TRUE(buffer2.is_valid());
397
398 // If this fails to close buffer1, ScopedHandleBase::CloseIfNecessary() will
399 // assert.
400 buffer1 = buffer2.Pass();
401
402 EXPECT_TRUE(buffer1.is_valid());
403 EXPECT_FALSE(buffer2.is_valid());
404 }
405
406 TEST(CoreCppTest, ScopedHandleMoveCtorSelf) {
407 ScopedSharedBufferHandle buffer1;
408 EXPECT_EQ(MOJO_RESULT_OK, CreateSharedBuffer(NULL, 1024, &buffer1));
409 EXPECT_TRUE(buffer1.is_valid());
410
411 buffer1 = buffer1.Pass();
412
413 EXPECT_TRUE(buffer1.is_valid());
414 }
415
389 // TODO(vtl): Write data pipe tests. 416 // TODO(vtl): Write data pipe tests.
390 417
391 } // namespace 418 } // namespace
392 } // namespace mojo 419 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/system/core.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698