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

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: 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
« mojo/application/BUILD.gn ('K') | « mojo/application/BUILD.gn ('k') | no next file » | 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"
10 #include "mojo/public/cpp/system/message_pipe.h" 12 #include "mojo/public/cpp/system/message_pipe.h"
11 13
12 MojoResult MojoMain(MojoHandle shell_handle) { 14 MojoResult MojoMain(MojoHandle shell_handle) {
13 // An Environment instance is needed to construct run loops. 15 // An AtExitManager instance is needed to construct message loops.
14 mojo::Environment environment; 16 base::AtExitManager at_exit;
15 17
16 { 18 {
17 // 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.
18 mojo::Environment::InstantiateDefaultRunLoop(); 20 CHECK(!base::MessageLoop::current());
21 base::MessageLoop message_loop;
22 CHECK_EQ(&message_loop, base::MessageLoop::current());
19 23
20 // Construct an ApplicationImpl just for the GTEST commandline arguments. 24 // Construct an ApplicationImpl just for the GTEST commandline arguments.
21 // GTEST command line arguments are supported amid application arguments: 25 // GTEST command line arguments are supported amid application arguments:
22 // $ mojo_shell 'mojo:example_apptests arg1 --gtest_filter=foo arg2' 26 // $ mojo_shell 'mojo:example_apptests arg1 --gtest_filter=foo arg2'
23 mojo::ApplicationDelegate dummy_application_delegate; 27 mojo::ApplicationDelegate dummy_application_delegate;
24 mojo::ApplicationImpl app(&dummy_application_delegate, shell_handle); 28 mojo::ApplicationImpl app(&dummy_application_delegate, shell_handle);
25 MOJO_CHECK(app.WaitForInitialize()); 29 CHECK(app.WaitForInitialize());
26 30
27 // InitGoogleTest expects (argc + 1) elements, including a terminating NULL. 31 // InitGoogleTest expects (argc + 1) elements, including a terminating NULL.
28 // It also removes GTEST arguments from |argv| and updates the |argc| count. 32 // It also removes GTEST arguments from |argv| and updates the |argc| count.
29 // TODO(msw): Provide tests access to these actual command line arguments. 33 // TODO(msw): Provide tests access to these actual command line arguments.
30 const std::vector<std::string>& args = app.args(); 34 const std::vector<std::string>& args = app.args();
31 MOJO_CHECK(args.size() < 35 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()); 36 int argc = static_cast<int>(args.size());
34 std::vector<const char*> argv(argc + 1); 37 std::vector<const char*> argv(argc + 1);
35 for (int i = 0; i < argc; ++i) 38 for (int i = 0; i < argc; ++i)
36 argv[i] = args[i].c_str(); 39 argv[i] = args[i].c_str();
37 argv[argc] = nullptr; 40 argv[argc] = nullptr;
38 41
39 testing::InitGoogleTest(&argc, const_cast<char**>(&(argv[0]))); 42 testing::InitGoogleTest(&argc, const_cast<char**>(&(argv[0])));
40 mojo::test::SetShellHandle(app.UnbindShell()); 43 mojo::test::SetShellHandle(app.UnbindShell());
41 mojo::Environment::DestroyDefaultRunLoop();
42 } 44 }
45 CHECK(!base::MessageLoop::current());
jamesr 2014/11/11 20:18:31 this seems superfluous to me
msw 2014/11/11 20:27:02 Hmm, left as-is; Trung was adamant about killing l
43 46
44 int result = RUN_ALL_TESTS(); 47 int result = RUN_ALL_TESTS();
45 48
46 shell_handle = mojo::test::PassShellHandle().release().value(); 49 shell_handle = mojo::test::PassShellHandle().release().value();
47 MojoResult close_result = MojoClose(shell_handle); 50 MojoResult close_result = MojoClose(shell_handle);
48 MOJO_CHECK(close_result == MOJO_RESULT_OK); 51 CHECK_EQ(close_result, MOJO_RESULT_OK);
49 52
50 return (result == 0) ? MOJO_RESULT_OK : MOJO_RESULT_UNKNOWN; 53 return (result == 0) ? MOJO_RESULT_OK : MOJO_RESULT_UNKNOWN;
51 } 54 }
OLDNEW
« mojo/application/BUILD.gn ('K') | « mojo/application/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698