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

Unified Diff: mojo/examples/apptest/example_apptest.cc

Issue 626033003: Plumb commandline arguments for mojo_example_apptests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@example_apptests_init
Patch Set: Include <limits.h> Created 6 years, 2 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/examples/apptest/example_apptest.cc
diff --git a/mojo/examples/apptest/example_apptest.cc b/mojo/examples/apptest/example_apptest.cc
index cd1c7d8db665ecbc5425f66c2d86dec826b55b28..c754c85e3b7b56dc959a8a357fe54dc7531593e7 100644
--- a/mojo/examples/apptest/example_apptest.cc
+++ b/mojo/examples/apptest/example_apptest.cc
@@ -2,13 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <limits.h>
+
#include "mojo/examples/apptest/example_client_application.h"
#include "mojo/examples/apptest/example_client_impl.h"
#include "mojo/examples/apptest/example_service.mojom.h"
#include "mojo/public/c/system/main.h"
#include "mojo/public/cpp/application/application_impl.h"
+#include "mojo/public/cpp/bindings/array.h"
#include "mojo/public/cpp/bindings/callback.h"
+#include "mojo/public/cpp/bindings/string.h"
#include "mojo/public/cpp/environment/environment.h"
+#include "mojo/public/cpp/environment/logging.h"
#include "mojo/public/cpp/system/macros.h"
#include "mojo/public/cpp/utility/run_loop.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -89,10 +94,19 @@ MojoResult MojoMain(MojoHandle shell_handle) {
g_application_impl_hack = &app;
MOJO_CHECK(app.WaitForInitialize());
- // TODO(msw): Plumb commandline arguments through app->args().
- int argc = 0;
- char** argv = NULL;
- testing::InitGoogleTest(&argc, argv);
+ {
+ // InitGoogleTest expects (argc + 1) elements, including a terminating NULL.
+ // It also removes GTEST arguments from |argv| and updates the |argc| count.
+ const mojo::Array<mojo::String>& args = app.args();
+ MOJO_CHECK(args.size() < INT_MAX);
+ int argc = static_cast<int>(args.size());
+ std::vector<char*> argv(argc + 1);
+ for (int i = 0; i < argc; ++i)
+ argv[i] = const_cast<char*>(args[i].data());
+ argv[argc] = NULL;
+ testing::InitGoogleTest(&argc, &argv[0]);
+ }
+
mojo_ignore_result(RUN_ALL_TESTS());
delete delegate;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698