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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 if (!text2.empty()) { | 87 if (!text2.empty()) { |
88 CreateMessagePipe(NULL, &pipe0, &pipe1_); | 88 CreateMessagePipe(NULL, &pipe0, &pipe1_); |
89 EXPECT_TRUE(WriteTextMessage(pipe1_.get(), text2)); | 89 EXPECT_TRUE(WriteTextMessage(pipe1_.get(), text2)); |
90 } | 90 } |
91 | 91 |
92 sample::ResponsePtr response(sample::Response::New()); | 92 sample::ResponsePtr response(sample::Response::New()); |
93 response->x = 2; | 93 response->x = 2; |
94 response->pipe = pipe0.Pass(); | 94 response->pipe = pipe0.Pass(); |
95 client()->DidStuff(response.Pass(), text1); | 95 client()->DidStuff(response.Pass(), text1); |
96 | 96 |
97 if (request->obj.get()) | 97 if (request->obj) |
98 request->obj->DoSomething(); | 98 request->obj->DoSomething(); |
99 } | 99 } |
100 | 100 |
101 virtual void DoStuff2(ScopedDataPipeConsumerHandle pipe) MOJO_OVERRIDE { | 101 virtual void DoStuff2(ScopedDataPipeConsumerHandle pipe) MOJO_OVERRIDE { |
102 // Read the data from the pipe, writing the response (as a string) to | 102 // Read the data from the pipe, writing the response (as a string) to |
103 // DidStuff2(). | 103 // DidStuff2(). |
104 ASSERT_TRUE(pipe.is_valid()); | 104 ASSERT_TRUE(pipe.is_valid()); |
105 uint32_t data_size = 0; | 105 uint32_t data_size = 0; |
106 ASSERT_EQ(MOJO_RESULT_OK, | 106 ASSERT_EQ(MOJO_RESULT_OK, |
107 ReadDataRaw(pipe.get(), NULL, &data_size, | 107 ReadDataRaw(pipe.get(), NULL, &data_size, |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 EXPECT_FALSE(internal::IsHandle<int>::value); | 328 EXPECT_FALSE(internal::IsHandle<int>::value); |
329 EXPECT_FALSE(internal::IsHandle<sample::FactoryPtr>::value); | 329 EXPECT_FALSE(internal::IsHandle<sample::FactoryPtr>::value); |
330 EXPECT_FALSE(internal::IsHandle<String>::value); | 330 EXPECT_FALSE(internal::IsHandle<String>::value); |
331 } | 331 } |
332 | 332 |
333 TEST_F(HandlePassingTest, CreateNamedObject) { | 333 TEST_F(HandlePassingTest, CreateNamedObject) { |
334 sample::FactoryPtr factory; | 334 sample::FactoryPtr factory; |
335 BindToProxy(new SampleFactoryImpl(), &factory); | 335 BindToProxy(new SampleFactoryImpl(), &factory); |
336 | 336 |
337 sample::NamedObjectPtr object1; | 337 sample::NamedObjectPtr object1; |
338 EXPECT_FALSE(object1.get()); | 338 EXPECT_FALSE(object1); |
339 | 339 |
340 InterfaceRequest<sample::NamedObject> object1_request = Get(&object1); | 340 InterfaceRequest<sample::NamedObject> object1_request = Get(&object1); |
341 EXPECT_TRUE(object1_request.is_pending()); | 341 EXPECT_TRUE(object1_request.is_pending()); |
342 factory->CreateNamedObject(object1_request.Pass()); | 342 factory->CreateNamedObject(object1_request.Pass()); |
343 EXPECT_FALSE(object1_request.is_pending()); // We've passed the request. | 343 EXPECT_FALSE(object1_request.is_pending()); // We've passed the request. |
344 | 344 |
345 ASSERT_TRUE(object1.get()); | 345 ASSERT_TRUE(object1); |
346 object1->SetName("object1"); | 346 object1->SetName("object1"); |
347 | 347 |
348 sample::NamedObjectPtr object2; | 348 sample::NamedObjectPtr object2; |
349 factory->CreateNamedObject(Get(&object2)); | 349 factory->CreateNamedObject(Get(&object2)); |
350 object2->SetName("object2"); | 350 object2->SetName("object2"); |
351 | 351 |
352 std::string name1; | 352 std::string name1; |
353 object1->GetName(StringRecorder(&name1)); | 353 object1->GetName(StringRecorder(&name1)); |
354 | 354 |
355 std::string name2; | 355 std::string name2; |
356 object2->GetName(StringRecorder(&name2)); | 356 object2->GetName(StringRecorder(&name2)); |
357 | 357 |
358 PumpMessages(); // Yield for results. | 358 PumpMessages(); // Yield for results. |
359 | 359 |
360 EXPECT_EQ(std::string("object1"), name1); | 360 EXPECT_EQ(std::string("object1"), name1); |
361 EXPECT_EQ(std::string("object2"), name2); | 361 EXPECT_EQ(std::string("object2"), name2); |
362 } | 362 } |
363 | 363 |
364 } // namespace | 364 } // namespace |
365 } // namespace test | 365 } // namespace test |
366 } // namespace mojo | 366 } // namespace mojo |
OLD | NEW |