Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #include "mojo/examples/apptest/example_client_application.h" | 5 #include "mojo/examples/apptest/example_client_application.h" |
| 6 #include "mojo/examples/apptest/example_client_impl.h" | 6 #include "mojo/examples/apptest/example_client_impl.h" |
| 7 #include "mojo/examples/apptest/example_service.mojom.h" | 7 #include "mojo/examples/apptest/example_service.mojom.h" |
| 8 #include "mojo/public/c/system/main.h" | 8 #include "mojo/public/c/system/main.h" |
| 9 #include "mojo/public/cpp/application/application_impl.h" | 9 #include "mojo/public/cpp/application/application_impl.h" |
| 10 #include "mojo/public/cpp/bindings/callback.h" | 10 #include "mojo/public/cpp/bindings/callback.h" |
| 11 #include "mojo/public/cpp/environment/environment.h" | 11 #include "mojo/public/cpp/environment/environment.h" |
| 12 #include "mojo/public/cpp/system/macros.h" | 12 #include "mojo/public/cpp/system/macros.h" |
| 13 #include "mojo/public/cpp/utility/run_loop.h" | 13 #include "mojo/public/cpp/utility/run_loop.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 // TODO(msw): Remove this once we can get ApplicationImpl from TLS. | 18 // TODO(msw): Remove this once we can get ApplicationImpl from TLS. |
| 19 mojo::ApplicationImpl* g_application_impl_hack = NULL; | 19 mojo::ApplicationImpl* g_application_impl_hack = NULL; |
| 20 | 20 |
| 21 static const char kMojoExampleService[] = "mojo:mojo_example_service"; | |
| 22 | |
| 21 } // namespace | 23 } // namespace |
| 22 | 24 |
| 23 namespace mojo { | 25 namespace mojo { |
| 24 | 26 |
| 25 namespace { | 27 namespace { |
| 26 | 28 |
| 27 class ExampleApptest : public testing::Test { | 29 class ExampleApptest : public testing::Test { |
| 28 public: | 30 public: |
| 29 ExampleApptest() { | 31 ExampleApptest() { |
| 30 g_application_impl_hack->ConnectToService("mojo:mojo_example_service", | 32 g_application_impl_hack->ConnectToService(kMojoExampleService, |
| 31 &example_service_); | 33 &example_service_); |
| 32 example_service_.set_client(&example_client_); | 34 example_service_.set_client(&example_client_); |
| 33 } | 35 } |
| 34 | 36 |
| 35 virtual ~ExampleApptest() override {} | 37 virtual ~ExampleApptest() override {} |
| 36 | 38 |
| 37 protected: | 39 protected: |
| 38 ExampleServicePtr example_service_; | 40 ExampleServicePtr example_service_; |
| 39 ExampleClientImpl example_client_; | 41 ExampleClientImpl example_client_; |
| 40 | 42 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 82 MojoResult MojoMain(MojoHandle shell_handle) { | 84 MojoResult MojoMain(MojoHandle shell_handle) { |
| 83 mojo::Environment env; | 85 mojo::Environment env; |
| 84 // TODO(msw): Destroy this ambient RunLoop before running tests. | 86 // TODO(msw): Destroy this ambient RunLoop before running tests. |
| 85 // Need to CancelWait() / PassMessagePipe() from the ShellPtr? | 87 // Need to CancelWait() / PassMessagePipe() from the ShellPtr? |
| 86 mojo::RunLoop loop; | 88 mojo::RunLoop loop; |
| 87 mojo::ApplicationDelegate* delegate = new mojo::ExampleClientApplication(); | 89 mojo::ApplicationDelegate* delegate = new mojo::ExampleClientApplication(); |
| 88 mojo::ApplicationImpl app(delegate, shell_handle); | 90 mojo::ApplicationImpl app(delegate, shell_handle); |
| 89 g_application_impl_hack = &app; | 91 g_application_impl_hack = &app; |
| 90 MOJO_CHECK(app.WaitForInitialize()); | 92 MOJO_CHECK(app.WaitForInitialize()); |
| 91 | 93 |
| 92 // TODO(msw): Plumb commandline arguments through app->args(). | 94 std::vector<std::string> args = app.args().To<std::vector<std::string> >(); |
| 93 int argc = 0; | 95 int argc = args.size(); |
| 94 char** argv = NULL; | 96 std::vector<char *> argv(argc); |
| 95 testing::InitGoogleTest(&argc, argv); | 97 for (int i = 0; i < argc; ++i) |
|
hansmuller
2014/10/06 21:08:52
You might want to use size_t instead of int for th
msw
2014/10/06 21:32:33
InitGoogleTest eventually requires an int* :-/
| |
| 98 argv[i] = &args[i][0]; | |
| 99 testing::InitGoogleTest(&argc, argv.data()); | |
| 100 | |
| 96 mojo_ignore_result(RUN_ALL_TESTS()); | 101 mojo_ignore_result(RUN_ALL_TESTS()); |
| 97 | 102 |
| 98 delete delegate; | 103 delete delegate; |
| 99 return MOJO_RESULT_OK; | 104 return MOJO_RESULT_OK; |
| 100 } | 105 } |
| OLD | NEW |