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

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

Issue 718123002: Use loops directly in apptest main files. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: 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/public/cpp/application/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" 5 #include "base/at_exit.h"
6 #include "base/logging.h"
7 #include "base/message_loop/message_loop.h"
6 #include "mojo/public/c/system/main.h" 8 #include "mojo/public/c/system/main.h"
7 #include "mojo/public/cpp/application/application_delegate.h" 9 #include "mojo/public/cpp/application/application_delegate.h"
8 #include "mojo/public/cpp/application/application_impl.h" 10 #include "mojo/public/cpp/application/application_impl.h"
9 #include "mojo/public/cpp/application/application_test_base.h" 11 #include "mojo/public/cpp/application/application_test_base.h"
10 #include "mojo/public/cpp/environment/logging.h"
11 #include "mojo/public/cpp/system/message_pipe.h" 12 #include "mojo/public/cpp/system/message_pipe.h"
12 13
13 MojoResult MojoMain(MojoHandle shell_handle) { 14 MojoResult MojoMain(MojoHandle shell_handle) {
14 // An AtExitManager instance is needed to construct message loops. 15 // An AtExitManager instance is needed to construct message loops.
15 base::AtExitManager at_exit; 16 base::AtExitManager at_exit;
16 17
17 { 18 {
18 // This RunLoop is used for init, and then destroyed before running tests. 19 // This loop is used for init, and then destroyed before running tests.
19 mojo::Environment::InstantiateDefaultRunLoop(); 20 base::MessageLoop message_loop;
20 21
21 // Construct an ApplicationImpl just for the GTEST commandline arguments. 22 // Construct an ApplicationImpl just for the GTEST commandline arguments.
22 // GTEST command line arguments are supported amid application arguments: 23 // GTEST command line arguments are supported amid application arguments:
23 // $ mojo_shell 'mojo:example_apptests arg1 --gtest_filter=foo arg2' 24 // $ mojo_shell 'mojo:example_apptests arg1 --gtest_filter=foo arg2'
24 mojo::ApplicationDelegate dummy_application_delegate; 25 mojo::ApplicationDelegate dummy_application_delegate;
25 mojo::ApplicationImpl app(&dummy_application_delegate, shell_handle); 26 mojo::ApplicationImpl app(&dummy_application_delegate, shell_handle);
26 MOJO_CHECK(app.WaitForInitialize()); 27 CHECK(app.WaitForInitialize());
27 28
28 // InitGoogleTest expects (argc + 1) elements, including a terminating NULL. 29 // InitGoogleTest expects (argc + 1) elements, including a terminating NULL.
29 // It also removes GTEST arguments from |argv| and updates the |argc| count. 30 // It also removes GTEST arguments from |argv| and updates the |argc| count.
30 // TODO(msw): Provide tests access to these actual command line arguments. 31 // TODO(msw): Provide tests access to these actual command line arguments.
31 const std::vector<std::string>& args = app.args(); 32 const std::vector<std::string>& args = app.args();
32 MOJO_CHECK(args.size() < 33 CHECK_LT(args.size(), static_cast<size_t>(std::numeric_limits<int>::max()));
33 static_cast<size_t>(std::numeric_limits<int>::max()));
34 int argc = static_cast<int>(args.size()); 34 int argc = static_cast<int>(args.size());
35 std::vector<const char*> argv(argc + 1); 35 std::vector<const char*> argv(argc + 1);
36 for (int i = 0; i < argc; ++i) 36 for (int i = 0; i < argc; ++i)
37 argv[i] = args[i].c_str(); 37 argv[i] = args[i].c_str();
38 argv[argc] = nullptr; 38 argv[argc] = nullptr;
39 39
40 testing::InitGoogleTest(&argc, const_cast<char**>(&(argv[0]))); 40 testing::InitGoogleTest(&argc, const_cast<char**>(&(argv[0])));
41 mojo::test::SetShellHandle(app.UnbindShell()); 41 mojo::test::SetShellHandle(app.UnbindShell());
42 mojo::Environment::DestroyDefaultRunLoop();
43 } 42 }
44 43
45 int result = RUN_ALL_TESTS(); 44 int result = RUN_ALL_TESTS();
46 45
47 shell_handle = mojo::test::PassShellHandle().release().value(); 46 shell_handle = mojo::test::PassShellHandle().release().value();
48 MojoResult close_result = MojoClose(shell_handle); 47 MojoResult close_result = MojoClose(shell_handle);
49 MOJO_CHECK(close_result == MOJO_RESULT_OK); 48 CHECK_EQ(close_result, MOJO_RESULT_OK);
50 49
51 return (result == 0) ? MOJO_RESULT_OK : MOJO_RESULT_UNKNOWN; 50 return (result == 0) ? MOJO_RESULT_OK : MOJO_RESULT_UNKNOWN;
52 } 51 }
OLDNEW
« no previous file with comments | « mojo/application/BUILD.gn ('k') | mojo/public/cpp/application/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698