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/public/c/system/main.h" | 5 #include "mojo/public/c/system/main.h" |
6 #include "mojo/public/cpp/application/application_delegate.h" | 6 #include "mojo/public/cpp/application/application_delegate.h" |
7 #include "mojo/public/cpp/application/application_impl.h" | 7 #include "mojo/public/cpp/application/application_impl.h" |
8 #include "mojo/public/cpp/application/application_test_base.h" | 8 #include "mojo/public/cpp/application/application_test_base.h" |
| 9 #include "mojo/public/cpp/environment/environment.h" |
9 #include "mojo/public/cpp/environment/logging.h" | 10 #include "mojo/public/cpp/environment/logging.h" |
10 #include "mojo/public/cpp/system/message_pipe.h" | 11 #include "mojo/public/cpp/system/message_pipe.h" |
| 12 #include "mojo/public/cpp/utility/run_loop.h" |
11 | 13 |
12 MojoResult MojoMain(MojoHandle shell_handle) { | 14 MojoResult MojoMain(MojoHandle shell_handle) { |
13 // An Environment instance is needed to construct run loops. | 15 // An Environment instance is needed to construct run loops. |
14 mojo::Environment environment; | 16 mojo::Environment environment; |
15 | 17 |
16 { | 18 { |
17 // This RunLoop is used for init, and then destroyed before running tests. | 19 // This loop is used for init, and then destroyed before running tests. |
18 mojo::Environment::InstantiateDefaultRunLoop(); | 20 mojo::RunLoop run_loop; |
19 | 21 |
20 // Construct an ApplicationImpl just for the GTEST commandline arguments. | 22 // Construct an ApplicationImpl just for the GTEST commandline arguments. |
21 // GTEST command line arguments are supported amid application arguments: | 23 // GTEST command line arguments are supported amid application arguments: |
22 // $ mojo_shell 'mojo:example_apptests arg1 --gtest_filter=foo arg2' | 24 // $ mojo_shell 'mojo:example_apptests arg1 --gtest_filter=foo arg2' |
23 mojo::ApplicationDelegate dummy_application_delegate; | 25 mojo::ApplicationDelegate dummy_application_delegate; |
24 mojo::ApplicationImpl app(&dummy_application_delegate, shell_handle); | 26 mojo::ApplicationImpl app(&dummy_application_delegate, shell_handle); |
25 MOJO_CHECK(app.WaitForInitialize()); | 27 MOJO_CHECK(app.WaitForInitialize()); |
26 | 28 |
27 // InitGoogleTest expects (argc + 1) elements, including a terminating NULL. | 29 // InitGoogleTest expects (argc + 1) elements, including a terminating NULL. |
28 // It also removes GTEST arguments from |argv| and updates the |argc| count. | 30 // It also removes GTEST arguments from |argv| and updates the |argc| count. |
29 // TODO(msw): Provide tests access to these actual command line arguments. | 31 // TODO(msw): Provide tests access to these actual command line arguments. |
30 const std::vector<std::string>& args = app.args(); | 32 const std::vector<std::string>& args = app.args(); |
31 MOJO_CHECK(args.size() < | 33 MOJO_CHECK(args.size() < |
32 static_cast<size_t>(std::numeric_limits<int>::max())); | 34 static_cast<size_t>(std::numeric_limits<int>::max())); |
33 int argc = static_cast<int>(args.size()); | 35 int argc = static_cast<int>(args.size()); |
34 std::vector<const char*> argv(argc + 1); | 36 std::vector<const char*> argv(argc + 1); |
35 for (int i = 0; i < argc; ++i) | 37 for (int i = 0; i < argc; ++i) |
36 argv[i] = args[i].c_str(); | 38 argv[i] = args[i].c_str(); |
37 argv[argc] = nullptr; | 39 argv[argc] = nullptr; |
38 | 40 |
39 testing::InitGoogleTest(&argc, const_cast<char**>(&(argv[0]))); | 41 testing::InitGoogleTest(&argc, const_cast<char**>(&(argv[0]))); |
40 mojo::test::SetShellHandle(app.UnbindShell()); | 42 mojo::test::SetShellHandle(app.UnbindShell()); |
41 mojo::Environment::DestroyDefaultRunLoop(); | |
42 } | 43 } |
43 | 44 |
44 int result = RUN_ALL_TESTS(); | 45 int result = RUN_ALL_TESTS(); |
45 | 46 |
46 shell_handle = mojo::test::PassShellHandle().release().value(); | 47 shell_handle = mojo::test::PassShellHandle().release().value(); |
47 MojoResult close_result = MojoClose(shell_handle); | 48 MojoResult close_result = MojoClose(shell_handle); |
48 MOJO_CHECK(close_result == MOJO_RESULT_OK); | 49 MOJO_CHECK(close_result == MOJO_RESULT_OK); |
49 | 50 |
50 return (result == 0) ? MOJO_RESULT_OK : MOJO_RESULT_UNKNOWN; | 51 return (result == 0) ? MOJO_RESULT_OK : MOJO_RESULT_UNKNOWN; |
51 } | 52 } |
OLD | NEW |