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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: examples/python/python_apptest.cc
diff --git a/examples/python/python_apptest.cc b/examples/python/python_apptest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5b64cf23a92e0ed27b796a3ac04de0f6f27ec8d9
--- /dev/null
+++ b/examples/python/python_apptest.cc
@@ -0,0 +1,84 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <stdio.h>
+
+#include "base/run_loop.h"
+#include "examples/python/echo_service.mojom.h"
+#include "mojo/public/c/system/main.h"
+#include "mojo/public/cpp/application/application_delegate.h"
+#include "mojo/public/cpp/application/application_impl.h"
+#include "mojo/public/cpp/application/application_runner.h"
+#include "mojo/public/cpp/application/application_test_base.h"
+#include "mojo/public/cpp/utility/run_loop.h"
+
+namespace mojo {
+namespace examples {
+
+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
+ public:
+ PythonApplicationTest() : ApplicationTestBase() {}
+ ~PythonApplicationTest() override {}
+
+ protected:
+ // ApplicationTestBase:
+ void SetUp() override {
+ ApplicationTestBase::SetUp();
+
+ application_impl()->ConnectToService("mojo:py_service", &echo_service_);
+ }
+
+ EchoServicePtr echo_service_;
+
+ private:
+ MOJO_DISALLOW_COPY_AND_ASSIGN(PythonApplicationTest);
+};
+
+class ResponseRecorder {
+ public:
+ void set_record(const String& value) {
+ has_record_ = true;
+ value_ = value;
+ }
+
+ bool has_record() {
+ return has_record_;
+ }
+
+ const String& get_record() {
+ return value_;
+ }
+
+ private:
+ String value_;
+ bool has_record_ = false;
+};
+
+class ResponseCallback : public mojo::Callback<void(const String&)>::Runnable {
+ public:
+ ResponseCallback(ResponseRecorder* recorder) : recorder_(recorder) {};
+ ~ResponseCallback() {};
+
+ void Run(const String& value) const override {
+ recorder_->set_record(value);
+ base::MessageLoop::current()->QuitWhenIdle();
+ }
+
+ ResponseRecorder* recorder_;
+};
+
+TEST_F(PythonApplicationTest, CallMethodOnService) {
+ // Verify that we can call a method on a python service and get an answer.
+ const String& test_string = "Hello, World!";
+ ResponseRecorder responseRecoder;
+ ResponseCallback responseCallback(&responseRecoder);
+ echo_service_->EchoString(test_string, responseCallback);
+ base::RunLoop().Run();
+ EXPECT_TRUE(responseRecoder.has_record());
+ EXPECT_TRUE(test_string == responseRecoder.get_record());
+}
+
+} // namespace examples
+} // namespace mojo
+

Powered by Google App Engine
This is Rietveld 408576698