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

Side by Side Diff: mojo/public/cpp/application/lib/application_test_main.cc

Issue 782693004: Update mojo sdk to rev f6c8ec07c01deebc13178d516225fd12695c3dc2 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: hack mojo_system_impl gypi for android :| Created 6 years 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
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 "mojo/public/c/system/main.h" 5 #include "mojo/public/c/system/main.h"
6 #include "mojo/public/cpp/application/application_delegate.h" 6 #include "mojo/public/cpp/application/application_delegate.h"
7 #include "mojo/public/cpp/application/application_impl.h" 7 #include "mojo/public/cpp/application/application_impl.h"
8 #include "mojo/public/cpp/application/application_test_base.h" 8 #include "mojo/public/cpp/application/application_test_base.h"
9 #include "mojo/public/cpp/environment/environment.h" 9 #include "mojo/public/cpp/environment/environment.h"
10 #include "mojo/public/cpp/environment/logging.h" 10 #include "mojo/public/cpp/environment/logging.h"
11 #include "mojo/public/cpp/system/message_pipe.h" 11 #include "mojo/public/cpp/system/message_pipe.h"
12 #include "mojo/public/cpp/utility/run_loop.h" 12 #include "mojo/public/cpp/utility/run_loop.h"
13 13
14 MojoResult MojoMain(MojoHandle shell_handle) { 14 MojoResult MojoMain(MojoHandle shell_handle) {
15 // An Environment instance is needed to construct run loops. 15 // An Environment instance is needed to construct run loops.
16 mojo::Environment environment; 16 mojo::Environment environment;
17 17
18 { 18 {
19 // This loop is used for init, and then destroyed before running tests. 19 // This loop is used for init, and then destroyed before running tests.
20 mojo::RunLoop run_loop; 20 mojo::RunLoop run_loop;
21 21
22 // Construct an ApplicationImpl just for the GTEST commandline arguments. 22 // Construct an ApplicationImpl just for the GTEST commandline arguments.
23 // GTEST command line arguments are supported amid application arguments: 23 // GTEST command line arguments are supported amid application arguments:
24 // $ mojo_shell mojo:example_apptests 24 // $ mojo_shell mojo:example_apptests
25 // --args-for='mojo:example_apptests arg1 --gtest_filter=foo arg2' 25 // --args-for='mojo:example_apptests arg1 --gtest_filter=foo arg2'
26 mojo::ApplicationDelegate dummy_application_delegate; 26 mojo::ApplicationDelegate dummy_application_delegate;
27 mojo::ApplicationImpl app(&dummy_application_delegate, shell_handle); 27 mojo::ApplicationImpl app(&dummy_application_delegate, shell_handle);
28 MOJO_CHECK(app.WaitForInitialize()); 28 MOJO_CHECK(app.WaitForInitialize());
29 29
30 // InitGoogleTest expects (argc + 1) elements, including a terminating NULL. 30 // InitGoogleTest expects (argc + 1) elements, including a terminating null.
31 // 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.
32 const std::vector<std::string>& args = app.args(); 32 const std::vector<std::string>& args = app.args();
33 MOJO_CHECK(args.size() < 33 MOJO_CHECK(args.size() <
34 static_cast<size_t>(std::numeric_limits<int>::max())); 34 static_cast<size_t>(std::numeric_limits<int>::max()));
35 int argc = static_cast<int>(args.size()); 35 int argc = static_cast<int>(args.size());
36 std::vector<const char*> argv(argc + 1); 36 std::vector<const char*> argv(argc + 1);
37 for (int i = 0; i < argc; ++i) 37 for (int i = 0; i < argc; ++i)
38 argv[i] = args[i].c_str(); 38 argv[i] = args[i].c_str();
39 argv[argc] = nullptr; 39 argv[argc] = nullptr;
40 40
41 testing::InitGoogleTest(&argc, const_cast<char**>(&(argv[0]))); 41 testing::InitGoogleTest(&argc, const_cast<char**>(&(argv[0])));
42 mojo::test::SetShellHandle(app.UnbindShell()); 42 mojo::test::SetShellHandle(app.UnbindShell());
43 mojo::test::InitializeArgs(argc, argv); 43 mojo::test::InitializeArgs(argc, argv);
44 } 44 }
45 45
46 int result = RUN_ALL_TESTS(); 46 int result = RUN_ALL_TESTS();
47 47
48 shell_handle = mojo::test::PassShellHandle().release().value(); 48 shell_handle = mojo::test::PassShellHandle().release().value();
49 MojoResult close_result = MojoClose(shell_handle); 49 MojoResult close_result = MojoClose(shell_handle);
50 MOJO_CHECK(close_result == MOJO_RESULT_OK); 50 MOJO_CHECK(close_result == MOJO_RESULT_OK);
51 51
52 return (result == 0) ? MOJO_RESULT_OK : MOJO_RESULT_UNKNOWN; 52 return (result == 0) ? MOJO_RESULT_OK : MOJO_RESULT_UNKNOWN;
53 } 53 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698