Index: mojo/public/cpp/application/lib/application_test_main.cc |
diff --git a/mojo/public/cpp/application/lib/application_test_base.cc b/mojo/public/cpp/application/lib/application_test_main.cc |
similarity index 54% |
copy from mojo/public/cpp/application/lib/application_test_base.cc |
copy to mojo/public/cpp/application/lib/application_test_main.cc |
index 76e1c95485120a4311d5f1da6f45b7a0cad10d3d..be4e54ef1125c371740cfc3210be9f818919849b 100644 |
--- a/mojo/public/cpp/application/lib/application_test_base.cc |
+++ b/mojo/public/cpp/application/lib/application_test_main.cc |
@@ -2,66 +2,19 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "mojo/public/cpp/application/application_test_base.h" |
- |
#include "mojo/public/c/system/main.h" |
#include "mojo/public/cpp/application/application_delegate.h" |
#include "mojo/public/cpp/application/application_impl.h" |
+#include "mojo/public/cpp/application/application_test_base.h" |
#include "mojo/public/cpp/environment/logging.h" |
#include "mojo/public/cpp/system/message_pipe.h" |
-#include "mojo/public/cpp/utility/lib/thread_local.h" |
-#include "mojo/public/cpp/utility/run_loop.h" |
- |
-namespace mojo { |
-namespace test { |
- |
-namespace { |
- |
-// This global shell handle is needed for repeated use by test applications. |
-MessagePipeHandle test_shell_handle; |
- |
-// TODO(msw): Support base::MessageLoop environments. |
-internal::ThreadLocalPointer<RunLoop> test_run_loop; |
- |
-} // namespace |
- |
-ApplicationTestBase::ApplicationTestBase(Array<String> args) |
- : args_(args.Pass()), application_impl_(nullptr) { |
-} |
-ApplicationTestBase::~ApplicationTestBase() { |
-} |
- |
-void ApplicationTestBase::SetUp() { |
- // A run loop is needed for ApplicationImpl initialization and communication. |
- test_run_loop.Set(new RunLoop()); |
- |
- // New applications are constructed for each test to avoid persisting state. |
- MOJO_CHECK(test_shell_handle.is_valid()); |
- application_impl_ = new ApplicationImpl(GetApplicationDelegate(), |
- MakeScopedHandle(test_shell_handle)); |
- |
- // Fake application initialization with the given command line arguments. |
- application_impl_->Initialize(args_.Clone()); |
-} |
- |
-void ApplicationTestBase::TearDown() { |
- test_shell_handle = application_impl_->UnbindShell().release(); |
- delete application_impl_; |
- delete test_run_loop.Get(); |
- test_run_loop.Set(nullptr); |
-} |
- |
-} // namespace test |
-} // namespace mojo |
- |
-// TODO(msw): Split this into an application_test_main.cc. |
MojoResult MojoMain(MojoHandle shell_handle) { |
mojo::Environment environment; |
{ |
// This RunLoop is used for init, and then destroyed before running tests. |
- mojo::RunLoop run_loop; |
+ mojo::Environment::InstantiateDefaultRunLoop(); |
// Construct an ApplicationImpl just for the GTEST commandline arguments. |
// GTEST command line arguments are supported amid application arguments: |
@@ -81,13 +34,16 @@ MojoResult MojoMain(MojoHandle shell_handle) { |
for (int i = 0; i < argc; ++i) |
argv[i] = args[i].c_str(); |
argv[argc] = nullptr; |
+ |
testing::InitGoogleTest(&argc, const_cast<char**>(&(argv[0]))); |
- mojo::test::test_shell_handle = app.UnbindShell().release(); |
+ mojo::test::SetShellHandle(app.UnbindShell()); |
+ mojo::Environment::DestroyDefaultRunLoop(); |
} |
int result = RUN_ALL_TESTS(); |
- MojoResult close_result = MojoClose(mojo::test::test_shell_handle.value()); |
+ shell_handle = mojo::test::PassShellHandle().release().value(); |
+ MojoResult close_result = MojoClose(shell_handle); |
MOJO_CHECK(close_result == MOJO_RESULT_OK); |
return (result == 0) ? MOJO_RESULT_OK : MOJO_RESULT_UNKNOWN; |