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 "mojo/public/cpp/application/application_delegate.h" | 7 #include "mojo/public/cpp/application/application_delegate.h" |
8 #include "mojo/public/cpp/application/application_impl.h" | 8 #include "mojo/public/cpp/application/application_impl.h" |
9 #include "mojo/public/cpp/environment/environment.h" | 9 #include "mojo/public/cpp/environment/environment.h" |
10 #include "mojo/public/cpp/environment/logging.h" | 10 #include "mojo/public/cpp/environment/logging.h" |
11 #include "mojo/public/cpp/system/message_pipe.h" | 11 #include "mojo/public/cpp/system/message_pipe.h" |
12 | 12 |
13 namespace mojo { | 13 namespace mojo { |
14 namespace test { | 14 namespace test { |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 // This shell handle is shared by multiple test application instances. | 18 // This shell handle is shared by multiple test application instances. |
19 MessagePipeHandle g_shell_handle; | 19 MessagePipeHandle g_shell_handle; |
20 // Command-line args passed to the harness are available to any test | |
msw
2014/11/20 21:59:12
The args are actually passed to the test applicati
| |
21 // application instance. | |
22 Array<String> g_args; | |
20 | 23 |
21 } // namespace | 24 } // namespace |
22 | 25 |
23 ScopedMessagePipeHandle PassShellHandle() { | 26 ScopedMessagePipeHandle PassShellHandle() { |
24 MOJO_CHECK(g_shell_handle.is_valid()); | 27 MOJO_CHECK(g_shell_handle.is_valid()); |
25 ScopedMessagePipeHandle scoped_handle(g_shell_handle); | 28 ScopedMessagePipeHandle scoped_handle(g_shell_handle); |
26 g_shell_handle = MessagePipeHandle(); | 29 g_shell_handle = MessagePipeHandle(); |
27 return scoped_handle.Pass(); | 30 return scoped_handle.Pass(); |
28 } | 31 } |
29 | 32 |
30 void SetShellHandle(ScopedMessagePipeHandle handle) { | 33 void SetShellHandle(ScopedMessagePipeHandle handle) { |
31 MOJO_CHECK(handle.is_valid()); | 34 MOJO_CHECK(handle.is_valid()); |
32 MOJO_CHECK(!g_shell_handle.is_valid()); | 35 MOJO_CHECK(!g_shell_handle.is_valid()); |
33 g_shell_handle = handle.release(); | 36 g_shell_handle = handle.release(); |
34 } | 37 } |
35 | 38 |
39 const Array<String>& Args() { | |
msw
2014/11/20 21:59:12
nit: can this be inlined in the header as args()?
Chris Masone
2014/11/20 23:35:19
I actually don't think so, as g_args is defined on
msw
2014/11/22 18:23:38
Acknowledged.
| |
40 return g_args; | |
41 } | |
42 | |
43 void InitializeArgs(int argc, std::vector<const char*> argv) { | |
44 MOJO_CHECK(g_args.is_null()); | |
45 for (const char* arg : argv) { | |
46 if (arg) | |
msw
2014/11/20 21:59:12
When are these ever null?
Chris Masone
2014/11/20 23:35:19
After processing by the gtest library, the last ar
msw
2014/11/22 18:23:38
Ah, OK. This is fine as-is.
| |
47 g_args.push_back(arg); | |
48 } | |
49 } | |
50 | |
36 ApplicationTestBase::ApplicationTestBase(Array<String> args) | 51 ApplicationTestBase::ApplicationTestBase(Array<String> args) |
37 : args_(args.Pass()), application_impl_(nullptr) { | 52 : args_(args.Pass()), application_impl_(nullptr) { |
38 } | 53 } |
39 | 54 |
40 ApplicationTestBase::~ApplicationTestBase() { | 55 ApplicationTestBase::~ApplicationTestBase() { |
41 } | 56 } |
42 | 57 |
43 void ApplicationTestBase::SetUp() { | 58 void ApplicationTestBase::SetUp() { |
44 // A run loop is needed for ApplicationImpl initialization and communication. | 59 // A run loop is needed for ApplicationImpl initialization and communication. |
45 Environment::InstantiateDefaultRunLoop(); | 60 Environment::InstantiateDefaultRunLoop(); |
46 | 61 |
47 // New applications are constructed for each test to avoid persisting state. | 62 // New applications are constructed for each test to avoid persisting state. |
48 application_impl_ = new ApplicationImpl(GetApplicationDelegate(), | 63 application_impl_ = new ApplicationImpl(GetApplicationDelegate(), |
49 PassShellHandle()); | 64 PassShellHandle()); |
50 | 65 |
51 // Fake application initialization with the given command line arguments. | 66 // Fake application initialization with the given command line arguments. |
52 application_impl_->Initialize(args_.Clone()); | 67 application_impl_->Initialize(args_.Clone()); |
53 } | 68 } |
54 | 69 |
55 void ApplicationTestBase::TearDown() { | 70 void ApplicationTestBase::TearDown() { |
56 SetShellHandle(application_impl_->UnbindShell()); | 71 SetShellHandle(application_impl_->UnbindShell()); |
57 delete application_impl_; | 72 delete application_impl_; |
58 Environment::DestroyDefaultRunLoop(); | 73 Environment::DestroyDefaultRunLoop(); |
59 } | 74 } |
60 | 75 |
61 } // namespace test | 76 } // namespace test |
62 } // namespace mojo | 77 } // namespace mojo |
OLD | NEW |