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

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

Issue 2104183002: Rationalize mojo_public_*tests targets. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: moar Created 4 years, 5 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 | « mojo/public/cpp/system/tests/BUILD.gn ('k') | mojo/public/cpp/system/tests/macros_unittest.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 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 // 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): Split this test into more reasonable units/files.
7 // compiled into a different binary from the C API tests.
8 7
9 #include <stddef.h> 8 #include <stddef.h>
10 9
11 #include <map> 10 #include <map>
12 11
13 #include "mojo/public/cpp/system/buffer.h" 12 #include "mojo/public/cpp/system/buffer.h"
14 #include "mojo/public/cpp/system/data_pipe.h" 13 #include "mojo/public/cpp/system/data_pipe.h"
15 #include "mojo/public/cpp/system/handle.h" 14 #include "mojo/public/cpp/system/handle.h"
16 #include "mojo/public/cpp/system/macros.h" 15 #include "mojo/public/cpp/system/macros.h"
17 #include "mojo/public/cpp/system/message_pipe.h" 16 #include "mojo/public/cpp/system/message_pipe.h"
18 #include "mojo/public/cpp/system/time.h" 17 #include "mojo/public/cpp/system/time.h"
19 #include "mojo/public/cpp/system/wait.h" 18 #include "mojo/public/cpp/system/wait.h"
20 #include "mojo/public/cpp/system/wait_set.h" 19 #include "mojo/public/cpp/system/wait_set.h"
21 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
22 21
23 namespace mojo { 22 namespace mojo {
24 namespace { 23 namespace {
25 24
26 TEST(CoreCppTest, GetTimeTicksNow) { 25 TEST(CoreTest, GetTimeTicksNow) {
27 const MojoTimeTicks start = GetTimeTicksNow(); 26 const MojoTimeTicks start = GetTimeTicksNow();
28 EXPECT_NE(static_cast<MojoTimeTicks>(0), start) 27 EXPECT_NE(static_cast<MojoTimeTicks>(0), start)
29 << "GetTimeTicksNow should return nonzero value"; 28 << "GetTimeTicksNow should return nonzero value";
30 } 29 }
31 30
32 TEST(CoreCppTest, Basic) { 31 TEST(CoreTest, Basic) {
33 // Basic |Handle| implementation: 32 // Basic |Handle| implementation:
34 { 33 {
35 EXPECT_EQ(MOJO_HANDLE_INVALID, kInvalidHandleValue); 34 EXPECT_EQ(MOJO_HANDLE_INVALID, kInvalidHandleValue);
36 35
37 Handle h0; 36 Handle h0;
38 EXPECT_EQ(kInvalidHandleValue, h0.value()); 37 EXPECT_EQ(kInvalidHandleValue, h0.value());
39 EXPECT_EQ(kInvalidHandleValue, *h0.mutable_value()); 38 EXPECT_EQ(kInvalidHandleValue, *h0.mutable_value());
40 EXPECT_FALSE(h0.is_valid()); 39 EXPECT_FALSE(h0.is_valid());
41 40
42 Handle h1(static_cast<MojoHandle>(123)); 41 Handle h1(static_cast<MojoHandle>(123));
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 EXPECT_STREQ(kWorld, buffer); 357 EXPECT_STREQ(kWorld, buffer);
359 EXPECT_EQ(0u, handles_count); 358 EXPECT_EQ(0u, handles_count);
360 } 359 }
361 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, MojoClose(hv0)); 360 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, MojoClose(hv0));
362 } 361 }
363 362
364 // TODO(vtl): Test |CloseRaw()|. 363 // TODO(vtl): Test |CloseRaw()|.
365 // TODO(vtl): Test |reset()| more thoroughly? 364 // TODO(vtl): Test |reset()| more thoroughly?
366 } 365 }
367 366
368 TEST(CoreCppTest, TearDownWithMessagesEnqueued) { 367 TEST(CoreTest, TearDownWithMessagesEnqueued) {
369 // Tear down a message pipe which still has a message enqueued, with the 368 // Tear down a message pipe which still has a message enqueued, with the
370 // message also having a valid message pipe handle. 369 // message also having a valid message pipe handle.
371 { 370 {
372 ScopedMessagePipeHandle h0; 371 ScopedMessagePipeHandle h0;
373 ScopedMessagePipeHandle h1; 372 ScopedMessagePipeHandle h1;
374 ASSERT_EQ(MOJO_RESULT_OK, CreateMessagePipe(nullptr, &h0, &h1)); 373 ASSERT_EQ(MOJO_RESULT_OK, CreateMessagePipe(nullptr, &h0, &h1));
375 374
376 // Send a handle over the previously-establish message pipe. 375 // Send a handle over the previously-establish message pipe.
377 ScopedMessagePipeHandle h2; 376 ScopedMessagePipeHandle h2;
378 ScopedMessagePipeHandle h3; 377 ScopedMessagePipeHandle h3;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 MOJO_WRITE_MESSAGE_FLAG_NONE)); 465 MOJO_WRITE_MESSAGE_FLAG_NONE));
467 // |h3_value| should actually be invalid now. 466 // |h3_value| should actually be invalid now.
468 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, MojoClose(h3_value)); 467 EXPECT_EQ(MOJO_RESULT_INVALID_ARGUMENT, MojoClose(h3_value));
469 468
470 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h2.release().value())); 469 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h2.release().value()));
471 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h0.release().value())); 470 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h0.release().value()));
472 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h1.release().value())); 471 EXPECT_EQ(MOJO_RESULT_OK, MojoClose(h1.release().value()));
473 } 472 }
474 } 473 }
475 474
476 TEST(CoreCppTest, ScopedHandleMoveCtor) { 475 TEST(CoreTest, ScopedHandleMoveCtor) {
477 ScopedSharedBufferHandle buffer1; 476 ScopedSharedBufferHandle buffer1;
478 EXPECT_EQ(MOJO_RESULT_OK, CreateSharedBuffer(nullptr, 1024, &buffer1)); 477 EXPECT_EQ(MOJO_RESULT_OK, CreateSharedBuffer(nullptr, 1024, &buffer1));
479 EXPECT_TRUE(buffer1.is_valid()); 478 EXPECT_TRUE(buffer1.is_valid());
480 479
481 ScopedSharedBufferHandle buffer2; 480 ScopedSharedBufferHandle buffer2;
482 EXPECT_EQ(MOJO_RESULT_OK, CreateSharedBuffer(nullptr, 1024, &buffer2)); 481 EXPECT_EQ(MOJO_RESULT_OK, CreateSharedBuffer(nullptr, 1024, &buffer2));
483 EXPECT_TRUE(buffer2.is_valid()); 482 EXPECT_TRUE(buffer2.is_valid());
484 483
485 // If this fails to close buffer1, ScopedHandleBase::CloseIfNecessary() will 484 // If this fails to close buffer1, ScopedHandleBase::CloseIfNecessary() will
486 // assert. 485 // assert.
487 buffer1 = buffer2.Pass(); 486 buffer1 = buffer2.Pass();
488 487
489 EXPECT_TRUE(buffer1.is_valid()); 488 EXPECT_TRUE(buffer1.is_valid());
490 EXPECT_FALSE(buffer2.is_valid()); 489 EXPECT_FALSE(buffer2.is_valid());
491 } 490 }
492 491
493 TEST(CoreCppTest, ScopedHandleMoveCtorSelf) { 492 TEST(CoreTest, ScopedHandleMoveCtorSelf) {
494 ScopedSharedBufferHandle buffer1; 493 ScopedSharedBufferHandle buffer1;
495 EXPECT_EQ(MOJO_RESULT_OK, CreateSharedBuffer(nullptr, 1024, &buffer1)); 494 EXPECT_EQ(MOJO_RESULT_OK, CreateSharedBuffer(nullptr, 1024, &buffer1));
496 EXPECT_TRUE(buffer1.is_valid()); 495 EXPECT_TRUE(buffer1.is_valid());
497 496
498 buffer1 = buffer1.Pass(); 497 buffer1 = buffer1.Pass();
499 498
500 EXPECT_TRUE(buffer1.is_valid()); 499 EXPECT_TRUE(buffer1.is_valid());
501 } 500 }
502 501
503 TEST(CoreCppTest, WaitManyResult) { 502 TEST(CoreTest, WaitManyResult) {
504 { 503 {
505 WaitManyResult wmr(MOJO_RESULT_OK); 504 WaitManyResult wmr(MOJO_RESULT_OK);
506 EXPECT_FALSE(wmr.IsIndexValid()); 505 EXPECT_FALSE(wmr.IsIndexValid());
507 EXPECT_TRUE(wmr.AreSignalsStatesValid()); 506 EXPECT_TRUE(wmr.AreSignalsStatesValid());
508 EXPECT_EQ(MOJO_RESULT_OK, wmr.result); 507 EXPECT_EQ(MOJO_RESULT_OK, wmr.result);
509 } 508 }
510 509
511 { 510 {
512 WaitManyResult wmr(MOJO_RESULT_FAILED_PRECONDITION); 511 WaitManyResult wmr(MOJO_RESULT_FAILED_PRECONDITION);
513 EXPECT_FALSE(wmr.IsIndexValid()); 512 EXPECT_FALSE(wmr.IsIndexValid());
(...skipping 23 matching lines...) Expand all
537 536
538 { 537 {
539 WaitManyResult wmr(MOJO_RESULT_FAILED_PRECONDITION, 5u); 538 WaitManyResult wmr(MOJO_RESULT_FAILED_PRECONDITION, 5u);
540 EXPECT_TRUE(wmr.IsIndexValid()); 539 EXPECT_TRUE(wmr.IsIndexValid());
541 EXPECT_TRUE(wmr.AreSignalsStatesValid()); 540 EXPECT_TRUE(wmr.AreSignalsStatesValid());
542 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, wmr.result); 541 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, wmr.result);
543 EXPECT_EQ(5u, wmr.index); 542 EXPECT_EQ(5u, wmr.index);
544 } 543 }
545 } 544 }
546 545
547 TEST(CoreCppTest, DataPipe) { 546 TEST(CoreTest, DataPipe) {
548 ScopedDataPipeProducerHandle ph; 547 ScopedDataPipeProducerHandle ph;
549 ScopedDataPipeConsumerHandle ch; 548 ScopedDataPipeConsumerHandle ch;
550 549
551 ASSERT_EQ(MOJO_RESULT_OK, CreateDataPipe(nullptr, &ph, &ch)); 550 ASSERT_EQ(MOJO_RESULT_OK, CreateDataPipe(nullptr, &ph, &ch));
552 ASSERT_TRUE(ph.get().is_valid()); 551 ASSERT_TRUE(ph.get().is_valid());
553 ASSERT_TRUE(ch.get().is_valid()); 552 ASSERT_TRUE(ch.get().is_valid());
554 553
555 uint32_t read_threshold = 123u; 554 uint32_t read_threshold = 123u;
556 EXPECT_EQ(MOJO_RESULT_OK, 555 EXPECT_EQ(MOJO_RESULT_OK,
557 GetDataPipeConsumerOptions(ch.get(), &read_threshold)); 556 GetDataPipeConsumerOptions(ch.get(), &read_threshold));
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 // Close the producer. 637 // Close the producer.
639 ph.reset(); 638 ph.reset();
640 639
641 // Waiting for "read" should now fail. 640 // Waiting for "read" should now fail.
642 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, 641 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
643 Wait(ch.get(), MOJO_HANDLE_SIGNAL_READ_THRESHOLD, 1000, nullptr)); 642 Wait(ch.get(), MOJO_HANDLE_SIGNAL_READ_THRESHOLD, 1000, nullptr));
644 } 643 }
645 644
646 } // namespace 645 } // namespace
647 } // namespace mojo 646 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/system/tests/BUILD.gn ('k') | mojo/public/cpp/system/tests/macros_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698