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 <limits.h> |
| 6 |
5 #include "mojo/examples/apptest/example_client_application.h" | 7 #include "mojo/examples/apptest/example_client_application.h" |
6 #include "mojo/examples/apptest/example_client_impl.h" | 8 #include "mojo/examples/apptest/example_client_impl.h" |
7 #include "mojo/examples/apptest/example_service.mojom.h" | 9 #include "mojo/examples/apptest/example_service.mojom.h" |
8 #include "mojo/public/c/system/main.h" | 10 #include "mojo/public/c/system/main.h" |
9 #include "mojo/public/cpp/application/application_impl.h" | 11 #include "mojo/public/cpp/application/application_impl.h" |
| 12 #include "mojo/public/cpp/bindings/array.h" |
10 #include "mojo/public/cpp/bindings/callback.h" | 13 #include "mojo/public/cpp/bindings/callback.h" |
| 14 #include "mojo/public/cpp/bindings/string.h" |
11 #include "mojo/public/cpp/environment/environment.h" | 15 #include "mojo/public/cpp/environment/environment.h" |
| 16 #include "mojo/public/cpp/environment/logging.h" |
12 #include "mojo/public/cpp/system/macros.h" | 17 #include "mojo/public/cpp/system/macros.h" |
13 #include "mojo/public/cpp/utility/run_loop.h" | 18 #include "mojo/public/cpp/utility/run_loop.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
15 | 20 |
16 namespace { | 21 namespace { |
17 | 22 |
18 // TODO(msw): Remove this once we can get ApplicationImpl from TLS. | 23 // TODO(msw): Remove this once we can get ApplicationImpl from TLS. |
19 mojo::ApplicationImpl* g_application_impl_hack = NULL; | 24 mojo::ApplicationImpl* g_application_impl_hack = NULL; |
20 | 25 |
21 } // namespace | 26 } // namespace |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 MojoResult MojoMain(MojoHandle shell_handle) { | 87 MojoResult MojoMain(MojoHandle shell_handle) { |
83 mojo::Environment env; | 88 mojo::Environment env; |
84 // TODO(msw): Destroy this ambient RunLoop before running tests. | 89 // TODO(msw): Destroy this ambient RunLoop before running tests. |
85 // Need to CancelWait() / PassMessagePipe() from the ShellPtr? | 90 // Need to CancelWait() / PassMessagePipe() from the ShellPtr? |
86 mojo::RunLoop loop; | 91 mojo::RunLoop loop; |
87 mojo::ApplicationDelegate* delegate = new mojo::ExampleClientApplication(); | 92 mojo::ApplicationDelegate* delegate = new mojo::ExampleClientApplication(); |
88 mojo::ApplicationImpl app(delegate, shell_handle); | 93 mojo::ApplicationImpl app(delegate, shell_handle); |
89 g_application_impl_hack = &app; | 94 g_application_impl_hack = &app; |
90 MOJO_CHECK(app.WaitForInitialize()); | 95 MOJO_CHECK(app.WaitForInitialize()); |
91 | 96 |
92 // TODO(msw): Plumb commandline arguments through app->args(). | 97 { |
93 int argc = 0; | 98 // InitGoogleTest expects (argc + 1) elements, including a terminating NULL. |
94 char** argv = NULL; | 99 // It also removes GTEST arguments from |argv| and updates the |argc| count. |
95 testing::InitGoogleTest(&argc, argv); | 100 const mojo::Array<mojo::String>& args = app.args(); |
| 101 MOJO_CHECK(args.size() < INT_MAX); |
| 102 int argc = static_cast<int>(args.size()); |
| 103 std::vector<char*> argv(argc + 1); |
| 104 for (int i = 0; i < argc; ++i) |
| 105 argv[i] = const_cast<char*>(args[i].data()); |
| 106 argv[argc] = NULL; |
| 107 testing::InitGoogleTest(&argc, &argv[0]); |
| 108 } |
| 109 |
96 mojo_ignore_result(RUN_ALL_TESTS()); | 110 mojo_ignore_result(RUN_ALL_TESTS()); |
97 | 111 |
98 delete delegate; | 112 delete delegate; |
99 return MOJO_RESULT_OK; | 113 return MOJO_RESULT_OK; |
100 } | 114 } |
OLD | NEW |