| Index: mojom/mojom_parser/serialization/serialization_test.go
|
| diff --git a/mojom/mojom_parser/serialization/serialization_test.go b/mojom/mojom_parser/serialization/serialization_test.go
|
| index 7e81c322ba67839dbd9295642d90e4ded964609f..b08512645a43ec27df127a08c6ef8cea8c173800 100644
|
| --- a/mojom/mojom_parser/serialization/serialization_test.go
|
| +++ b/mojom/mojom_parser/serialization/serialization_test.go
|
| @@ -1186,40 +1186,44 @@ func TestWithComputedData(t *testing.T) {
|
| {
|
| DeclData: test.newShortDeclDataO(0, -1, "x"),
|
| Type: &mojom_types.TypeSimpleType{mojom_types.SimpleType_Int32},
|
| + Offset: 0,
|
| },
|
| // field y
|
| {
|
| DeclData: test.newShortDeclDataO(1, -1, "y"),
|
| Type: &mojom_types.TypeSimpleType{mojom_types.SimpleType_Int32},
|
| + Offset: 4,
|
| },
|
| // field z
|
| {
|
| DeclData: test.newShortDeclDataAO(2, -1, "z", &[]mojom_types.Attribute{{"MinVersion", &mojom_types.LiteralValueInt8Value{1}}}),
|
| Type: &mojom_types.TypeArrayType{mojom_types.ArrayType{true, -1, &mojom_types.TypeSimpleType{mojom_types.SimpleType_Int32}}},
|
| MinVersion: 1,
|
| + Offset: 8,
|
| },
|
| // field w
|
| {
|
| DeclData: test.newShortDeclDataAO(3, -1, "w", &[]mojom_types.Attribute{{"MinVersion", &mojom_types.LiteralValueInt8Value{2}}}),
|
| Type: &mojom_types.TypeArrayType{mojom_types.ArrayType{true, -1, &mojom_types.TypeSimpleType{mojom_types.SimpleType_Int32}}},
|
| MinVersion: 2,
|
| + Offset: 16,
|
| },
|
| },
|
| VersionInfo: &[]mojom_types.StructVersion{
|
| mojom_types.StructVersion{
|
| VersionNumber: 0,
|
| NumFields: 2,
|
| - NumBytes: 0,
|
| + NumBytes: 16,
|
| },
|
| mojom_types.StructVersion{
|
| VersionNumber: 1,
|
| NumFields: 3,
|
| - NumBytes: 0,
|
| + NumBytes: 24,
|
| },
|
| mojom_types.StructVersion{
|
| VersionNumber: 2,
|
| NumFields: 4,
|
| - NumBytes: 0,
|
| + NumBytes: 32,
|
| },
|
| },
|
| }}
|
| @@ -1259,40 +1263,44 @@ func TestWithComputedData(t *testing.T) {
|
| {
|
| DeclData: test.newShortDeclDataO(0, -1, "x"),
|
| Type: &mojom_types.TypeSimpleType{mojom_types.SimpleType_Int32},
|
| + Offset: 0,
|
| },
|
| // field y
|
| {
|
| DeclData: test.newShortDeclDataO(1, -1, "y"),
|
| Type: &mojom_types.TypeSimpleType{mojom_types.SimpleType_Int32},
|
| + Offset: 4,
|
| },
|
| // field z
|
| {
|
| DeclData: test.newShortDeclDataAO(2, -1, "z", &[]mojom_types.Attribute{{"MinVersion", &mojom_types.LiteralValueInt8Value{1}}}),
|
| Type: &mojom_types.TypeArrayType{mojom_types.ArrayType{true, -1, &mojom_types.TypeSimpleType{mojom_types.SimpleType_Int32}}},
|
| MinVersion: 1,
|
| + Offset: 8,
|
| },
|
| // field w
|
| {
|
| DeclData: test.newShortDeclDataAO(3, -1, "w", &[]mojom_types.Attribute{{"MinVersion", &mojom_types.LiteralValueInt8Value{3}}}),
|
| Type: &mojom_types.TypeArrayType{mojom_types.ArrayType{true, -1, &mojom_types.TypeSimpleType{mojom_types.SimpleType_Int32}}},
|
| MinVersion: 3,
|
| + Offset: 16,
|
| },
|
| },
|
| VersionInfo: &[]mojom_types.StructVersion{
|
| mojom_types.StructVersion{
|
| VersionNumber: 0,
|
| NumFields: 2,
|
| - NumBytes: 0,
|
| + NumBytes: 16,
|
| },
|
| mojom_types.StructVersion{
|
| VersionNumber: 1,
|
| NumFields: 3,
|
| - NumBytes: 0,
|
| + NumBytes: 24,
|
| },
|
| mojom_types.StructVersion{
|
| VersionNumber: 3,
|
| NumFields: 4,
|
| - NumBytes: 0,
|
| + NumBytes: 32,
|
| },
|
| },
|
| }}
|
| @@ -1332,35 +1340,39 @@ func TestWithComputedData(t *testing.T) {
|
| {
|
| DeclData: test.newShortDeclDataO(0, -1, "x"),
|
| Type: &mojom_types.TypeSimpleType{mojom_types.SimpleType_Int32},
|
| + Offset: 0,
|
| },
|
| // field y
|
| {
|
| DeclData: test.newShortDeclDataO(1, -1, "y"),
|
| Type: &mojom_types.TypeSimpleType{mojom_types.SimpleType_Int32},
|
| + Offset: 4,
|
| },
|
| // field z
|
| {
|
| DeclData: test.newShortDeclDataAO(2, -1, "z", &[]mojom_types.Attribute{{"MinVersion", &mojom_types.LiteralValueInt8Value{1}}}),
|
| Type: &mojom_types.TypeArrayType{mojom_types.ArrayType{true, -1, &mojom_types.TypeSimpleType{mojom_types.SimpleType_Int32}}},
|
| MinVersion: 1,
|
| + Offset: 8,
|
| },
|
| // field w
|
| {
|
| DeclData: test.newShortDeclDataAO(3, -1, "w", &[]mojom_types.Attribute{{"MinVersion", &mojom_types.LiteralValueInt8Value{1}}}),
|
| Type: &mojom_types.TypeArrayType{mojom_types.ArrayType{true, -1, &mojom_types.TypeSimpleType{mojom_types.SimpleType_Int32}}},
|
| MinVersion: 1,
|
| + Offset: 16,
|
| },
|
| },
|
| VersionInfo: &[]mojom_types.StructVersion{
|
| mojom_types.StructVersion{
|
| VersionNumber: 0,
|
| NumFields: 2,
|
| - NumBytes: 0,
|
| + NumBytes: 16,
|
| },
|
| mojom_types.StructVersion{
|
| VersionNumber: 1,
|
| NumFields: 4,
|
| - NumBytes: 0,
|
| + NumBytes: 32,
|
| },
|
| },
|
| }}
|
| @@ -1401,40 +1413,183 @@ func TestWithComputedData(t *testing.T) {
|
| {
|
| DeclData: test.newShortDeclDataO(3, 0, "x"),
|
| Type: &mojom_types.TypeSimpleType{mojom_types.SimpleType_Int32},
|
| + Offset: 0,
|
| },
|
| // field y
|
| {
|
| DeclData: test.newShortDeclDataO(0, 1, "y"),
|
| Type: &mojom_types.TypeSimpleType{mojom_types.SimpleType_Int32},
|
| + Offset: 4,
|
| },
|
| // field z
|
| {
|
| DeclData: test.newShortDeclDataAO(1, 2, "z", &[]mojom_types.Attribute{{"MinVersion", &mojom_types.LiteralValueInt8Value{1}}}),
|
| Type: &mojom_types.TypeArrayType{mojom_types.ArrayType{true, -1, &mojom_types.TypeSimpleType{mojom_types.SimpleType_Int32}}},
|
| MinVersion: 1,
|
| + Offset: 8,
|
| },
|
| // field w
|
| {
|
| DeclData: test.newShortDeclDataAO(2, 3, "w", &[]mojom_types.Attribute{{"MinVersion", &mojom_types.LiteralValueInt8Value{2}}}),
|
| Type: &mojom_types.TypeArrayType{mojom_types.ArrayType{true, -1, &mojom_types.TypeSimpleType{mojom_types.SimpleType_Int32}}},
|
| MinVersion: 2,
|
| + Offset: 16,
|
| },
|
| },
|
| VersionInfo: &[]mojom_types.StructVersion{
|
| mojom_types.StructVersion{
|
| VersionNumber: 0,
|
| NumFields: 2,
|
| - NumBytes: 0,
|
| + NumBytes: 16,
|
| },
|
| mojom_types.StructVersion{
|
| VersionNumber: 1,
|
| NumFields: 3,
|
| - NumBytes: 0,
|
| + NumBytes: 24,
|
| },
|
| mojom_types.StructVersion{
|
| VersionNumber: 2,
|
| NumFields: 4,
|
| - NumBytes: 0,
|
| + NumBytes: 32,
|
| + },
|
| + },
|
| + }}
|
| +
|
| + test.endTestCase()
|
| + }
|
| +
|
| + ////////////////////////////////////////////////////////////
|
| + // Test Case: 3 boolean fields
|
| + ////////////////////////////////////////////////////////////
|
| + {
|
| + contents := `
|
| + struct MyStruct1 {
|
| + bool b1;
|
| + bool b2;
|
| + bool b3;
|
| + };`
|
| +
|
| + test.addTestCase("", contents)
|
| +
|
| + test.expectedFile().DeclaredMojomObjects.Structs = &[]string{"TYPE_KEY:MyStruct1"}
|
| +
|
| + // ResolvedTypes
|
| +
|
| + // struct Foo
|
| + test.expectedGraph().ResolvedTypes["TYPE_KEY:MyStruct1"] = &mojom_types.UserDefinedTypeStructType{mojom_types.MojomStruct{
|
| + DeclData: test.newDeclData("MyStruct1", "MyStruct1"),
|
| + Fields: []mojom_types.StructField{
|
| + // The fields are in ordinal order and the first two arguments to newShortDeclDataO() are
|
| + // declarationOrder and declaredOrdinal.
|
| + // field b1
|
| + {
|
| + DeclData: test.newShortDeclDataO(0, -1, "b1"),
|
| + Type: &mojom_types.TypeSimpleType{mojom_types.SimpleType_Bool},
|
| + Offset: 0,
|
| + Bit: 0,
|
| + },
|
| + // field b2
|
| + {
|
| + DeclData: test.newShortDeclDataO(1, -1, "b2"),
|
| + Type: &mojom_types.TypeSimpleType{mojom_types.SimpleType_Bool},
|
| + Offset: 0,
|
| + Bit: 1,
|
| + },
|
| + // field b3
|
| + {
|
| + DeclData: test.newShortDeclDataO(2, -1, "b3"),
|
| + Type: &mojom_types.TypeSimpleType{mojom_types.SimpleType_Bool},
|
| + Offset: 0,
|
| + Bit: 2,
|
| + },
|
| + },
|
| + VersionInfo: &[]mojom_types.StructVersion{
|
| + mojom_types.StructVersion{
|
| + VersionNumber: 0,
|
| + NumFields: 3,
|
| + NumBytes: 16,
|
| + },
|
| + },
|
| + }}
|
| +
|
| + test.endTestCase()
|
| + }
|
| +
|
| + ////////////////////////////////////////////////////////////
|
| + // Test Case: int8 field + 2 boolean fields + int32field + 2 boolean fields
|
| + ////////////////////////////////////////////////////////////
|
| + {
|
| + contents := `
|
| + struct MyStruct1 {
|
| + int8 x;
|
| +
|
| + bool b1;
|
| + bool b2;
|
| +
|
| + int32 y;
|
| +
|
| + bool b3;
|
| + bool b4;
|
| + };`
|
| +
|
| + test.addTestCase("", contents)
|
| +
|
| + test.expectedFile().DeclaredMojomObjects.Structs = &[]string{"TYPE_KEY:MyStruct1"}
|
| +
|
| + // ResolvedTypes
|
| +
|
| + // struct Foo
|
| + test.expectedGraph().ResolvedTypes["TYPE_KEY:MyStruct1"] = &mojom_types.UserDefinedTypeStructType{mojom_types.MojomStruct{
|
| + DeclData: test.newDeclData("MyStruct1", "MyStruct1"),
|
| + Fields: []mojom_types.StructField{
|
| + // The fields are in ordinal order and the first two arguments to newShortDeclDataO() are
|
| + // declarationOrder and declaredOrdinal.
|
| + // field x
|
| + {
|
| + DeclData: test.newShortDeclDataO(0, -1, "x"),
|
| + Type: &mojom_types.TypeSimpleType{mojom_types.SimpleType_Int8},
|
| + Offset: 0,
|
| + },
|
| + // field b1
|
| + {
|
| + DeclData: test.newShortDeclDataO(1, -1, "b1"),
|
| + Type: &mojom_types.TypeSimpleType{mojom_types.SimpleType_Bool},
|
| + Offset: 1,
|
| + Bit: 0,
|
| + },
|
| + // field b2
|
| + {
|
| + DeclData: test.newShortDeclDataO(2, -1, "b2"),
|
| + Type: &mojom_types.TypeSimpleType{mojom_types.SimpleType_Bool},
|
| + Offset: 1,
|
| + Bit: 1,
|
| + },
|
| + // field y
|
| + {
|
| + DeclData: test.newShortDeclDataO(3, -1, "y"),
|
| + Type: &mojom_types.TypeSimpleType{mojom_types.SimpleType_Int32},
|
| + Offset: 4,
|
| + },
|
| + // field b3
|
| + {
|
| + DeclData: test.newShortDeclDataO(4, -1, "b3"),
|
| + Type: &mojom_types.TypeSimpleType{mojom_types.SimpleType_Bool},
|
| + Offset: 1,
|
| + Bit: 2,
|
| + },
|
| + // field b4
|
| + {
|
| + DeclData: test.newShortDeclDataO(5, -1, "b4"),
|
| + Type: &mojom_types.TypeSimpleType{mojom_types.SimpleType_Bool},
|
| + Offset: 1,
|
| + Bit: 3,
|
| + },
|
| + },
|
| + VersionInfo: &[]mojom_types.StructVersion{
|
| + mojom_types.StructVersion{
|
| + VersionNumber: 0,
|
| + NumFields: 6,
|
| + NumBytes: 16,
|
| },
|
| },
|
| }}
|
|
|