| 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/cpp/application/application_test_base.h" | 5 #include "mojo/public/cpp/application/application_test_base.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "mojo/public/cpp/application/application_impl.h" | 9 #include "mojo/public/cpp/application/application_impl.h" |
| 10 #include "mojo/public/cpp/bindings/binding.h" | 10 #include "mojo/public/cpp/bindings/binding.h" |
| 11 #include "mojo/public/cpp/environment/environment.h" | 11 #include "mojo/public/cpp/environment/environment.h" |
| 12 #include "mojo/public/cpp/system/message_pipe.h" | 12 #include "mojo/public/cpp/system/message_pipe.h" |
| 13 #include "mojo/public/interfaces/application/application.mojom.h" | 13 #include "mojo/public/interfaces/application/application.mojom.h" |
| 14 | 14 |
| 15 namespace mojo { | 15 namespace mojo { |
| 16 namespace test { | 16 namespace test { |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 |
| 19 // Share the application command-line arguments with multiple application tests. | 20 // Share the application command-line arguments with multiple application tests. |
| 20 Array<String> g_args; | 21 Array<String> g_args; |
| 21 | 22 |
| 22 // Share the application URL with multiple application tests. | 23 // Share the application URL with multiple application tests. |
| 23 String g_url; | 24 String g_url; |
| 24 | 25 |
| 25 // Application request handle passed from the shell in MojoMain, stored in | 26 // Application request handle passed from the shell in MojoMain, stored in |
| 26 // between SetUp()/TearDown() so we can (re-)intialize new ApplicationImpls. | 27 // between SetUp()/TearDown() so we can (re-)intialize new ApplicationImpls. |
| 27 InterfaceRequest<Application> g_application_request; | 28 InterfaceRequest<Application> g_application_request; |
| 28 | 29 |
| 29 // Shell pointer passed in the initial mojo.Application.Initialize() call, | 30 // Shell pointer passed in the initial mojo.Application.Initialize() call, |
| 30 // stored in between initial setup and the first test and between SetUp/TearDown | 31 // stored in between initial setup and the first test and between SetUp/TearDown |
| 31 // calls so we can (re-)initialize new ApplicationImpls. | 32 // calls so we can (re-)initialize new ApplicationImpls. |
| 32 ShellPtr g_shell; | 33 ShellPtr g_shell; |
| 33 | 34 |
| 34 void InitializeArgs(int argc, std::vector<const char*> argv) { | 35 void InitializeArgs(int argc, const char** argv) { |
| 35 MOJO_CHECK(g_args.is_null()); | 36 MOJO_CHECK(g_args.is_null()); |
| 36 for (const char* arg : argv) { | 37 for (int i = 0; i < argc; i++) { |
| 37 if (arg) | 38 MOJO_CHECK(argv[i]); |
| 38 g_args.push_back(arg); | 39 g_args.push_back(argv[i]); |
| 39 } | 40 } |
| 40 } | 41 } |
| 41 | 42 |
| 42 class ShellAndArgumentGrabber : public Application { | 43 class ShellAndArgumentGrabber : public Application { |
| 43 public: | 44 public: |
| 44 ShellAndArgumentGrabber(Array<String>* args, | 45 ShellAndArgumentGrabber(Array<String>* args, |
| 45 InterfaceRequest<Application> application_request) | 46 InterfaceRequest<Application> application_request) |
| 46 : args_(args), binding_(this, application_request.Pass()) {} | 47 : args_(args), binding_(this, application_request.Pass()) {} |
| 47 | 48 |
| 48 void WaitForInitialize() { | 49 void WaitForInitialize() { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 // InitGoogleTest expects (argc + 1) elements, including a terminating null. | 101 // InitGoogleTest expects (argc + 1) elements, including a terminating null. |
| 101 // It also removes GTEST arguments from |argv| and updates the |argc| count. | 102 // It also removes GTEST arguments from |argv| and updates the |argc| count. |
| 102 MOJO_CHECK(args.size() < | 103 MOJO_CHECK(args.size() < |
| 103 static_cast<size_t>(std::numeric_limits<int>::max())); | 104 static_cast<size_t>(std::numeric_limits<int>::max())); |
| 104 int argc = static_cast<int>(args.size()); | 105 int argc = static_cast<int>(args.size()); |
| 105 std::vector<const char*> argv(argc + 1); | 106 std::vector<const char*> argv(argc + 1); |
| 106 for (int i = 0; i < argc; ++i) | 107 for (int i = 0; i < argc; ++i) |
| 107 argv[i] = args[i].get().c_str(); | 108 argv[i] = args[i].get().c_str(); |
| 108 argv[argc] = nullptr; | 109 argv[argc] = nullptr; |
| 109 | 110 |
| 110 testing::InitGoogleTest(&argc, const_cast<char**>(&(argv[0]))); | 111 // Note: |InitGoogleTest()| will modify |argc| and |argv[...]|. |
| 111 InitializeArgs(argc, argv); | 112 testing::InitGoogleTest(&argc, const_cast<char**>(&argv[0])); |
| 113 InitializeArgs(argc, &argv[0]); |
| 112 | 114 |
| 113 Environment::DestroyDefaultRunLoop(); | 115 Environment::DestroyDefaultRunLoop(); |
| 114 } | 116 } |
| 115 | 117 |
| 116 int result = RUN_ALL_TESTS(); | 118 int result = RUN_ALL_TESTS(); |
| 117 | 119 |
| 118 // Shut down our message pipes before exiting. | 120 // Shut down our message pipes before exiting. |
| 119 (void)g_application_request.PassMessagePipe(); | 121 (void)g_application_request.PassMessagePipe(); |
| 120 (void)g_shell.PassInterfaceHandle(); | 122 (void)g_shell.PassInterfaceHandle(); |
| 121 | 123 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 if (ShouldCreateDefaultRunLoop()) | 160 if (ShouldCreateDefaultRunLoop()) |
| 159 Environment::DestroyDefaultRunLoop(); | 161 Environment::DestroyDefaultRunLoop(); |
| 160 } | 162 } |
| 161 | 163 |
| 162 bool ApplicationTestBase::ShouldCreateDefaultRunLoop() { | 164 bool ApplicationTestBase::ShouldCreateDefaultRunLoop() { |
| 163 return true; | 165 return true; |
| 164 } | 166 } |
| 165 | 167 |
| 166 } // namespace test | 168 } // namespace test |
| 167 } // namespace mojo | 169 } // namespace mojo |
| OLD | NEW |