summaryrefslogtreecommitdiffstats
path: root/mojo/public/cpp/application/lib/application_test_main.cc
diff options
context:
space:
mode:
authorjamesr <jamesr@chromium.org>2014-10-31 15:08:24 -0700
committerCommit bot <commit-bot@chromium.org>2014-10-31 22:08:55 +0000
commit904ce270798bd27f4f6fa4348838b00ee6e9a408 (patch)
treec697c74b2cc1cf2f286bfcad6c9340a3a7df4fe4 /mojo/public/cpp/application/lib/application_test_main.cc
parent82c6af625500a7bfdcf9f619c4e5702fa12f2b40 (diff)
downloadchromium_src-904ce270798bd27f4f6fa4348838b00ee6e9a408.zip
chromium_src-904ce270798bd27f4f6fa4348838b00ee6e9a408.tar.gz
chromium_src-904ce270798bd27f4f6fa4348838b00ee6e9a408.tar.bz2
Update mojo sdk to rev 91d94d6993c9b0c4135a95687a7d541ce90629b
Also includes changes from https://codereview.chromium.org/695953002/ to update html_viewer for API changes. Review URL: https://codereview.chromium.org/694923002 Cr-Commit-Position: refs/heads/master@{#302333}
Diffstat (limited to 'mojo/public/cpp/application/lib/application_test_main.cc')
-rw-r--r--mojo/public/cpp/application/lib/application_test_main.cc50
1 files changed, 50 insertions, 0 deletions
diff --git a/mojo/public/cpp/application/lib/application_test_main.cc b/mojo/public/cpp/application/lib/application_test_main.cc
new file mode 100644
index 0000000..be4e54e
--- /dev/null
+++ b/mojo/public/cpp/application/lib/application_test_main.cc
@@ -0,0 +1,50 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#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"
+
+MojoResult MojoMain(MojoHandle shell_handle) {
+ mojo::Environment environment;
+
+ {
+ // This RunLoop is used for init, and then destroyed before running tests.
+ mojo::Environment::InstantiateDefaultRunLoop();
+
+ // Construct an ApplicationImpl just for the GTEST commandline arguments.
+ // GTEST command line arguments are supported amid application arguments:
+ // $ mojo_shell 'mojo:example_apptest 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.
+ // TODO(msw): Provide tests access to these actual command line arguments.
+ 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])));
+ mojo::test::SetShellHandle(app.UnbindShell());
+ mojo::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;
+}