| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package serialization | 5 package serialization |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "fmt" | 8 "fmt" |
| 9 "mojo/public/go/bindings" | 9 "mojo/public/go/bindings" |
| 10 "mojom/mojom_parser/generated/mojom_files" | 10 "mojom/mojom_parser/generated/mojom_files" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 } | 49 } |
| 50 | 50 |
| 51 // addTestCase() should be invoked at the start of a case in | 51 // addTestCase() should be invoked at the start of a case in |
| 52 // TestSingleFileSerialization. | 52 // TestSingleFileSerialization. |
| 53 func (test *singleFileTest) addTestCase(moduleNameSpace, contents string) { | 53 func (test *singleFileTest) addTestCase(moduleNameSpace, contents string) { |
| 54 fileName := fmt.Sprintf("file%d", test.testCaseNum) | 54 fileName := fmt.Sprintf("file%d", test.testCaseNum) |
| 55 test.cases = append(test.cases, singleFileTestCase{fileName, contents, f
alse, | 55 test.cases = append(test.cases, singleFileTestCase{fileName, contents, f
alse, |
| 56 new(mojom_files.MojomFile), new(mojom_files.MojomFileGraph)}) | 56 new(mojom_files.MojomFile), new(mojom_files.MojomFileGraph)}) |
| 57 | 57 |
| 58 test.expectedFile().FileName = fileName | 58 test.expectedFile().FileName = fileName |
| 59 » test.expectedFile().ModuleNamespace = newString(moduleNameSpace) | 59 » test.expectedFile().ModuleNamespace = &moduleNameSpace |
| 60 | 60 |
| 61 test.expectedGraph().ResolvedTypes = make(map[string]mojom_types.UserDef
inedType) | 61 test.expectedGraph().ResolvedTypes = make(map[string]mojom_types.UserDef
inedType) |
| 62 test.expectedGraph().ResolvedValues = make(map[string]mojom_types.UserDe
finedValue) | 62 test.expectedGraph().ResolvedValues = make(map[string]mojom_types.UserDe
finedValue) |
| 63 } | 63 } |
| 64 | 64 |
| 65 // endTestCase() should be invoked at the end of a case in | 65 // endTestCase() should be invoked at the end of a case in |
| 66 // TestSingleFileSerialization. | 66 // TestSingleFileSerialization. |
| 67 func (test *singleFileTest) endTestCase() { | 67 func (test *singleFileTest) endTestCase() { |
| 68 test.expectedGraph().Files = make(map[string]mojom_files.MojomFile) | 68 test.expectedGraph().Files = make(map[string]mojom_files.MojomFile) |
| 69 test.expectedGraph().Files[test.fileName()] = *test.expectedFile() | 69 test.expectedGraph().Files[test.fileName()] = *test.expectedFile() |
| 70 test.testCaseNum += 1 | 70 test.testCaseNum += 1 |
| 71 } | 71 } |
| 72 | 72 |
| 73 // newDeclData constructs a new DeclarationData with the given data. | 73 // newDeclData constructs a new DeclarationData with the given data. |
| 74 func (test *singleFileTest) newDeclData(shortName, fullIdentifier string) *mojom
_types.DeclarationData { | 74 func (test *singleFileTest) newDeclData(shortName, fullIdentifier string) *mojom
_types.DeclarationData { |
| 75 return &mojom_types.DeclarationData{ | 75 return &mojom_types.DeclarationData{ |
| 76 » » ShortName: newString(shortName), | 76 » » ShortName: &shortName, |
| 77 » » FullIdentifier: newString(fullIdentifier), | 77 » » FullIdentifier: &fullIdentifier, |
| 78 DeclaredOrdinal: -1, | 78 DeclaredOrdinal: -1, |
| 79 DeclarationOrder: -1, | 79 DeclarationOrder: -1, |
| 80 SourceFileInfo: &mojom_types.SourceFileInfo{ | 80 SourceFileInfo: &mojom_types.SourceFileInfo{ |
| 81 FileName: test.fileName(), | 81 FileName: test.fileName(), |
| 82 }} | 82 }} |
| 83 } | 83 } |
| 84 | 84 |
| 85 // TestSingleFileSerialization uses a series of test cases in which the text of
a .mojom | 85 // TestSingleFileSerialization uses a series of test cases in which the text of
a .mojom |
| 86 // file is specified and the expected MojomFileGraph is specified using Go struc
t literals. | 86 // file is specified and the expected MojomFileGraph is specified using Go struc
t literals. |
| 87 func TestSingleFileSerialization(t *testing.T) { | 87 func TestSingleFileSerialization(t *testing.T) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 IntValue: -1, | 146 IntValue: -1, |
| 147 }} | 147 }} |
| 148 | 148 |
| 149 // Hats.COWBOY | 149 // Hats.COWBOY |
| 150 test.expectedGraph().ResolvedValues["TYPE_KEY:mojom.test.Foo.Hat
s.COWBOY"] = &mojom_types.UserDefinedValueEnumValue{mojom_types.EnumValue{ | 150 test.expectedGraph().ResolvedValues["TYPE_KEY:mojom.test.Foo.Hat
s.COWBOY"] = &mojom_types.UserDefinedValueEnumValue{mojom_types.EnumValue{ |
| 151 DeclData: test.newDeclData("COWBOY", "mojom.test.Foo.
Hats.COWBOY"), | 151 DeclData: test.newDeclData("COWBOY", "mojom.test.Foo.
Hats.COWBOY"), |
| 152 EnumTypeKey: "TYPE_KEY:mojom.test.Foo.Hats", | 152 EnumTypeKey: "TYPE_KEY:mojom.test.Foo.Hats", |
| 153 IntValue: 3, | 153 IntValue: 3, |
| 154 InitializerValue: &mojom_types.ValueUserValueReference{m
ojom_types.UserValueReference{ | 154 InitializerValue: &mojom_types.ValueUserValueReference{m
ojom_types.UserValueReference{ |
| 155 Identifier: "NUM_MAGI", | 155 Identifier: "NUM_MAGI", |
| 156 » » » » ValueKey: newString("TYPE_KEY:mojom
.test.NUM_MAGI"), | 156 » » » » ValueKey: stringPointer("TYPE_KEY:m
ojom.test.NUM_MAGI"), |
| 157 ResolvedConcreteValue: &mojom_types.ValueLiteral
Value{&mojom_types.LiteralValueInt64Value{3}}, | 157 ResolvedConcreteValue: &mojom_types.ValueLiteral
Value{&mojom_types.LiteralValueInt64Value{3}}, |
| 158 }}, | 158 }}, |
| 159 }} | 159 }} |
| 160 | 160 |
| 161 // ResolvedTypes | 161 // ResolvedTypes |
| 162 | 162 |
| 163 // struct Foo | 163 // struct Foo |
| 164 test.expectedGraph().ResolvedTypes["TYPE_KEY:mojom.test.Foo"] =
&mojom_types.UserDefinedTypeStructType{mojom_types.MojomStruct{ | 164 test.expectedGraph().ResolvedTypes["TYPE_KEY:mojom.test.Foo"] =
&mojom_types.UserDefinedTypeStructType{mojom_types.MojomStruct{ |
| 165 DeclData: &mojom_types.DeclarationData{ | 165 DeclData: &mojom_types.DeclarationData{ |
| 166 » » » » ShortName: newString("Foo"), | 166 » » » » ShortName: stringPointer("Foo"), |
| 167 » » » » FullIdentifier: newString("mojom.test.Foo"), | 167 » » » » FullIdentifier: stringPointer("mojom.test.Foo"
), |
| 168 DeclaredOrdinal: -1, | 168 DeclaredOrdinal: -1, |
| 169 DeclarationOrder: -1, | 169 DeclarationOrder: -1, |
| 170 SourceFileInfo: &mojom_types.SourceFileInfo{ | 170 SourceFileInfo: &mojom_types.SourceFileInfo{ |
| 171 FileName: test.fileName(), | 171 FileName: test.fileName(), |
| 172 }, | 172 }, |
| 173 ContainedDeclarations: &mojom_types.ContainedDec
larations{ | 173 ContainedDeclarations: &mojom_types.ContainedDec
larations{ |
| 174 Enums: &[]string{"TYPE_KEY:mojom.test.Fo
o.Hats"}}, | 174 Enums: &[]string{"TYPE_KEY:mojom.test.Fo
o.Hats"}}, |
| 175 }, | 175 }, |
| 176 Fields: []mojom_types.StructField{ | 176 Fields: []mojom_types.StructField{ |
| 177 // field x | 177 // field x |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 } | 292 } |
| 293 return fmt.Errorf("*****\nexpected=\n*****\n%q\n*****\na
ctual=\n*****\n%q\n*****\n"+ | 293 return fmt.Errorf("*****\nexpected=\n*****\n%q\n*****\na
ctual=\n*****\n%q\n*****\n"+ |
| 294 "match failed at position %d: expected=\n*****\n
%s\n******\nactual=\n*****\n%s\n******\n", | 294 "match failed at position %d: expected=\n*****\n
%s\n******\nactual=\n*****\n%s\n******\n", |
| 295 expectedString, actualString, diffPos, mismatchE
xpected, mismatchActual) | 295 expectedString, actualString, diffPos, mismatchE
xpected, mismatchActual) |
| 296 } else { | 296 } else { |
| 297 return fmt.Errorf("expected != actual but the two printe
d equal.") | 297 return fmt.Errorf("expected != actual but the two printe
d equal.") |
| 298 } | 298 } |
| 299 } | 299 } |
| 300 return nil | 300 return nil |
| 301 } | 301 } |
| OLD | NEW |