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 "bytes" | 8 "bytes" |
9 "compress/gzip" | 9 "compress/gzip" |
10 "encoding/base64" | 10 "encoding/base64" |
(...skipping 1084 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1095 parser := parser.MakeParser(c.fileName, c.fileName, c.mojomConte
nts, descriptor, nil) | 1095 parser := parser.MakeParser(c.fileName, c.fileName, c.mojomConte
nts, descriptor, nil) |
1096 parser.Parse() | 1096 parser.Parse() |
1097 if !parser.OK() { | 1097 if !parser.OK() { |
1098 t.Errorf("Parsing error for %s: %s", c.fileName, parser.
GetError().Error()) | 1098 t.Errorf("Parsing error for %s: %s", c.fileName, parser.
GetError().Error()) |
1099 continue | 1099 continue |
1100 } | 1100 } |
1101 if err := descriptor.Resolve(); err != nil { | 1101 if err := descriptor.Resolve(); err != nil { |
1102 t.Errorf("Resolve error for %s: %s", c.fileName, err.Err
or()) | 1102 t.Errorf("Resolve error for %s: %s", c.fileName, err.Err
or()) |
1103 continue | 1103 continue |
1104 } | 1104 } |
1105 if err := descriptor.ComputeEnumValueIntegers(); err != nil { | 1105 if err := descriptor.ComputeFinalData(); err != nil { |
1106 t.Errorf("ComputeEnumValueIntegers error for %s: %s", c.
fileName, err.Error()) | 1106 t.Errorf("ComputeFinalData error for %s: %s", c.fileName
, err.Error()) |
1107 continue | 1107 continue |
1108 } | 1108 } |
1109 if err := descriptor.ComputeDataForGenerators(); err != nil { | 1109 |
1110 t.Errorf("ComputeDataForGenerators error for %s: %s", c.
fileName, err.Error()) | 1110 // Simulate setting the canonical file name for the imported fil
es. In real operation |
1111 continue | 1111 // this step is done in parser_driver.go when each of the import
ed files are parsed. |
1112 } | 1112 mojomFile := parser.GetMojomFile() |
1113 | 1113 if mojomFile.Imports != nil { |
| 1114 for _, imp := range mojomFile.Imports { |
| 1115 imp.CanonicalFileName = fmt.Sprintf("%s.canonica
l", imp.SpecifiedName) |
| 1116 } |
| 1117 } |
| 1118 |
| 1119 // Serialize |
| 1120 bytes, _, err := serialize(descriptor, false, false, c.lineAndco
lumnNumbers, false, false) |
| 1121 if err != nil { |
| 1122 t.Errorf("Serialization error for %s: %s", c.fileName, e
rr.Error()) |
| 1123 continue |
| 1124 } |
| 1125 |
| 1126 // Serialize again and check for consistency. |
| 1127 bytes2, _, err := serialize(descriptor, false, false, c.lineAndc
olumnNumbers, false, false) |
| 1128 if err != nil { |
| 1129 t.Errorf("Serialization error for %s: %s", c.fileName, e
rr.Error()) |
| 1130 continue |
| 1131 } |
| 1132 |
| 1133 if !reflect.DeepEqual(bytes, bytes2) { |
| 1134 t.Errorf("Inconsistent serialization for %s:\nbytes=%v\n
bytes2=%v\n", |
| 1135 c.fileName, bytes, bytes2) |
| 1136 continue |
| 1137 } |
| 1138 |
| 1139 // Deserialize |
| 1140 decoder := bindings.NewDecoder(bytes, nil) |
| 1141 fileGraph := mojom_files.MojomFileGraph{} |
| 1142 fileGraph.Decode(decoder) |
| 1143 |
| 1144 // Compare |
| 1145 if err := compareTwoGoObjects(c.expectedGraph, &fileGraph); err
!= nil { |
| 1146 t.Errorf("%s:\n%s", c.fileName, err.Error()) |
| 1147 continue |
| 1148 } |
| 1149 } |
| 1150 } |
| 1151 |
| 1152 // TestWithComputedData is similar to the previous test except that it sets |
| 1153 // emitComputedPackingData = true. |
| 1154 func TestWithComputedData(t *testing.T) { |
| 1155 test := singleFileTest{} |
| 1156 |
| 1157 //////////////////////////////////////////////////////////// |
| 1158 // Test Case: Test struct field min versions: 1,2 |
| 1159 //////////////////////////////////////////////////////////// |
| 1160 { |
| 1161 contents := ` |
| 1162 struct Foo{ |
| 1163 int32 x; |
| 1164 int32 y; |
| 1165 |
| 1166 [MinVersion = 1] |
| 1167 array<int32>? z; |
| 1168 |
| 1169 [MinVersion = 2] |
| 1170 array<int32>? w; |
| 1171 };` |
| 1172 |
| 1173 test.addTestCase("", contents) |
| 1174 |
| 1175 test.expectedFile().DeclaredMojomObjects.Structs = &[]string{"TY
PE_KEY:Foo"} |
| 1176 |
| 1177 // ResolvedTypes |
| 1178 |
| 1179 // struct Foo |
| 1180 test.expectedGraph().ResolvedTypes["TYPE_KEY:Foo"] = &mojom_type
s.UserDefinedTypeStructType{mojom_types.MojomStruct{ |
| 1181 DeclData: test.newDeclData("Foo", "Foo"), |
| 1182 Fields: []mojom_types.StructField{ |
| 1183 // The fields are in ordinal order and the first
two arguments to newShortDeclDataO() are |
| 1184 // declarationOrder and declaredOrdinal. |
| 1185 // field x |
| 1186 { |
| 1187 DeclData: test.newShortDeclDataO(0, -1,
"x"), |
| 1188 Type: &mojom_types.TypeSimpleType{mo
jom_types.SimpleType_Int32}, |
| 1189 }, |
| 1190 // field y |
| 1191 { |
| 1192 DeclData: test.newShortDeclDataO(1, -1,
"y"), |
| 1193 Type: &mojom_types.TypeSimpleType{mo
jom_types.SimpleType_Int32}, |
| 1194 }, |
| 1195 // field z |
| 1196 { |
| 1197 DeclData: test.newShortDeclDataAO(2, -
1, "z", &[]mojom_types.Attribute{{"MinVersion", &mojom_types.LiteralValueInt8Val
ue{1}}}), |
| 1198 Type: &mojom_types.TypeArrayType{m
ojom_types.ArrayType{true, -1, &mojom_types.TypeSimpleType{mojom_types.SimpleTyp
e_Int32}}}, |
| 1199 MinVersion: 1, |
| 1200 }, |
| 1201 // field w |
| 1202 { |
| 1203 DeclData: test.newShortDeclDataAO(3, -
1, "w", &[]mojom_types.Attribute{{"MinVersion", &mojom_types.LiteralValueInt8Val
ue{2}}}), |
| 1204 Type: &mojom_types.TypeArrayType{m
ojom_types.ArrayType{true, -1, &mojom_types.TypeSimpleType{mojom_types.SimpleTyp
e_Int32}}}, |
| 1205 MinVersion: 2, |
| 1206 }, |
| 1207 }, |
| 1208 VersionInfo: &[]mojom_types.StructVersion{ |
| 1209 mojom_types.StructVersion{ |
| 1210 VersionNumber: 0, |
| 1211 NumFields: 2, |
| 1212 NumBytes: 0, |
| 1213 }, |
| 1214 mojom_types.StructVersion{ |
| 1215 VersionNumber: 1, |
| 1216 NumFields: 3, |
| 1217 NumBytes: 0, |
| 1218 }, |
| 1219 mojom_types.StructVersion{ |
| 1220 VersionNumber: 2, |
| 1221 NumFields: 4, |
| 1222 NumBytes: 0, |
| 1223 }, |
| 1224 }, |
| 1225 }} |
| 1226 |
| 1227 test.endTestCase() |
| 1228 } |
| 1229 |
| 1230 //////////////////////////////////////////////////////////// |
| 1231 // Test Case: Test struct field min versions: 1, 3 |
| 1232 //////////////////////////////////////////////////////////// |
| 1233 { |
| 1234 contents := ` |
| 1235 struct Foo{ |
| 1236 int32 x; |
| 1237 int32 y; |
| 1238 |
| 1239 [MinVersion = 1] |
| 1240 array<int32>? z; |
| 1241 |
| 1242 [MinVersion = 3] |
| 1243 array<int32>? w; |
| 1244 };` |
| 1245 |
| 1246 test.addTestCase("", contents) |
| 1247 |
| 1248 test.expectedFile().DeclaredMojomObjects.Structs = &[]string{"TY
PE_KEY:Foo"} |
| 1249 |
| 1250 // ResolvedTypes |
| 1251 |
| 1252 // struct Foo |
| 1253 test.expectedGraph().ResolvedTypes["TYPE_KEY:Foo"] = &mojom_type
s.UserDefinedTypeStructType{mojom_types.MojomStruct{ |
| 1254 DeclData: test.newDeclData("Foo", "Foo"), |
| 1255 Fields: []mojom_types.StructField{ |
| 1256 // The fields are in ordinal order and the first
two arguments to newShortDeclDataO() are |
| 1257 // declarationOrder and declaredOrdinal. |
| 1258 // field x |
| 1259 { |
| 1260 DeclData: test.newShortDeclDataO(0, -1,
"x"), |
| 1261 Type: &mojom_types.TypeSimpleType{mo
jom_types.SimpleType_Int32}, |
| 1262 }, |
| 1263 // field y |
| 1264 { |
| 1265 DeclData: test.newShortDeclDataO(1, -1,
"y"), |
| 1266 Type: &mojom_types.TypeSimpleType{mo
jom_types.SimpleType_Int32}, |
| 1267 }, |
| 1268 // field z |
| 1269 { |
| 1270 DeclData: test.newShortDeclDataAO(2, -
1, "z", &[]mojom_types.Attribute{{"MinVersion", &mojom_types.LiteralValueInt8Val
ue{1}}}), |
| 1271 Type: &mojom_types.TypeArrayType{m
ojom_types.ArrayType{true, -1, &mojom_types.TypeSimpleType{mojom_types.SimpleTyp
e_Int32}}}, |
| 1272 MinVersion: 1, |
| 1273 }, |
| 1274 // field w |
| 1275 { |
| 1276 DeclData: test.newShortDeclDataAO(3, -
1, "w", &[]mojom_types.Attribute{{"MinVersion", &mojom_types.LiteralValueInt8Val
ue{3}}}), |
| 1277 Type: &mojom_types.TypeArrayType{m
ojom_types.ArrayType{true, -1, &mojom_types.TypeSimpleType{mojom_types.SimpleTyp
e_Int32}}}, |
| 1278 MinVersion: 3, |
| 1279 }, |
| 1280 }, |
| 1281 VersionInfo: &[]mojom_types.StructVersion{ |
| 1282 mojom_types.StructVersion{ |
| 1283 VersionNumber: 0, |
| 1284 NumFields: 2, |
| 1285 NumBytes: 0, |
| 1286 }, |
| 1287 mojom_types.StructVersion{ |
| 1288 VersionNumber: 1, |
| 1289 NumFields: 3, |
| 1290 NumBytes: 0, |
| 1291 }, |
| 1292 mojom_types.StructVersion{ |
| 1293 VersionNumber: 3, |
| 1294 NumFields: 4, |
| 1295 NumBytes: 0, |
| 1296 }, |
| 1297 }, |
| 1298 }} |
| 1299 |
| 1300 test.endTestCase() |
| 1301 } |
| 1302 |
| 1303 //////////////////////////////////////////////////////////// |
| 1304 // Test Case: Test struct field min versions: 1, 1 |
| 1305 //////////////////////////////////////////////////////////// |
| 1306 { |
| 1307 contents := ` |
| 1308 struct Foo{ |
| 1309 int32 x; |
| 1310 int32 y; |
| 1311 |
| 1312 [MinVersion = 1] |
| 1313 array<int32>? z; |
| 1314 |
| 1315 [MinVersion = 1] |
| 1316 array<int32>? w; |
| 1317 };` |
| 1318 |
| 1319 test.addTestCase("", contents) |
| 1320 |
| 1321 test.expectedFile().DeclaredMojomObjects.Structs = &[]string{"TY
PE_KEY:Foo"} |
| 1322 |
| 1323 // ResolvedTypes |
| 1324 |
| 1325 // struct Foo |
| 1326 test.expectedGraph().ResolvedTypes["TYPE_KEY:Foo"] = &mojom_type
s.UserDefinedTypeStructType{mojom_types.MojomStruct{ |
| 1327 DeclData: test.newDeclData("Foo", "Foo"), |
| 1328 Fields: []mojom_types.StructField{ |
| 1329 // The fields are in ordinal order and the first
two arguments to newShortDeclDataO() are |
| 1330 // declarationOrder and declaredOrdinal. |
| 1331 // field x |
| 1332 { |
| 1333 DeclData: test.newShortDeclDataO(0, -1,
"x"), |
| 1334 Type: &mojom_types.TypeSimpleType{mo
jom_types.SimpleType_Int32}, |
| 1335 }, |
| 1336 // field y |
| 1337 { |
| 1338 DeclData: test.newShortDeclDataO(1, -1,
"y"), |
| 1339 Type: &mojom_types.TypeSimpleType{mo
jom_types.SimpleType_Int32}, |
| 1340 }, |
| 1341 // field z |
| 1342 { |
| 1343 DeclData: test.newShortDeclDataAO(2, -
1, "z", &[]mojom_types.Attribute{{"MinVersion", &mojom_types.LiteralValueInt8Val
ue{1}}}), |
| 1344 Type: &mojom_types.TypeArrayType{m
ojom_types.ArrayType{true, -1, &mojom_types.TypeSimpleType{mojom_types.SimpleTyp
e_Int32}}}, |
| 1345 MinVersion: 1, |
| 1346 }, |
| 1347 // field w |
| 1348 { |
| 1349 DeclData: test.newShortDeclDataAO(3, -
1, "w", &[]mojom_types.Attribute{{"MinVersion", &mojom_types.LiteralValueInt8Val
ue{1}}}), |
| 1350 Type: &mojom_types.TypeArrayType{m
ojom_types.ArrayType{true, -1, &mojom_types.TypeSimpleType{mojom_types.SimpleTyp
e_Int32}}}, |
| 1351 MinVersion: 1, |
| 1352 }, |
| 1353 }, |
| 1354 VersionInfo: &[]mojom_types.StructVersion{ |
| 1355 mojom_types.StructVersion{ |
| 1356 VersionNumber: 0, |
| 1357 NumFields: 2, |
| 1358 NumBytes: 0, |
| 1359 }, |
| 1360 mojom_types.StructVersion{ |
| 1361 VersionNumber: 1, |
| 1362 NumFields: 4, |
| 1363 NumBytes: 0, |
| 1364 }, |
| 1365 }, |
| 1366 }} |
| 1367 |
| 1368 test.endTestCase() |
| 1369 } |
| 1370 |
| 1371 //////////////////////////////////////////////////////////// |
| 1372 // Test Case: Test struct field min versions: 1,2 with specified ordinal
s |
| 1373 //////////////////////////////////////////////////////////// |
| 1374 { |
| 1375 contents := ` |
| 1376 struct Foo{ |
| 1377 int32 y@1; |
| 1378 |
| 1379 [MinVersion = 1] |
| 1380 array<int32>? z@2; |
| 1381 |
| 1382 [MinVersion = 2] |
| 1383 array<int32>? w@3; |
| 1384 |
| 1385 int32 x@0; |
| 1386 };` |
| 1387 |
| 1388 test.addTestCase("", contents) |
| 1389 |
| 1390 test.expectedFile().DeclaredMojomObjects.Structs = &[]string{"TY
PE_KEY:Foo"} |
| 1391 |
| 1392 // ResolvedTypes |
| 1393 |
| 1394 // struct Foo |
| 1395 test.expectedGraph().ResolvedTypes["TYPE_KEY:Foo"] = &mojom_type
s.UserDefinedTypeStructType{mojom_types.MojomStruct{ |
| 1396 DeclData: test.newDeclData("Foo", "Foo"), |
| 1397 Fields: []mojom_types.StructField{ |
| 1398 // The fields are in ordinal order and the first
two arguments to newShortDeclDataO() are |
| 1399 // declarationOrder and declaredOrdinal. |
| 1400 // field x |
| 1401 { |
| 1402 DeclData: test.newShortDeclDataO(3, 0, "
x"), |
| 1403 Type: &mojom_types.TypeSimpleType{mo
jom_types.SimpleType_Int32}, |
| 1404 }, |
| 1405 // field y |
| 1406 { |
| 1407 DeclData: test.newShortDeclDataO(0, 1, "
y"), |
| 1408 Type: &mojom_types.TypeSimpleType{mo
jom_types.SimpleType_Int32}, |
| 1409 }, |
| 1410 // field z |
| 1411 { |
| 1412 DeclData: test.newShortDeclDataAO(1, 2
, "z", &[]mojom_types.Attribute{{"MinVersion", &mojom_types.LiteralValueInt8Valu
e{1}}}), |
| 1413 Type: &mojom_types.TypeArrayType{m
ojom_types.ArrayType{true, -1, &mojom_types.TypeSimpleType{mojom_types.SimpleTyp
e_Int32}}}, |
| 1414 MinVersion: 1, |
| 1415 }, |
| 1416 // field w |
| 1417 { |
| 1418 DeclData: test.newShortDeclDataAO(2, 3
, "w", &[]mojom_types.Attribute{{"MinVersion", &mojom_types.LiteralValueInt8Valu
e{2}}}), |
| 1419 Type: &mojom_types.TypeArrayType{m
ojom_types.ArrayType{true, -1, &mojom_types.TypeSimpleType{mojom_types.SimpleTyp
e_Int32}}}, |
| 1420 MinVersion: 2, |
| 1421 }, |
| 1422 }, |
| 1423 VersionInfo: &[]mojom_types.StructVersion{ |
| 1424 mojom_types.StructVersion{ |
| 1425 VersionNumber: 0, |
| 1426 NumFields: 2, |
| 1427 NumBytes: 0, |
| 1428 }, |
| 1429 mojom_types.StructVersion{ |
| 1430 VersionNumber: 1, |
| 1431 NumFields: 3, |
| 1432 NumBytes: 0, |
| 1433 }, |
| 1434 mojom_types.StructVersion{ |
| 1435 VersionNumber: 2, |
| 1436 NumFields: 4, |
| 1437 NumBytes: 0, |
| 1438 }, |
| 1439 }, |
| 1440 }} |
| 1441 |
| 1442 test.endTestCase() |
| 1443 } |
| 1444 |
| 1445 //////////////////////////////////////////////////////////// |
| 1446 // Execute all of the test cases. |
| 1447 //////////////////////////////////////////////////////////// |
| 1448 for _, c := range test.cases { |
| 1449 // Parse and resolve the mojom input. |
| 1450 descriptor := mojom.NewMojomDescriptor() |
| 1451 parser := parser.MakeParser(c.fileName, c.fileName, c.mojomConte
nts, descriptor, nil) |
| 1452 parser.Parse() |
| 1453 if !parser.OK() { |
| 1454 t.Errorf("Parsing error for %s: %s", c.fileName, parser.
GetError().Error()) |
| 1455 continue |
| 1456 } |
| 1457 if err := descriptor.Resolve(); err != nil { |
| 1458 t.Errorf("Resolve error for %s: %s", c.fileName, err.Err
or()) |
| 1459 continue |
| 1460 } |
| 1461 if err := descriptor.ComputeFinalData(); err != nil { |
| 1462 t.Errorf("ComputeFinalData error for %s: %s", c.fileName
, err.Error()) |
| 1463 continue |
| 1464 } |
| 1465 |
1114 // Simulate setting the canonical file name for the imported fil
es. In real operation | 1466 // Simulate setting the canonical file name for the imported fil
es. In real operation |
1115 // this step is done in parser_driver.go when each of the import
ed files are parsed. | 1467 // this step is done in parser_driver.go when each of the import
ed files are parsed. |
1116 mojomFile := parser.GetMojomFile() | 1468 mojomFile := parser.GetMojomFile() |
1117 if mojomFile.Imports != nil { | 1469 if mojomFile.Imports != nil { |
1118 for _, imp := range mojomFile.Imports { | 1470 for _, imp := range mojomFile.Imports { |
1119 imp.CanonicalFileName = fmt.Sprintf("%s.canonica
l", imp.SpecifiedName) | 1471 imp.CanonicalFileName = fmt.Sprintf("%s.canonica
l", imp.SpecifiedName) |
1120 } | 1472 } |
1121 } | 1473 } |
1122 | 1474 |
1123 » » // Serialize | 1475 » » // Serialize. Notice that the fourth argument is |true|. |
1124 » » bytes, _, err := serialize(descriptor, false, c.lineAndcolumnNum
bers, false, false) | 1476 » » bytes, _, err := serialize(descriptor, false, false, true, false
, false) |
1125 if err != nil { | 1477 if err != nil { |
1126 t.Errorf("Serialization error for %s: %s", c.fileName, e
rr.Error()) | 1478 t.Errorf("Serialization error for %s: %s", c.fileName, e
rr.Error()) |
1127 continue | 1479 continue |
1128 } | 1480 } |
1129 | 1481 |
1130 // Serialize again and check for consistency. | 1482 // Serialize again and check for consistency. |
1131 » » bytes2, _, err := serialize(descriptor, false, c.lineAndcolumnNu
mbers, false, false) | 1483 » » bytes2, _, err := serialize(descriptor, false, false, true, fals
e, false) |
1132 if err != nil { | 1484 if err != nil { |
1133 t.Errorf("Serialization error for %s: %s", c.fileName, e
rr.Error()) | 1485 t.Errorf("Serialization error for %s: %s", c.fileName, e
rr.Error()) |
1134 continue | 1486 continue |
1135 } | 1487 } |
1136 | 1488 |
1137 if !reflect.DeepEqual(bytes, bytes2) { | 1489 if !reflect.DeepEqual(bytes, bytes2) { |
1138 t.Errorf("Inconsistent serialization for %s:\nbytes=%v\n
bytes2=%v\n", | 1490 t.Errorf("Inconsistent serialization for %s:\nbytes=%v\n
bytes2=%v\n", |
1139 c.fileName, bytes, bytes2) | 1491 c.fileName, bytes, bytes2) |
1140 continue | 1492 continue |
1141 } | 1493 } |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1208 parser.SetMetaDataOnlyMode(true) | 1560 parser.SetMetaDataOnlyMode(true) |
1209 parser.Parse() | 1561 parser.Parse() |
1210 if !parser.OK() { | 1562 if !parser.OK() { |
1211 t.Errorf("Parsing error for %s: %s", c.fileName, parser.
GetError().Error()) | 1563 t.Errorf("Parsing error for %s: %s", c.fileName, parser.
GetError().Error()) |
1212 continue | 1564 continue |
1213 } | 1565 } |
1214 if err := descriptor.Resolve(); err != nil { | 1566 if err := descriptor.Resolve(); err != nil { |
1215 t.Errorf("Resolve error for %s: %s", c.fileName, err.Err
or()) | 1567 t.Errorf("Resolve error for %s: %s", c.fileName, err.Err
or()) |
1216 continue | 1568 continue |
1217 } | 1569 } |
1218 » » if err := descriptor.ComputeEnumValueIntegers(); err != nil { | 1570 » » if err := descriptor.ComputeFinalData(); err != nil { |
1219 » » » t.Errorf("ComputeEnumValueIntegers error for %s: %s", c.
fileName, err.Error()) | 1571 » » » t.Errorf("ComputeFinalData error for %s: %s", c.fileName
, err.Error()) |
1220 » » » continue | |
1221 » » } | |
1222 » » if err := descriptor.ComputeDataForGenerators(); err != nil { | |
1223 » » » t.Errorf("ComputeDataForGenerators error for %s: %s", c.
fileName, err.Error()) | |
1224 continue | 1572 continue |
1225 } | 1573 } |
1226 | 1574 |
1227 // Serialize | 1575 // Serialize |
1228 » » bytes, _, err := serialize(descriptor, false, c.lineAndcolumnNum
bers, false, false) | 1576 » » bytes, _, err := serialize(descriptor, false, false, c.lineAndco
lumnNumbers, false, false) |
1229 if err != nil { | 1577 if err != nil { |
1230 t.Errorf("Serialization error for %s: %s", c.fileName, e
rr.Error()) | 1578 t.Errorf("Serialization error for %s: %s", c.fileName, e
rr.Error()) |
1231 continue | 1579 continue |
1232 } | 1580 } |
1233 | 1581 |
1234 // Deserialize | 1582 // Deserialize |
1235 decoder := bindings.NewDecoder(bytes, nil) | 1583 decoder := bindings.NewDecoder(bytes, nil) |
1236 fileGraph := mojom_files.MojomFileGraph{} | 1584 fileGraph := mojom_files.MojomFileGraph{} |
1237 fileGraph.Decode(decoder) | 1585 fileGraph.Decode(decoder) |
1238 | 1586 |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1487 // first argument. Thus here we are also testing that |i
mportingName| is in fact string | 1835 // first argument. Thus here we are also testing that |i
mportingName| is in fact string |
1488 // that was parsed from the .mojom file. | 1836 // that was parsed from the .mojom file. |
1489 mojomFileA.SetCanonicalImportName(c.importingName, mojom
FileB.CanonicalFileName) | 1837 mojomFileA.SetCanonicalImportName(c.importingName, mojom
FileB.CanonicalFileName) |
1490 } | 1838 } |
1491 | 1839 |
1492 // Resolve | 1840 // Resolve |
1493 if err := descriptor.Resolve(); err != nil { | 1841 if err := descriptor.Resolve(); err != nil { |
1494 t.Errorf("Resolve error for case %d: %s", i, err.Error()
) | 1842 t.Errorf("Resolve error for case %d: %s", i, err.Error()
) |
1495 continue | 1843 continue |
1496 } | 1844 } |
1497 » » if err := descriptor.ComputeEnumValueIntegers(); err != nil { | 1845 » » if err := descriptor.ComputeFinalData(); err != nil { |
1498 » » » t.Errorf("ComputeEnumValueIntegers error for case %d: %s
", i, err.Error()) | 1846 » » » t.Errorf("ComputeFinalData error for case %d: %s", i, er
r.Error()) |
1499 » » » continue | |
1500 » » } | |
1501 » » if err := descriptor.ComputeDataForGenerators(); err != nil { | |
1502 » » » t.Errorf("ComputeDataForGenerators error for case %d: %s
", i, err.Error()) | |
1503 continue | 1847 continue |
1504 } | 1848 } |
1505 | 1849 |
1506 // Serialize | 1850 // Serialize |
1507 » » bytes, _, err := serialize(descriptor, false, c.lineAndcolumnNum
bers, false, false) | 1851 » » bytes, _, err := serialize(descriptor, false, false, c.lineAndco
lumnNumbers, false, false) |
1508 if err != nil { | 1852 if err != nil { |
1509 t.Errorf("Serialization error for case %d: %s", i, err.E
rror()) | 1853 t.Errorf("Serialization error for case %d: %s", i, err.E
rror()) |
1510 continue | 1854 continue |
1511 } | 1855 } |
1512 | 1856 |
1513 // Deserialize | 1857 // Deserialize |
1514 decoder := bindings.NewDecoder(bytes, nil) | 1858 decoder := bindings.NewDecoder(bytes, nil) |
1515 fileGraph := mojom_files.MojomFileGraph{} | 1859 fileGraph := mojom_files.MojomFileGraph{} |
1516 fileGraph.Decode(decoder) | 1860 fileGraph.Decode(decoder) |
1517 | 1861 |
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2111 if !parserB.OK() { | 2455 if !parserB.OK() { |
2112 t.Errorf("Parsing error for %s: %s", fileNameB, parserB.
GetError().Error()) | 2456 t.Errorf("Parsing error for %s: %s", fileNameB, parserB.
GetError().Error()) |
2113 continue | 2457 continue |
2114 } | 2458 } |
2115 | 2459 |
2116 // Resolve | 2460 // Resolve |
2117 if err := descriptor.Resolve(); err != nil { | 2461 if err := descriptor.Resolve(); err != nil { |
2118 t.Errorf("Resolve error for case %d: %s", i, err.Error()
) | 2462 t.Errorf("Resolve error for case %d: %s", i, err.Error()
) |
2119 continue | 2463 continue |
2120 } | 2464 } |
2121 » » if err := descriptor.ComputeEnumValueIntegers(); err != nil { | 2465 » » if err := descriptor.ComputeFinalData(); err != nil { |
2122 » » » t.Errorf("ComputeEnumValueIntegers error for case %d: %s
", i, err.Error()) | 2466 » » » t.Errorf("ComputeFinalData error for case %d: %s", i, er
r.Error()) |
2123 » » » continue | |
2124 » » } | |
2125 » » if err := descriptor.ComputeDataForGenerators(); err != nil { | |
2126 » » » t.Errorf("ComputeDataForGenerators error for case %d: %s
", i, err.Error()) | |
2127 continue | 2467 continue |
2128 } | 2468 } |
2129 | 2469 |
2130 // Serialize | 2470 // Serialize |
2131 » » bytes, _, err := serialize(descriptor, false, false, true, true) | 2471 » » bytes, _, err := serialize(descriptor, false, false, false, true
, true) |
2132 if err != nil { | 2472 if err != nil { |
2133 t.Errorf("Serialization error for case %d: %s", i, err.E
rror()) | 2473 t.Errorf("Serialization error for case %d: %s", i, err.E
rror()) |
2134 continue | 2474 continue |
2135 } | 2475 } |
2136 | 2476 |
2137 // Deserialize | 2477 // Deserialize |
2138 decoder := bindings.NewDecoder(bytes, nil) | 2478 decoder := bindings.NewDecoder(bytes, nil) |
2139 fileGraph := mojom_files.MojomFileGraph{} | 2479 fileGraph := mojom_files.MojomFileGraph{} |
2140 fileGraph.Decode(decoder) | 2480 fileGraph.Decode(decoder) |
2141 | 2481 |
2142 // Deserialize RuntimeTypeInfo A | 2482 // Deserialize RuntimeTypeInfo A |
2143 runtimeTypeInfoA := deserializeRuntimeTypeInfo(*fileGraph.Files[
fileNameA].SerializedRuntimeTypeInfo) | 2483 runtimeTypeInfoA := deserializeRuntimeTypeInfo(*fileGraph.Files[
fileNameA].SerializedRuntimeTypeInfo) |
2144 | 2484 |
2145 // Deserialize RuntimeTypeInfo B | 2485 // Deserialize RuntimeTypeInfo B |
2146 runtimeTypeInfoB := deserializeRuntimeTypeInfo(*fileGraph.Files[
fileNameB].SerializedRuntimeTypeInfo) | 2486 runtimeTypeInfoB := deserializeRuntimeTypeInfo(*fileGraph.Files[
fileNameB].SerializedRuntimeTypeInfo) |
2147 | 2487 |
2148 // Compare A | 2488 // Compare A |
2149 if err := compareTwoGoObjects(c.expectedRuntimeTypeInfoA, &runti
meTypeInfoA); err != nil { | 2489 if err := compareTwoGoObjects(c.expectedRuntimeTypeInfoA, &runti
meTypeInfoA); err != nil { |
2150 t.Errorf("case %d A:\n%s", i, err.Error()) | 2490 t.Errorf("case %d A:\n%s", i, err.Error()) |
2151 } | 2491 } |
2152 | 2492 |
2153 // Compare B | 2493 // Compare B |
2154 if err := compareTwoGoObjects(c.expectedRuntimeTypeInfoB, &runti
meTypeInfoB); err != nil { | 2494 if err := compareTwoGoObjects(c.expectedRuntimeTypeInfoB, &runti
meTypeInfoB); err != nil { |
2155 t.Errorf("case %d B:\n%s", i, err.Error()) | 2495 t.Errorf("case %d B:\n%s", i, err.Error()) |
2156 } | 2496 } |
2157 | 2497 |
2158 // Test the parameter populateCompleteTypeSet. We set the final | 2498 // Test the parameter populateCompleteTypeSet. We set the final |
2159 // parameter to false. | 2499 // parameter to false. |
2160 » » bytes, _, err = serialize(descriptor, false, false, true, false) | 2500 » » bytes, _, err = serialize(descriptor, false, false, false, true,
false) |
2161 if err != nil { | 2501 if err != nil { |
2162 t.Errorf("Serialization error for case %d: %s", i, err.E
rror()) | 2502 t.Errorf("Serialization error for case %d: %s", i, err.E
rror()) |
2163 continue | 2503 continue |
2164 } | 2504 } |
2165 | 2505 |
2166 // Deserialize | 2506 // Deserialize |
2167 decoder = bindings.NewDecoder(bytes, nil) | 2507 decoder = bindings.NewDecoder(bytes, nil) |
2168 fileGraph = mojom_files.MojomFileGraph{} | 2508 fileGraph = mojom_files.MojomFileGraph{} |
2169 fileGraph.Decode(decoder) | 2509 fileGraph.Decode(decoder) |
2170 runtimeTypeInfoA = deserializeRuntimeTypeInfo(*fileGraph.Files[f
ileNameA].SerializedRuntimeTypeInfo) | 2510 runtimeTypeInfoA = deserializeRuntimeTypeInfo(*fileGraph.Files[f
ileNameA].SerializedRuntimeTypeInfo) |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2229 } | 2569 } |
2230 return fmt.Errorf("*****\nexpected=\n*****\n%q\n*****\na
ctual=\n*****\n%q\n*****\n"+ | 2570 return fmt.Errorf("*****\nexpected=\n*****\n%q\n*****\na
ctual=\n*****\n%q\n*****\n"+ |
2231 "match failed at position %d: expected=\n*****\n
%q\n******\nactual=\n*****\n%q\n******\n", | 2571 "match failed at position %d: expected=\n*****\n
%q\n******\nactual=\n*****\n%q\n******\n", |
2232 expectedString, actualString, diffPos, mismatchE
xpected, mismatchActual) | 2572 expectedString, actualString, diffPos, mismatchE
xpected, mismatchActual) |
2233 } else { | 2573 } else { |
2234 return fmt.Errorf("expected != actual but the two printe
d equal.") | 2574 return fmt.Errorf("expected != actual but the two printe
d equal.") |
2235 } | 2575 } |
2236 } | 2576 } |
2237 return nil | 2577 return nil |
2238 } | 2578 } |
OLD | NEW |