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

Side by Side Diff: mojo/application/application_test_main_chromium.cc

Issue 710403002: Add Mojo application test support to Chromium. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address some comments. Created 6 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « mojo/application/BUILD.gn ('k') | mojo/environment/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/at_exit.h"
6 #include "base/logging.h"
7 #include "base/message_loop/message_loop.h"
5 #include "mojo/public/c/system/main.h" 8 #include "mojo/public/c/system/main.h"
6 #include "mojo/public/cpp/application/application_delegate.h" 9 #include "mojo/public/cpp/application/application_delegate.h"
7 #include "mojo/public/cpp/application/application_impl.h" 10 #include "mojo/public/cpp/application/application_impl.h"
8 #include "mojo/public/cpp/application/application_test_base.h" 11 #include "mojo/public/cpp/application/application_test_base.h"
9 #include "mojo/public/cpp/environment/logging.h" 12 #include "mojo/public/cpp/environment/environment.h"
10 #include "mojo/public/cpp/system/message_pipe.h" 13 #include "mojo/public/cpp/system/message_pipe.h"
11 14
12 MojoResult MojoMain(MojoHandle shell_handle) { 15 MojoResult MojoMain(MojoHandle shell_handle) {
13 // An Environment instance is needed to construct run loops. 16 // An AtExitManager instance is needed to construct message loops.
14 mojo::Environment environment; 17 base::AtExitManager at_exit;
jamesr 2014/11/11 23:07:33 this is only needed if we're creating a base::Mess
msw 2014/11/11 23:18:28 Yes, this file (application_test_main_chromium.cc)
jamesr 2014/11/11 23:22:21 OK... then at line 21 why don't you just call base
msw 2014/11/11 23:29:33 For consistency with ApplicationTestBase and the s
15 18
16 { 19 {
17 // This RunLoop is used for init, and then destroyed before running tests. 20 // This RunLoop is used for init, and then destroyed before running tests.
18 mojo::Environment::InstantiateDefaultRunLoop(); 21 mojo::Environment::InstantiateDefaultRunLoop();
19 22
20 // Construct an ApplicationImpl just for the GTEST commandline arguments. 23 // Construct an ApplicationImpl just for the GTEST commandline arguments.
21 // GTEST command line arguments are supported amid application arguments: 24 // GTEST command line arguments are supported amid application arguments:
22 // $ mojo_shell 'mojo:example_apptests arg1 --gtest_filter=foo arg2' 25 // $ mojo_shell 'mojo:example_apptests arg1 --gtest_filter=foo arg2'
23 mojo::ApplicationDelegate dummy_application_delegate; 26 mojo::ApplicationDelegate dummy_application_delegate;
24 mojo::ApplicationImpl app(&dummy_application_delegate, shell_handle); 27 mojo::ApplicationImpl app(&dummy_application_delegate, shell_handle);
25 MOJO_CHECK(app.WaitForInitialize()); 28 CHECK(app.WaitForInitialize());
26 29
27 // InitGoogleTest expects (argc + 1) elements, including a terminating NULL. 30 // InitGoogleTest expects (argc + 1) elements, including a terminating NULL.
28 // It also removes GTEST arguments from |argv| and updates the |argc| count. 31 // It also removes GTEST arguments from |argv| and updates the |argc| count.
29 // TODO(msw): Provide tests access to these actual command line arguments. 32 // TODO(msw): Provide tests access to these actual command line arguments.
30 const std::vector<std::string>& args = app.args(); 33 const std::vector<std::string>& args = app.args();
31 MOJO_CHECK(args.size() < 34 CHECK_LT(args.size(), static_cast<size_t>(std::numeric_limits<int>::max()));
32 static_cast<size_t>(std::numeric_limits<int>::max()));
33 int argc = static_cast<int>(args.size()); 35 int argc = static_cast<int>(args.size());
34 std::vector<const char*> argv(argc + 1); 36 std::vector<const char*> argv(argc + 1);
35 for (int i = 0; i < argc; ++i) 37 for (int i = 0; i < argc; ++i)
36 argv[i] = args[i].c_str(); 38 argv[i] = args[i].c_str();
37 argv[argc] = nullptr; 39 argv[argc] = nullptr;
38 40
39 testing::InitGoogleTest(&argc, const_cast<char**>(&(argv[0]))); 41 testing::InitGoogleTest(&argc, const_cast<char**>(&(argv[0])));
40 mojo::test::SetShellHandle(app.UnbindShell()); 42 mojo::test::SetShellHandle(app.UnbindShell());
41 mojo::Environment::DestroyDefaultRunLoop(); 43 mojo::Environment::DestroyDefaultRunLoop();
42 } 44 }
43 45
44 int result = RUN_ALL_TESTS(); 46 int result = RUN_ALL_TESTS();
45 47
46 shell_handle = mojo::test::PassShellHandle().release().value(); 48 shell_handle = mojo::test::PassShellHandle().release().value();
47 MojoResult close_result = MojoClose(shell_handle); 49 MojoResult close_result = MojoClose(shell_handle);
48 MOJO_CHECK(close_result == MOJO_RESULT_OK); 50 CHECK_EQ(close_result, MOJO_RESULT_OK);
49 51
50 return (result == 0) ? MOJO_RESULT_OK : MOJO_RESULT_UNKNOWN; 52 return (result == 0) ? MOJO_RESULT_OK : MOJO_RESULT_UNKNOWN;
51 } 53 }
OLDNEW
« no previous file with comments | « mojo/application/BUILD.gn ('k') | mojo/environment/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698