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

Side by Side Diff: examples/python/python_apptest.cc

Issue 796373006: Content handler for python. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 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
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 <stdio.h>
6
7 #include "base/run_loop.h"
8 #include "examples/python/echo_service.mojom.h"
9 #include "mojo/public/c/system/main.h"
10 #include "mojo/public/cpp/application/application_delegate.h"
11 #include "mojo/public/cpp/application/application_impl.h"
12 #include "mojo/public/cpp/application/application_runner.h"
13 #include "mojo/public/cpp/application/application_test_base.h"
14 #include "mojo/public/cpp/utility/run_loop.h"
15
16 namespace mojo {
17 namespace examples {
18
19 class PythonApplicationTest : public test::ApplicationTestBase {
qsr 2015/01/07 15:14:45 Did you think about using //example/apptest instea
etiennej 2015/01/08 11:23:12 //example/apptest requires more support code: in p
20 public:
21 PythonApplicationTest() : ApplicationTestBase() {}
22 ~PythonApplicationTest() override {}
23
24 protected:
25 // ApplicationTestBase:
26 void SetUp() override {
27 ApplicationTestBase::SetUp();
28
29 application_impl()->ConnectToService("mojo:py_service", &echo_service_);
30 }
31
32 EchoServicePtr echo_service_;
33
34 private:
35 MOJO_DISALLOW_COPY_AND_ASSIGN(PythonApplicationTest);
36 };
37
38 class ResponseRecorder {
39 public:
40 void set_record(const String& value) {
41 has_record_ = true;
42 value_ = value;
43 }
44
45 bool has_record() {
46 return has_record_;
47 }
48
49 const String& get_record() {
50 return value_;
51 }
52
53 private:
54 String value_;
55 bool has_record_ = false;
56 };
57
58 class ResponseCallback : public mojo::Callback<void(const String&)>::Runnable {
59 public:
60 ResponseCallback(ResponseRecorder* recorder) : recorder_(recorder) {};
61 ~ResponseCallback() {};
62
63 void Run(const String& value) const override {
64 recorder_->set_record(value);
65 base::MessageLoop::current()->QuitWhenIdle();
66 }
67
68 ResponseRecorder* recorder_;
69 };
70
71 TEST_F(PythonApplicationTest, CallMethodOnService) {
72 // Verify that we can call a method on a python service and get an answer.
73 const String& test_string = "Hello, World!";
74 ResponseRecorder responseRecoder;
75 ResponseCallback responseCallback(&responseRecoder);
76 echo_service_->EchoString(test_string, responseCallback);
77 base::RunLoop().Run();
78 EXPECT_TRUE(responseRecoder.has_record());
79 EXPECT_TRUE(test_string == responseRecoder.get_record());
80 }
81
82 } // namespace examples
83 } // namespace mojo
84
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698