Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1876)

Unified Diff: mojo/public/cpp/application/lib/application_test_base.cc

Issue 830593003: Update mojo sdk to rev 9fbbc4f0fef1187312316c0ed992342474e139f1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cherry-pick mojo 9d3b8dd17f12d20035a14737fdc38dd926890ff8 Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/public/cpp/application/lib/application_test_base.cc
diff --git a/mojo/public/cpp/application/lib/application_test_base.cc b/mojo/public/cpp/application/lib/application_test_base.cc
index 864289e2f2e99513f816a5cbaecf00193b572cc5..20a60a11b3ee49086801c60f1fd28de4b6e771a7 100644
--- a/mojo/public/cpp/application/lib/application_test_base.cc
+++ b/mojo/public/cpp/application/lib/application_test_base.cc
@@ -19,8 +19,6 @@ MessagePipeHandle g_shell_handle;
// Share the application command-line arguments with multiple application tests.
Array<String> g_args;
-} // namespace
-
ScopedMessagePipeHandle PassShellHandle() {
MOJO_CHECK(g_shell_handle.is_valid());
ScopedMessagePipeHandle scoped_handle(g_shell_handle);
@@ -34,10 +32,6 @@ void SetShellHandle(ScopedMessagePipeHandle handle) {
g_shell_handle = handle.release();
}
-const Array<String>& Args() {
- return g_args;
-}
-
void InitializeArgs(int argc, std::vector<const char*> argv) {
MOJO_CHECK(g_args.is_null());
for (const char* arg : argv) {
@@ -46,6 +40,52 @@ void InitializeArgs(int argc, std::vector<const char*> argv) {
}
}
+} // namespace
+
+const Array<String>& Args() {
+ return g_args;
+}
+
+MojoResult RunAllTests(MojoHandle shell_handle) {
+ {
+ // This loop is used for init, and then destroyed before running tests.
+ Environment::InstantiateDefaultRunLoop();
+
+ // Construct an ApplicationImpl just for the GTEST commandline arguments.
+ // GTEST command line arguments are supported amid application arguments:
+ // $ mojo_shell mojo:example_apptests
+ // --args-for='mojo:example_apptests arg1 --gtest_filter=foo arg2'
+ mojo::ApplicationDelegate dummy_application_delegate;
+ mojo::ApplicationImpl app(&dummy_application_delegate, shell_handle);
+ MOJO_CHECK(app.WaitForInitialize());
+
+ // InitGoogleTest expects (argc + 1) elements, including a terminating null.
+ // It also removes GTEST arguments from |argv| and updates the |argc| count.
+ const std::vector<std::string>& args = app.args();
+ MOJO_CHECK(args.size() <
+ static_cast<size_t>(std::numeric_limits<int>::max()));
+ int argc = static_cast<int>(args.size());
+ std::vector<const char*> argv(argc + 1);
+ for (int i = 0; i < argc; ++i)
+ argv[i] = args[i].c_str();
+ argv[argc] = nullptr;
+
+ testing::InitGoogleTest(&argc, const_cast<char**>(&(argv[0])));
+ SetShellHandle(app.UnbindShell());
+ InitializeArgs(argc, argv);
+
+ Environment::DestroyDefaultRunLoop();
+ }
+
+ int result = RUN_ALL_TESTS();
+
+ 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;
+}
+
ApplicationTestBase::ApplicationTestBase() : application_impl_(nullptr) {
}
« no previous file with comments | « mojo/public/cpp/application/application_test_base.h ('k') | mojo/public/cpp/application/lib/application_test_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698