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

Unified Diff: mojo/apps/js/test/js_to_cpp_unittest.cc

Issue 294833002: Mojo: more idiomatic C++ bindings (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 7 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
« no previous file with comments | « content/browser/webui/web_ui_mojo_browsertest.cc ('k') | mojo/aura/window_tree_host_mojo.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/apps/js/test/js_to_cpp_unittest.cc
diff --git a/mojo/apps/js/test/js_to_cpp_unittest.cc b/mojo/apps/js/test/js_to_cpp_unittest.cc
index 504f59b9efe36bae00aa6c2f9a21bc0186a6d515..7b5e5ef198e1c0dffedcf3ebb74c7b0381efa90e 100644
--- a/mojo/apps/js/test/js_to_cpp_unittest.cc
+++ b/mojo/apps/js/test/js_to_cpp_unittest.cc
@@ -12,7 +12,6 @@
#include "mojo/apps/js/test/js_to_cpp.mojom.h"
#include "mojo/common/common_type_converters.h"
#include "mojo/common/test/test_utils.h"
-#include "mojo/public/cpp/bindings/allocation_scope.h"
#include "mojo/public/cpp/environment/environment.h"
#include "mojo/public/cpp/system/core.h"
#include "mojo/public/cpp/system/macros.h"
@@ -89,74 +88,72 @@ void CheckMessagePipe(MojoHandle message_pipe_handle) {
}
}
-// NOTE: Callers will need to have established an AllocationScope, or you're
-// gonna have a bad time.
-js_to_cpp::EchoArgs BuildSampleEchoArgs() {
- js_to_cpp::EchoArgs::Builder builder;
- builder.set_si64(kExpectedInt64Value);
- builder.set_si32(kExpectedInt32Value);
- builder.set_si16(kExpectedInt16Value);
- builder.set_si8(kExpectedInt8Value);
- builder.set_ui64(kExpectedUInt64Value);
- builder.set_ui32(kExpectedUInt32Value);
- builder.set_ui16(kExpectedUInt16Value);
- builder.set_ui8(kExpectedUInt8Value);
- builder.set_float_val(kExpectedFloatVal);
- builder.set_float_inf(kExpectedFloatInf);
- builder.set_float_nan(kExpectedFloatNan);
- builder.set_double_val(kExpectedDoubleVal);
- builder.set_double_inf(kExpectedDoubleInf);
- builder.set_double_nan(kExpectedDoubleNan);
- builder.set_name("coming");
- mojo::Array<mojo::String>::Builder string_array(3);
+js_to_cpp::EchoArgsPtr BuildSampleEchoArgs() {
+ js_to_cpp::EchoArgsPtr args(js_to_cpp::EchoArgs::New());
+ args->si64 = kExpectedInt64Value;
+ args->si32 = kExpectedInt32Value;
+ args->si16 = kExpectedInt16Value;
+ args->si8 = kExpectedInt8Value;
+ args->ui64 = kExpectedUInt64Value;
+ args->ui32 = kExpectedUInt32Value;
+ args->ui16 = kExpectedUInt16Value;
+ args->ui8 = kExpectedUInt8Value;
+ args->float_val = kExpectedFloatVal;
+ args->float_inf = kExpectedFloatInf;
+ args->float_nan = kExpectedFloatNan;
+ args->double_val = kExpectedDoubleVal;
+ args->double_inf = kExpectedDoubleInf;
+ args->double_nan = kExpectedDoubleNan;
+ args->name = "coming";
+ Array<String> string_array(3);
string_array[0] = "one";
string_array[1] = "two";
string_array[2] = "three";
- builder.set_string_array(string_array.Finish());
- return builder.Finish();
+ args->string_array = string_array.Pass();
+ return args.Pass();
}
void CheckSampleEchoArgs(const js_to_cpp::EchoArgs& arg) {
- EXPECT_EQ(kExpectedInt64Value, arg.si64());
- EXPECT_EQ(kExpectedInt32Value, arg.si32());
- EXPECT_EQ(kExpectedInt16Value, arg.si16());
- EXPECT_EQ(kExpectedInt8Value, arg.si8());
- EXPECT_EQ(kExpectedUInt64Value, arg.ui64());
- EXPECT_EQ(kExpectedUInt32Value, arg.ui32());
- EXPECT_EQ(kExpectedUInt16Value, arg.ui16());
- EXPECT_EQ(kExpectedUInt8Value, arg.ui8());
- EXPECT_EQ(kExpectedFloatVal, arg.float_val());
- EXPECT_EQ(kExpectedFloatInf, arg.float_inf());
- EXPECT_NAN(arg.float_nan());
- EXPECT_EQ(kExpectedDoubleVal, arg.double_val());
- EXPECT_EQ(kExpectedDoubleInf, arg.double_inf());
- EXPECT_NAN(arg.double_nan());
- EXPECT_EQ(std::string("coming"), arg.name().To<std::string>());
- EXPECT_EQ(std::string("one"), arg.string_array()[0].To<std::string>());
- EXPECT_EQ(std::string("two"), arg.string_array()[1].To<std::string>());
- EXPECT_EQ(std::string("three"), arg.string_array()[2].To<std::string>());
- CheckDataPipe(arg.data_handle().get().value());
- CheckMessagePipe(arg.message_handle().get().value());
+ EXPECT_EQ(kExpectedInt64Value, arg.si64);
+ EXPECT_EQ(kExpectedInt32Value, arg.si32);
+ EXPECT_EQ(kExpectedInt16Value, arg.si16);
+ EXPECT_EQ(kExpectedInt8Value, arg.si8);
+ EXPECT_EQ(kExpectedUInt64Value, arg.ui64);
+ EXPECT_EQ(kExpectedUInt32Value, arg.ui32);
+ EXPECT_EQ(kExpectedUInt16Value, arg.ui16);
+ EXPECT_EQ(kExpectedUInt8Value, arg.ui8);
+ EXPECT_EQ(kExpectedFloatVal, arg.float_val);
+ EXPECT_EQ(kExpectedFloatInf, arg.float_inf);
+ EXPECT_NAN(arg.float_nan);
+ EXPECT_EQ(kExpectedDoubleVal, arg.double_val);
+ EXPECT_EQ(kExpectedDoubleInf, arg.double_inf);
+ EXPECT_NAN(arg.double_nan);
+ EXPECT_EQ(std::string("coming"), arg.name.get());
+ EXPECT_EQ(std::string("one"), arg.string_array[0].get());
+ EXPECT_EQ(std::string("two"), arg.string_array[1].get());
+ EXPECT_EQ(std::string("three"), arg.string_array[2].get());
+ CheckDataPipe(arg.data_handle.get().value());
+ CheckMessagePipe(arg.message_handle.get().value());
}
-void CheckSampleEchoArgsList(const js_to_cpp::EchoArgsList& list) {
+void CheckSampleEchoArgsList(const js_to_cpp::EchoArgsListPtr& list) {
if (list.is_null())
return;
- CheckSampleEchoArgs(list.item());
- CheckSampleEchoArgsList(list.next());
+ CheckSampleEchoArgs(*list->item);
+ CheckSampleEchoArgsList(list->next);
}
// More forgiving checks are needed in the face of potentially corrupt
// messages. The values don't matter so long as all accesses are within
// bounds.
-void CheckCorruptedString(const mojo::String& arg) {
+void CheckCorruptedString(const String& arg) {
if (arg.is_null())
return;
for (size_t i = 0; i < arg.size(); ++i)
g_waste_accumulator += arg[i];
}
-void CheckCorruptedStringArray(const mojo::Array<mojo::String>& string_array) {
+void CheckCorruptedStringArray(const Array<String>& string_array) {
if (string_array.is_null())
return;
for (size_t i = 0; i < string_array.size(); ++i)
@@ -185,22 +182,22 @@ void CheckCorruptedMessagePipe(MojoHandle message_pipe_handle) {
g_waste_accumulator += buffer[i];
}
-void CheckCorruptedEchoArgs(const js_to_cpp::EchoArgs& arg) {
+void CheckCorruptedEchoArgs(const js_to_cpp::EchoArgsPtr& arg) {
if (arg.is_null())
return;
- CheckCorruptedString(arg.name());
- CheckCorruptedStringArray(arg.string_array());
- if (arg.data_handle().is_valid())
- CheckCorruptedDataPipe(arg.data_handle().get().value());
- if (arg.message_handle().is_valid())
- CheckCorruptedMessagePipe(arg.message_handle().get().value());
+ CheckCorruptedString(arg->name);
+ CheckCorruptedStringArray(arg->string_array);
+ if (arg->data_handle.is_valid())
+ CheckCorruptedDataPipe(arg->data_handle.get().value());
+ if (arg->message_handle.is_valid())
+ CheckCorruptedMessagePipe(arg->message_handle.get().value());
}
-void CheckCorruptedEchoArgsList(const js_to_cpp::EchoArgsList& list) {
+void CheckCorruptedEchoArgsList(const js_to_cpp::EchoArgsListPtr& list) {
if (list.is_null())
return;
- CheckCorruptedEchoArgs(list.item());
- CheckCorruptedEchoArgsList(list.next());
+ CheckCorruptedEchoArgs(list->item);
+ CheckCorruptedEchoArgsList(list->next);
}
// Base Provider implementation class. It's expected that tests subclass and
@@ -234,16 +231,16 @@ class CppSideConnection : public js_to_cpp::CppSide {
mishandled_messages_ += 1;
}
- virtual void EchoResponse(const js_to_cpp::EchoArgsList& list) OVERRIDE {
+ virtual void EchoResponse(js_to_cpp::EchoArgsListPtr list) OVERRIDE {
mishandled_messages_ += 1;
}
- virtual void BitFlipResponse(const js_to_cpp::EchoArgsList& list) OVERRIDE {
+ virtual void BitFlipResponse(js_to_cpp::EchoArgsListPtr list) OVERRIDE {
mishandled_messages_ += 1;
}
virtual void BackPointerResponse(
- const js_to_cpp::EchoArgsList& list) OVERRIDE {
+ js_to_cpp::EchoArgsListPtr list) OVERRIDE {
mishandled_messages_ += 1;
}
@@ -292,19 +289,18 @@ class EchoCppSideConnection : public CppSideConnection {
// js_to_cpp::CppSide:
virtual void StartTest() OVERRIDE {
- AllocationScope scope;
js_side_->Echo(kExpectedMessageCount, BuildSampleEchoArgs());
}
- virtual void EchoResponse(const js_to_cpp::EchoArgsList& list) OVERRIDE {
- const js_to_cpp::EchoArgs& special_arg = list.item();
+ virtual void EchoResponse(js_to_cpp::EchoArgsListPtr list) OVERRIDE {
+ const js_to_cpp::EchoArgsPtr& special_arg = list->item;
message_count_ += 1;
- EXPECT_EQ(-1, special_arg.si64());
- EXPECT_EQ(-1, special_arg.si32());
- EXPECT_EQ(-1, special_arg.si16());
- EXPECT_EQ(-1, special_arg.si8());
- EXPECT_EQ(std::string("going"), special_arg.name().To<std::string>());
- CheckSampleEchoArgsList(list.next());
+ EXPECT_EQ(-1, special_arg->si64);
+ EXPECT_EQ(-1, special_arg->si32);
+ EXPECT_EQ(-1, special_arg->si16);
+ EXPECT_EQ(-1, special_arg->si8);
+ EXPECT_EQ(std::string("going"), special_arg->name.To<std::string>());
+ CheckSampleEchoArgsList(list->next);
}
virtual void TestFinished() OVERRIDE {
@@ -333,11 +329,10 @@ class BitFlipCppSideConnection : public CppSideConnection {
// js_to_cpp::CppSide:
virtual void StartTest() OVERRIDE {
- AllocationScope scope;
js_side_->BitFlip(BuildSampleEchoArgs());
}
- virtual void BitFlipResponse(const js_to_cpp::EchoArgsList& list) OVERRIDE {
+ virtual void BitFlipResponse(js_to_cpp::EchoArgsListPtr list) OVERRIDE {
CheckCorruptedEchoArgsList(list);
}
@@ -363,12 +358,11 @@ class BackPointerCppSideConnection : public CppSideConnection {
// js_to_cpp::CppSide:
virtual void StartTest() OVERRIDE {
- AllocationScope scope;
js_side_->BackPointer(BuildSampleEchoArgs());
}
virtual void BackPointerResponse(
- const js_to_cpp::EchoArgsList& list) OVERRIDE {
+ js_to_cpp::EchoArgsListPtr list) OVERRIDE {
CheckCorruptedEchoArgsList(list);
}
« no previous file with comments | « content/browser/webui/web_ui_mojo_browsertest.cc ('k') | mojo/aura/window_tree_host_mojo.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698