OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "mojo/examples/apptest/example_client_application.h" | |
6 #include "mojo/examples/apptest/example_client_impl.h" | |
7 #include "mojo/examples/apptest/example_service.mojom.h" | |
8 #include "mojo/public/cpp/application/application_impl.h" | |
9 #include "mojo/public/cpp/application/application_test_base.h" | |
10 #include "mojo/public/cpp/bindings/callback.h" | |
11 #include "mojo/public/cpp/environment/logging.h" | |
12 #include "mojo/public/cpp/system/macros.h" | |
13 | |
14 namespace mojo { | |
15 namespace { | |
16 | |
17 // Exemplifies ApplicationTestBase's application testing pattern. | |
18 class ExampleApplicationTest : public test::ApplicationTestBase { | |
19 public: | |
20 // TODO(msw): Exemplify the use of actual command line arguments. | |
21 ExampleApplicationTest() : ApplicationTestBase(Array<String>()) {} | |
22 ~ExampleApplicationTest() override {} | |
23 | |
24 protected: | |
25 // ApplicationTestBase: | |
26 ApplicationDelegate* GetApplicationDelegate() override { | |
27 return &example_client_application_; | |
28 } | |
29 void SetUp() override { | |
30 ApplicationTestBase::SetUp(); | |
31 application_impl()->ConnectToService("mojo:example_service", | |
32 &example_service_); | |
33 example_service_.set_client(&example_client_); | |
34 } | |
35 | |
36 ExampleServicePtr example_service_; | |
37 ExampleClientImpl example_client_; | |
38 | |
39 private: | |
40 ExampleClientApplication example_client_application_; | |
41 | |
42 MOJO_DISALLOW_COPY_AND_ASSIGN(ExampleApplicationTest); | |
43 }; | |
44 | |
45 TEST_F(ExampleApplicationTest, PongClientDirectly) { | |
46 // Test very basic standalone ExampleClient functionality. | |
47 ExampleClientImpl example_client; | |
48 EXPECT_EQ(0, example_client.last_pong_value()); | |
49 example_client.Pong(1); | |
50 EXPECT_EQ(1, example_client.last_pong_value()); | |
51 } | |
52 | |
53 TEST_F(ExampleApplicationTest, PingServiceToPongClient) { | |
54 // Test ExampleClient and ExampleService interaction. | |
55 EXPECT_EQ(0, example_client_.last_pong_value()); | |
56 example_service_->Ping(1); | |
57 EXPECT_TRUE(example_service_.WaitForIncomingMethodCall()); | |
58 EXPECT_EQ(1, example_client_.last_pong_value()); | |
59 } | |
60 | |
61 template <typename T> | |
62 struct SetCallback : public Callback<void()>::Runnable { | |
63 SetCallback(T* val, T result) : val_(val), result_(result) {} | |
64 ~SetCallback() override {} | |
65 void Run() const override { *val_ = result_; } | |
66 T* val_; | |
67 T result_; | |
68 }; | |
69 | |
70 TEST_F(ExampleApplicationTest, RunCallbackViaService) { | |
71 // Test ExampleService callback functionality. | |
72 bool was_run = false; | |
73 example_service_->RunCallback(SetCallback<bool>(&was_run, true)); | |
74 EXPECT_TRUE(example_service_.WaitForIncomingMethodCall()); | |
75 EXPECT_TRUE(was_run); | |
76 } | |
77 | |
78 } // namespace | |
79 } // namespace mojo | |
OLD | NEW |