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

Side by Side Diff: mojo/examples/apptest/example_apptest.cc

Issue 399653004: Add a Mojo example apptest that runs in mojo_shell. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move files to mojo/examples/apptest. Created 6 years, 4 months 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 | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "mojo/examples/apptest/example_client_impl.h"
6 #include "mojo/examples/apptest/example_service.mojom.h"
7 #include "mojo/public/cpp/application/application_delegate.h"
8 #include "mojo/public/cpp/application/application_impl.h"
9 #include "mojo/public/cpp/bindings/callback.h"
10 #include "mojo/public/cpp/environment/environment.h"
11 #include "mojo/public/cpp/system/macros.h"
12 #include "mojo/public/cpp/utility/run_loop.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace {
16
17 // TODO(msw): Remove this once we can get ApplicationImpl from TLS.
18 mojo::ApplicationImpl* g_application_impl_hack = NULL;
19
20 } // namespace
21
22 namespace mojo {
23
24 namespace {
25
26 class ExampleServiceTest : public testing::Test {
27 public:
28 ExampleServiceTest() {
29 g_application_impl_hack->ConnectToService("mojo:mojo_example_service",
30 &example_service_);
31 example_service_.set_client(&example_client_);
32 }
33
34 virtual ~ExampleServiceTest() MOJO_OVERRIDE {
35 example_service_.reset();
Ben Goodger (Google) 2014/08/07 15:53:09 should not be necessary.
msw 2014/08/07 18:31:15 Done.
36 }
37
38 protected:
39 ExampleServicePtr example_service_;
40 ExampleClientImpl example_client_;
41
42 private:
43 MOJO_DISALLOW_COPY_AND_ASSIGN(ExampleServiceTest);
44 };
45
46 TEST_F(ExampleServiceTest, Ping) {
47 EXPECT_EQ(0, example_client_.last_pong_value());
48 example_service_->Ping(1);
49 mojo::RunLoop::current()->Run();
50 EXPECT_EQ(1, example_client_.last_pong_value());
51 }
52
53 template <typename T>
54 struct SetAndQuit : public Callback<void()>::Runnable {
55 SetAndQuit(T* val, T result) : val_(val), result_(result) {}
56 virtual ~SetAndQuit() {}
57 virtual void Run() const MOJO_OVERRIDE{
58 *val_ = result_;
59 mojo::RunLoop::current()->Quit();
60 }
61 T* val_;
62 T result_;
63 };
64
65 TEST_F(ExampleServiceTest, RunCallback) {
66 bool was_run = false;
67 example_service_->RunCallback(SetAndQuit<bool>(&was_run, true));
68 mojo::RunLoop::current()->Run();
69 EXPECT_TRUE(was_run);
70 }
71
72 } // namespace
73
74 } // namespace mojo
75
76 extern "C" APPLICATION_EXPORT MojoResult CDECL MojoMain(
77 MojoHandle shell_handle) {
78 mojo::Environment env;
79 mojo::RunLoop loop;
80
81 mojo::ApplicationDelegate* delegate = mojo::ApplicationDelegate::Create();
82 mojo::ApplicationImpl app(delegate);
83 app.BindShell(shell_handle);
84 g_application_impl_hack = &app;
85
86 // TODO(msw): Get actual commandline arguments.
87 int argc = 0;
88 char** argv = NULL;
89 testing::InitGoogleTest(&argc, argv);
90 RUN_ALL_TESTS();
91
92 delete delegate;
93 printf("Exiting MojoMain.\n");
Ben Goodger (Google) 2014/08/07 15:53:09 delete
msw 2014/08/07 18:31:15 Done.
94 return MOJO_RESULT_OK;
95 }
OLDNEW
« no previous file with comments | « no previous file | mojo/examples/apptest/example_client_application.h » ('j') | mojo/examples/apptest/example_service_application.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698