OLD | NEW |
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 #include "mojo/public/cpp/environment/environment.h" | 5 #include "mojo/public/cpp/environment/environment.h" |
6 #include "mojo/public/cpp/test_support/test_utils.h" | 6 #include "mojo/public/cpp/test_support/test_utils.h" |
7 #include "mojo/public/cpp/utility/run_loop.h" | 7 #include "mojo/public/cpp/utility/run_loop.h" |
8 #include "mojo/public/interfaces/bindings/tests/sample_factory.mojom.h" | 8 #include "mojo/public/interfaces/bindings/tests/sample_factory.mojom.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 std::string text2; | 62 std::string text2; |
63 if (request->pipe.is_valid()) { | 63 if (request->pipe.is_valid()) { |
64 EXPECT_TRUE(ReadTextMessage(request->pipe.get(), &text2)); | 64 EXPECT_TRUE(ReadTextMessage(request->pipe.get(), &text2)); |
65 | 65 |
66 // Ensure that simply accessing request->pipe does not close it. | 66 // Ensure that simply accessing request->pipe does not close it. |
67 EXPECT_TRUE(request->pipe.is_valid()); | 67 EXPECT_TRUE(request->pipe.is_valid()); |
68 } | 68 } |
69 | 69 |
70 ScopedMessagePipeHandle pipe0; | 70 ScopedMessagePipeHandle pipe0; |
71 if (!text2.empty()) { | 71 if (!text2.empty()) { |
72 CreateMessagePipe(NULL, &pipe0, &pipe1_); | 72 CreateMessagePipe(nullptr, &pipe0, &pipe1_); |
73 EXPECT_TRUE(WriteTextMessage(pipe1_.get(), text2)); | 73 EXPECT_TRUE(WriteTextMessage(pipe1_.get(), text2)); |
74 } | 74 } |
75 | 75 |
76 sample::ResponsePtr response(sample::Response::New()); | 76 sample::ResponsePtr response(sample::Response::New()); |
77 response->x = 2; | 77 response->x = 2; |
78 response->pipe = pipe0.Pass(); | 78 response->pipe = pipe0.Pass(); |
79 client()->DidStuff(response.Pass(), text1); | 79 client()->DidStuff(response.Pass(), text1); |
80 | 80 |
81 if (request->obj) | 81 if (request->obj) |
82 request->obj->DoSomething(); | 82 request->obj->DoSomething(); |
83 } | 83 } |
84 | 84 |
85 virtual void DoStuff2(ScopedDataPipeConsumerHandle pipe) override { | 85 virtual void DoStuff2(ScopedDataPipeConsumerHandle pipe) override { |
86 // Read the data from the pipe, writing the response (as a string) to | 86 // Read the data from the pipe, writing the response (as a string) to |
87 // DidStuff2(). | 87 // DidStuff2(). |
88 ASSERT_TRUE(pipe.is_valid()); | 88 ASSERT_TRUE(pipe.is_valid()); |
89 uint32_t data_size = 0; | 89 uint32_t data_size = 0; |
90 ASSERT_EQ(MOJO_RESULT_OK, | 90 ASSERT_EQ(MOJO_RESULT_OK, |
91 ReadDataRaw(pipe.get(), NULL, &data_size, | 91 ReadDataRaw(pipe.get(), nullptr, &data_size, |
92 MOJO_READ_DATA_FLAG_QUERY)); | 92 MOJO_READ_DATA_FLAG_QUERY)); |
93 ASSERT_NE(0, static_cast<int>(data_size)); | 93 ASSERT_NE(0, static_cast<int>(data_size)); |
94 char data[64]; | 94 char data[64]; |
95 ASSERT_LT(static_cast<int>(data_size), 64); | 95 ASSERT_LT(static_cast<int>(data_size), 64); |
96 ASSERT_EQ(MOJO_RESULT_OK, | 96 ASSERT_EQ(MOJO_RESULT_OK, |
97 ReadDataRaw(pipe.get(), data, &data_size, | 97 ReadDataRaw(pipe.get(), data, &data_size, |
98 MOJO_READ_DATA_FLAG_ALL_OR_NONE)); | 98 MOJO_READ_DATA_FLAG_ALL_OR_NONE)); |
99 | 99 |
100 client()->DidStuff2(data); | 100 client()->DidStuff2(data); |
101 } | 101 } |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 | 341 |
342 PumpMessages(); // Yield for results. | 342 PumpMessages(); // Yield for results. |
343 | 343 |
344 EXPECT_EQ(std::string("object1"), name1); | 344 EXPECT_EQ(std::string("object1"), name1); |
345 EXPECT_EQ(std::string("object2"), name2); | 345 EXPECT_EQ(std::string("object2"), name2); |
346 } | 346 } |
347 | 347 |
348 } // namespace | 348 } // namespace |
349 } // namespace test | 349 } // namespace test |
350 } // namespace mojo | 350 } // namespace mojo |
OLD | NEW |