summaryrefslogtreecommitdiffstats
path: root/mojo
diff options
context:
space:
mode:
authorviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-21 22:52:22 +0000
committerviettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-21 22:52:22 +0000
commit78d446c9e740a0dfe565be9d8b99367d8380323f (patch)
tree5914ed771288f77c60ae4451a74898eaa48f6b9f /mojo
parentc17ebd9c388b0be18c77e3449d1fc20e8c156331 (diff)
downloadchromium_src-78d446c9e740a0dfe565be9d8b99367d8380323f.zip
chromium_src-78d446c9e740a0dfe565be9d8b99367d8380323f.tar.gz
chromium_src-78d446c9e740a0dfe565be9d8b99367d8380323f.tar.bz2
Mojo: Mojom: Remove default values for structs and arrays.
R=darin@chromium.org Review URL: https://codereview.chromium.org/293033005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@272001 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo')
-rw-r--r--mojo/apps/js/bindings/sample_service_unittests.js55
-rw-r--r--mojo/bindings/js/codec_unittests.js3
-rw-r--r--mojo/public/cpp/bindings/tests/sample_service_unittest.cc58
-rw-r--r--mojo/public/interfaces/bindings/tests/sample_import2.mojom2
-rw-r--r--mojo/public/interfaces/bindings/tests/sample_service.mojom43
-rw-r--r--mojo/public/tools/bindings/pylib/mojom/parse/parser.py35
6 files changed, 92 insertions, 104 deletions
diff --git a/mojo/apps/js/bindings/sample_service_unittests.js b/mojo/apps/js/bindings/sample_service_unittests.js
index d7c0126..b61f597 100644
--- a/mojo/apps/js/bindings/sample_service_unittests.js
+++ b/mojo/apps/js/bindings/sample_service_unittests.js
@@ -95,33 +95,38 @@ define([
var foo = new sample.Foo();
expect(foo.name).toBe("Fooby");
expect(foo.a).toBeTruthy();
-
- expect(foo.data.length).toBe(3);
- expect(foo.data[0]).toBe(1);
- expect(foo.data[1]).toBe(2);
- expect(foo.data[2]).toBe(3);
-
- var inner = new sample.DefaultsTestInner();
- expect(inner.names.length).toBe(1);
- expect(inner.names[0]).toBe("Jim");
- expect(inner.height).toBe(6*12);
+ // TODO(vtl): crbug.com/375845
+ // expect(foo.data).toBeNull();
var full = new sample.DefaultsTest();
- expect(full.people.length).toBe(1);
- expect(full.people[0].age).toBe(32);
- expect(full.people[0].names.length).toBe(2);
- expect(full.people[0].names[0]).toBe("Bob");
- expect(full.people[0].names[1]).toBe("Bobby");
- expect(full.people[0].height).toBe(6*12);
-
- expect(full.point.x).toBe(7);
- expect(full.point.y).toBe(15);
-
- expect(full.shape_masks.length).toBe(1);
- expect(full.shape_masks[0]).toBe(1 << imported.Shape.SHAPE_RECTANGLE);
-
- expect(full.thing.shape).toBe(imported.Shape.SHAPE_CIRCLE);
- expect(full.thing.color).toBe(imported2.Color.COLOR_BLACK);
+ expect(full.a0).toBe(-12);
+ expect(full.a1).toBe(12);
+ expect(full.a2).toBe(1234);
+ expect(full.a3).toBe(34567);
+ expect(full.a4).toBe(123456);
+ // TODO(vtl): crbug.com/375522
+ // expect(full.a5).toBe(3456789012);
+ expect(full.a6).toBe(111111111111);
+ // TODO(vtl): crbug.com/375522 (Also, can we get exact values for large
+ // int64/uint64's in JS?)
+ // expect(full.a7).toBe(9999999999999999999);
+ expect(full.a8).toBe(0x12345);
+ expect(full.a9).toBe(-0x12345);
+ // TODO(vtl): crbug.com/375829
+ // expect(full.a10).toBe(8);
+ // expect(full.a11).toBe(-8);
+ expect(full.a12).toBe(1234);
+ expect(full.a13).toBe(true);
+ expect(full.a14).toBe(false);
+ expect(full.a15).toBe(123.25);
+ expect(full.a16).toBe(1234567890.123);
+ expect(full.a17).toBe(1E10);
+ expect(full.a18).toBe(-1.2E+20);
+ expect(full.a19).toBe(1.23E-20);
+ expect(full.a20).toBeNull();
+ // TODO(vtl): crbug.com/375845
+ // expect(full.a21).toBeNull();
+ // expect(full.a22).toBeNull();
}
function ServiceImpl() {
diff --git a/mojo/bindings/js/codec_unittests.js b/mojo/bindings/js/codec_unittests.js
index c6172ef..6a223ff 100644
--- a/mojo/bindings/js/codec_unittests.js
+++ b/mojo/bindings/js/codec_unittests.js
@@ -84,6 +84,9 @@ define([
foo.name = "I am a banana";
// This is supposed to be a handle, but we fake it with an integer.
foo.source = 23423782;
+ foo.array_of_array_of_bools = [
+ [true], [false, true]
+ ];
var messageName = 31;
var payloadSize = 304;
diff --git a/mojo/public/cpp/bindings/tests/sample_service_unittest.cc b/mojo/public/cpp/bindings/tests/sample_service_unittest.cc
index 6bbb334..1cb1af4 100644
--- a/mojo/public/cpp/bindings/tests/sample_service_unittest.cc
+++ b/mojo/public/cpp/bindings/tests/sample_service_unittest.cc
@@ -361,39 +361,33 @@ TEST(BindingsSampleTest, DefaultValues) {
SimpleMessageReceiver receiver;
mojo::AllocationScope scope;
- Bar bar = Bar::Builder().Finish();
- EXPECT_EQ(255, bar.alpha());
-
- Foo foo = Foo::Builder().Finish();
- ASSERT_FALSE(foo.name().is_null());
- EXPECT_EQ("Fooby", foo.name().To<std::string>());
- EXPECT_TRUE(foo.a());
- EXPECT_EQ(3u, foo.data().size());
- EXPECT_EQ(1, foo.data()[0]);
- EXPECT_EQ(2, foo.data()[1]);
- EXPECT_EQ(3, foo.data()[2]);
-
- DefaultsTestInner inner = DefaultsTestInner::Builder().Finish();
- EXPECT_EQ(1u, inner.names().size());
- EXPECT_EQ("Jim", inner.names()[0].To<std::string>());
- EXPECT_EQ(6*12, inner.height());
-
DefaultsTest full = DefaultsTest::Builder().Finish();
- EXPECT_EQ(1u, full.people().size());
- EXPECT_EQ(32, full.people()[0].age());
- EXPECT_EQ(2u, full.people()[0].names().size());
- EXPECT_EQ("Bob", full.people()[0].names()[0].To<std::string>());
- EXPECT_EQ("Bobby", full.people()[0].names()[1].To<std::string>());
- EXPECT_EQ(6*12, full.people()[0].height());
-
- EXPECT_EQ(7, full.point().x());
- EXPECT_EQ(15, full.point().y());
-
- EXPECT_EQ(1u, full.shape_masks().size());
- EXPECT_EQ(1 << imported::SHAPE_RECTANGLE, full.shape_masks()[0]);
-
- EXPECT_EQ(imported::SHAPE_CIRCLE, full.thing().shape());
- EXPECT_EQ(imported::COLOR_BLACK, full.thing().color());
+ EXPECT_EQ(-12, full.a0());
+ EXPECT_EQ(12U, full.a1());
+ EXPECT_EQ(1234, full.a2());
+ EXPECT_EQ(34567U, full.a3());
+ EXPECT_EQ(123456, full.a4());
+ // TODO(vtl): crbug.com/375522
+ // EXPECT_EQ(3456789012U, full.a5());
+ EXPECT_EQ(111111111111LL, full.a6());
+ // TODO(vtl): crbug.com/375522
+ // EXPECT_EQ(9999999999999999999ULL, full.a7());
+ EXPECT_EQ(0x12345, full.a8());
+ EXPECT_EQ(-0x12345, full.a9());
+ // TODO(vtl): crbug.com/375829
+ // EXPECT_EQ(8, full.a10());
+ // EXPECT_EQ(-8, full.a11());
+ EXPECT_EQ(1234, full.a12());
+ EXPECT_TRUE(full.a13());
+ EXPECT_FALSE(full.a14());
+ EXPECT_FLOAT_EQ(123.25f, full.a15());
+ EXPECT_DOUBLE_EQ(1234567890.123, full.a16());
+ EXPECT_DOUBLE_EQ(1E10, full.a17());
+ EXPECT_DOUBLE_EQ(-1.2E+20, full.a18());
+ EXPECT_DOUBLE_EQ(1.23E-20, full.a19());
+ EXPECT_TRUE(full.a20().is_null());
+ EXPECT_TRUE(full.a21().is_null());
+ EXPECT_TRUE(full.a22().is_null());
}
} // namespace
diff --git a/mojo/public/interfaces/bindings/tests/sample_import2.mojom b/mojo/public/interfaces/bindings/tests/sample_import2.mojom
index b93be69..7f6bcad 100644
--- a/mojo/public/interfaces/bindings/tests/sample_import2.mojom
+++ b/mojo/public/interfaces/bindings/tests/sample_import2.mojom
@@ -23,7 +23,7 @@ struct Size {
struct Thing {
imported.Shape shape = SHAPE_RECTANGLE;
int32 color = COLOR_BLACK;
- Point location = {0, 0};
+ Point location;
Size size;
};
diff --git a/mojo/public/interfaces/bindings/tests/sample_service.mojom b/mojo/public/interfaces/bindings/tests/sample_service.mojom
index d4327a4..72f8f18 100644
--- a/mojo/public/interfaces/bindings/tests/sample_service.mojom
+++ b/mojo/public/interfaces/bindings/tests/sample_service.mojom
@@ -34,27 +34,48 @@ struct Foo {
bool c @4;
Bar bar @5;
Bar[] extra_bars @7;
- uint8[] data = [1,2,kThree] @6;
+ uint8[] data @6;
handle<message_pipe> source @9;
handle<data_pipe_consumer>[] input_streams @10;
handle<data_pipe_producer>[] output_streams @11;
- bool[][] array_of_array_of_bools = [[true], [false, true]] @12;
+ bool[][] array_of_array_of_bools @12;
string[][][] multi_array_of_strings @13;
};
struct DefaultsTestInner {
- int32 age @2;
- string[] names = ["Jim"] @1;
- int32 height = 6*12 @3;
+ int32 x = 123 @0;
};
struct DefaultsTest {
- sample.DefaultsTestInner[] people = [{32, ["Bob", "Bobby"]}] @1;
- uint8[] data = [1, 2, 3] @2;
- imported.Point point = {7, 15} @3;
- int32[] shape_masks = [1 << imported.SHAPE_RECTANGLE] @4;
- imported.Thing thing = {imported.SHAPE_CIRCLE, imported.COLOR_BLACK};
- Bar.Type bar_type = Bar.TYPE_BOTH;
+ int8 a0 = -12 @0;
+ uint8 a1 = 12 @1;
+ int16 a2 = 1234 @2;
+ uint16 a3 = 34567 @3;
+ int32 a4 = 123456 @4;
+ // TODO(vtl): crbug.com/375522
+ uint32 a5 /* = 3456789012 */ @5;
+ // TODO(vtl): crbug.com/375522
+ int64 a6 = 111111111111 @6;
+ uint64 a7 /* = 9999999999999999999 */ @7;
+ int32 a8 = 0x12345 @8;
+ int32 a9 = -0x12345 @9;
+ // TODO(vtl): crbug.com/375829
+ int32 a10 /* = 010 */ @10; // Octal.
+ int32 a11 /* = -010 */ @11; // Negative octal.
+ int32 a12 = +1234 @12;
+ bool a13 = true @13;
+ bool a14 = false @14;
+ float a15 = 123.25 @15;
+ double a16 = 1234567890.123 @16;
+ double a17 = 1E10 @17;
+ double a18 = -1.2E+20 @18;
+ double a19 = +1.23E-20 @19;
+
+ // TODO(vtl): Add tests for default vs null when those are implemented (for
+ // structs, arrays, and strings).
+ sample.DefaultsTestInner a20 @20;
+ uint8[] a21 @21;
+ string a22 @22;
};
struct StructWithHoleV1 {
diff --git a/mojo/public/tools/bindings/pylib/mojom/parse/parser.py b/mojo/public/tools/bindings/pylib/mojom/parse/parser.py
index f0aea16..342ac4a 100644
--- a/mojo/public/tools/bindings/pylib/mojom/parse/parser.py
+++ b/mojo/public/tools/bindings/pylib/mojom/parse/parser.py
@@ -143,7 +143,6 @@ class Parser(object):
def p_default(self, p):
"""default : EQUALS expression
- | EQUALS expression_object
| """
if len(p) > 2:
p[0] = p[2]
@@ -257,40 +256,6 @@ class Parser(object):
### Expressions ###
- def p_expression_object(self, p):
- """expression_object : expression_array
- | LBRACE expression_object_elements RBRACE """
- if len(p) < 3:
- p[0] = p[1]
- else:
- p[0] = ('OBJECT', p[2])
-
- def p_expression_object_elements(self, p):
- """expression_object_elements : expression_object
- | expression_object COMMA expression_object_elements
- | """
- if len(p) == 2:
- p[0] = _ListFromConcat(p[1])
- elif len(p) > 3:
- p[0] = _ListFromConcat(p[1], p[3])
-
- def p_expression_array(self, p):
- """expression_array : expression
- | LBRACKET expression_array_elements RBRACKET """
- if len(p) < 3:
- p[0] = p[1]
- else:
- p[0] = ('ARRAY', p[2])
-
- def p_expression_array_elements(self, p):
- """expression_array_elements : expression_object
- | expression_object COMMA expression_array_elements
- | """
- if len(p) == 2:
- p[0] = _ListFromConcat(p[1])
- elif len(p) > 3:
- p[0] = _ListFromConcat(p[1], p[3])
-
# TODO(vtl): This is now largely redundant.
def p_expression(self, p):
"""expression : binary_expression"""