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

Side by Side Diff: mojom/mojom_parser/serialization/serialization_test.go

Issue 1823563002: Mojom frontend: Implement computeFieldOffsets(). (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Another comment and more tests. Created 4 years, 9 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 unified diff | Download patch
« no previous file with comments | « mojom/mojom_parser/mojom/user_defined_types.go ('k') | mojom/mojom_parser/utils/math_utils.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1156 matching lines...) Expand 10 before | Expand all | Expand 10 after
1167 array<int32>? z; 1167 array<int32>? z;
1168 1168
1169 [MinVersion = 2] 1169 [MinVersion = 2]
1170 array<int32>? w; 1170 array<int32>? w;
1171 };` 1171 };`
1172 1172
1173 test.addTestCase("", contents) 1173 test.addTestCase("", contents)
1174 1174
1175 test.expectedFile().DeclaredMojomObjects.Structs = &[]string{"TY PE_KEY:Foo"} 1175 test.expectedFile().DeclaredMojomObjects.Structs = &[]string{"TY PE_KEY:Foo"}
1176 1176
1177 // ResolvedTypes
1178
1179 // struct Foo
1180 test.expectedGraph().ResolvedTypes["TYPE_KEY:Foo"] = &mojom_type s.UserDefinedTypeStructType{mojom_types.MojomStruct{ 1177 test.expectedGraph().ResolvedTypes["TYPE_KEY:Foo"] = &mojom_type s.UserDefinedTypeStructType{mojom_types.MojomStruct{
1181 DeclData: test.newDeclData("Foo", "Foo"), 1178 DeclData: test.newDeclData("Foo", "Foo"),
1182 Fields: []mojom_types.StructField{ 1179 Fields: []mojom_types.StructField{
1183 // The fields are in ordinal order and the first two arguments to newShortDeclDataO() are 1180 // The fields are in ordinal order and the first two arguments to newShortDeclDataO() are
1184 // declarationOrder and declaredOrdinal. 1181 // declarationOrder and declaredOrdinal.
1185 // field x 1182 // field x
1186 { 1183 {
1187 DeclData: test.newShortDeclDataO(0, -1, "x"), 1184 DeclData: test.newShortDeclDataO(0, -1, "x"),
1188 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Int32}, 1185 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Int32},
1186 Offset: 0,
1189 }, 1187 },
1190 // field y 1188 // field y
1191 { 1189 {
1192 DeclData: test.newShortDeclDataO(1, -1, "y"), 1190 DeclData: test.newShortDeclDataO(1, -1, "y"),
1193 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Int32}, 1191 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Int32},
1192 Offset: 4,
1194 }, 1193 },
1195 // field z 1194 // field z
1196 { 1195 {
1197 DeclData: test.newShortDeclDataAO(2, - 1, "z", &[]mojom_types.Attribute{{"MinVersion", &mojom_types.LiteralValueInt8Val ue{1}}}), 1196 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}}}, 1197 Type: &mojom_types.TypeArrayType{m ojom_types.ArrayType{true, -1, &mojom_types.TypeSimpleType{mojom_types.SimpleTyp e_Int32}}},
1199 MinVersion: 1, 1198 MinVersion: 1,
1199 Offset: 8,
1200 }, 1200 },
1201 // field w 1201 // field w
1202 { 1202 {
1203 DeclData: test.newShortDeclDataAO(3, - 1, "w", &[]mojom_types.Attribute{{"MinVersion", &mojom_types.LiteralValueInt8Val ue{2}}}), 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}}}, 1204 Type: &mojom_types.TypeArrayType{m ojom_types.ArrayType{true, -1, &mojom_types.TypeSimpleType{mojom_types.SimpleTyp e_Int32}}},
1205 MinVersion: 2, 1205 MinVersion: 2,
1206 Offset: 16,
1206 }, 1207 },
1207 }, 1208 },
1208 VersionInfo: &[]mojom_types.StructVersion{ 1209 VersionInfo: &[]mojom_types.StructVersion{
1209 mojom_types.StructVersion{ 1210 mojom_types.StructVersion{
1210 VersionNumber: 0, 1211 VersionNumber: 0,
1211 NumFields: 2, 1212 NumFields: 2,
1212 » » » » » NumBytes: 0, 1213 » » » » » NumBytes: 16,
1213 }, 1214 },
1214 mojom_types.StructVersion{ 1215 mojom_types.StructVersion{
1215 VersionNumber: 1, 1216 VersionNumber: 1,
1216 NumFields: 3, 1217 NumFields: 3,
1217 » » » » » NumBytes: 0, 1218 » » » » » NumBytes: 24,
1218 }, 1219 },
1219 mojom_types.StructVersion{ 1220 mojom_types.StructVersion{
1220 VersionNumber: 2, 1221 VersionNumber: 2,
1221 NumFields: 4, 1222 NumFields: 4,
1222 » » » » » NumBytes: 0, 1223 » » » » » NumBytes: 32,
1223 }, 1224 },
1224 }, 1225 },
1225 }} 1226 }}
1226 1227
1227 test.endTestCase() 1228 test.endTestCase()
1228 } 1229 }
1229 1230
1230 //////////////////////////////////////////////////////////// 1231 ////////////////////////////////////////////////////////////
1231 // Test Case: Test struct field min versions: 1, 3 1232 // Test Case: Test struct field min versions: 1, 3
1232 //////////////////////////////////////////////////////////// 1233 ////////////////////////////////////////////////////////////
1233 { 1234 {
1234 contents := ` 1235 contents := `
1235 struct Foo{ 1236 struct Foo{
1236 int32 x; 1237 int32 x;
1237 int32 y; 1238 int32 y;
1238 1239
1239 [MinVersion = 1] 1240 [MinVersion = 1]
1240 array<int32>? z; 1241 array<int32>? z;
1241 1242
1242 [MinVersion = 3] 1243 [MinVersion = 3]
1243 array<int32>? w; 1244 array<int32>? w;
1244 };` 1245 };`
1245 1246
1246 test.addTestCase("", contents) 1247 test.addTestCase("", contents)
1247 1248
1248 test.expectedFile().DeclaredMojomObjects.Structs = &[]string{"TY PE_KEY:Foo"} 1249 test.expectedFile().DeclaredMojomObjects.Structs = &[]string{"TY PE_KEY:Foo"}
1249 1250
1250 // ResolvedTypes
1251
1252 // struct Foo
1253 test.expectedGraph().ResolvedTypes["TYPE_KEY:Foo"] = &mojom_type s.UserDefinedTypeStructType{mojom_types.MojomStruct{ 1251 test.expectedGraph().ResolvedTypes["TYPE_KEY:Foo"] = &mojom_type s.UserDefinedTypeStructType{mojom_types.MojomStruct{
1254 DeclData: test.newDeclData("Foo", "Foo"), 1252 DeclData: test.newDeclData("Foo", "Foo"),
1255 Fields: []mojom_types.StructField{ 1253 Fields: []mojom_types.StructField{
1256 // The fields are in ordinal order and the first two arguments to newShortDeclDataO() are 1254 // The fields are in ordinal order and the first two arguments to newShortDeclDataO() are
1257 // declarationOrder and declaredOrdinal. 1255 // declarationOrder and declaredOrdinal.
1258 // field x 1256 // field x
1259 { 1257 {
1260 DeclData: test.newShortDeclDataO(0, -1, "x"), 1258 DeclData: test.newShortDeclDataO(0, -1, "x"),
1261 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Int32}, 1259 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Int32},
1260 Offset: 0,
1262 }, 1261 },
1263 // field y 1262 // field y
1264 { 1263 {
1265 DeclData: test.newShortDeclDataO(1, -1, "y"), 1264 DeclData: test.newShortDeclDataO(1, -1, "y"),
1266 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Int32}, 1265 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Int32},
1266 Offset: 4,
1267 }, 1267 },
1268 // field z 1268 // field z
1269 { 1269 {
1270 DeclData: test.newShortDeclDataAO(2, - 1, "z", &[]mojom_types.Attribute{{"MinVersion", &mojom_types.LiteralValueInt8Val ue{1}}}), 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}}}, 1271 Type: &mojom_types.TypeArrayType{m ojom_types.ArrayType{true, -1, &mojom_types.TypeSimpleType{mojom_types.SimpleTyp e_Int32}}},
1272 MinVersion: 1, 1272 MinVersion: 1,
1273 Offset: 8,
1273 }, 1274 },
1274 // field w 1275 // field w
1275 { 1276 {
1276 DeclData: test.newShortDeclDataAO(3, - 1, "w", &[]mojom_types.Attribute{{"MinVersion", &mojom_types.LiteralValueInt8Val ue{3}}}), 1277 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 Type: &mojom_types.TypeArrayType{m ojom_types.ArrayType{true, -1, &mojom_types.TypeSimpleType{mojom_types.SimpleTyp e_Int32}}},
1278 MinVersion: 3, 1279 MinVersion: 3,
1280 Offset: 16,
1279 }, 1281 },
1280 }, 1282 },
1281 VersionInfo: &[]mojom_types.StructVersion{ 1283 VersionInfo: &[]mojom_types.StructVersion{
1282 mojom_types.StructVersion{ 1284 mojom_types.StructVersion{
1283 VersionNumber: 0, 1285 VersionNumber: 0,
1284 NumFields: 2, 1286 NumFields: 2,
1285 » » » » » NumBytes: 0, 1287 » » » » » NumBytes: 16,
1286 }, 1288 },
1287 mojom_types.StructVersion{ 1289 mojom_types.StructVersion{
1288 VersionNumber: 1, 1290 VersionNumber: 1,
1289 NumFields: 3, 1291 NumFields: 3,
1290 » » » » » NumBytes: 0, 1292 » » » » » NumBytes: 24,
1291 }, 1293 },
1292 mojom_types.StructVersion{ 1294 mojom_types.StructVersion{
1293 VersionNumber: 3, 1295 VersionNumber: 3,
1294 NumFields: 4, 1296 NumFields: 4,
1295 » » » » » NumBytes: 0, 1297 » » » » » NumBytes: 32,
1296 }, 1298 },
1297 }, 1299 },
1298 }} 1300 }}
1299 1301
1300 test.endTestCase() 1302 test.endTestCase()
1301 } 1303 }
1302 1304
1303 //////////////////////////////////////////////////////////// 1305 ////////////////////////////////////////////////////////////
1304 // Test Case: Test struct field min versions: 1, 1 1306 // Test Case: Test struct field min versions: 1, 1
1305 //////////////////////////////////////////////////////////// 1307 ////////////////////////////////////////////////////////////
1306 { 1308 {
1307 contents := ` 1309 contents := `
1308 struct Foo{ 1310 struct Foo{
1309 int32 x; 1311 int32 x;
1310 int32 y; 1312 int32 y;
1311 1313
1312 [MinVersion = 1] 1314 [MinVersion = 1]
1313 array<int32>? z; 1315 array<int32>? z;
1314 1316
1315 [MinVersion = 1] 1317 [MinVersion = 1]
1316 array<int32>? w; 1318 array<int32>? w;
1317 };` 1319 };`
1318 1320
1319 test.addTestCase("", contents) 1321 test.addTestCase("", contents)
1320 1322
1321 test.expectedFile().DeclaredMojomObjects.Structs = &[]string{"TY PE_KEY:Foo"} 1323 test.expectedFile().DeclaredMojomObjects.Structs = &[]string{"TY PE_KEY:Foo"}
1322 1324
1323 // ResolvedTypes
1324
1325 // struct Foo
1326 test.expectedGraph().ResolvedTypes["TYPE_KEY:Foo"] = &mojom_type s.UserDefinedTypeStructType{mojom_types.MojomStruct{ 1325 test.expectedGraph().ResolvedTypes["TYPE_KEY:Foo"] = &mojom_type s.UserDefinedTypeStructType{mojom_types.MojomStruct{
1327 DeclData: test.newDeclData("Foo", "Foo"), 1326 DeclData: test.newDeclData("Foo", "Foo"),
1328 Fields: []mojom_types.StructField{ 1327 Fields: []mojom_types.StructField{
1329 // The fields are in ordinal order and the first two arguments to newShortDeclDataO() are 1328 // The fields are in ordinal order and the first two arguments to newShortDeclDataO() are
1330 // declarationOrder and declaredOrdinal. 1329 // declarationOrder and declaredOrdinal.
1331 // field x 1330 // field x
1332 { 1331 {
1333 DeclData: test.newShortDeclDataO(0, -1, "x"), 1332 DeclData: test.newShortDeclDataO(0, -1, "x"),
1334 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Int32}, 1333 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Int32},
1334 Offset: 0,
1335 }, 1335 },
1336 // field y 1336 // field y
1337 { 1337 {
1338 DeclData: test.newShortDeclDataO(1, -1, "y"), 1338 DeclData: test.newShortDeclDataO(1, -1, "y"),
1339 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Int32}, 1339 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Int32},
1340 Offset: 4,
1340 }, 1341 },
1341 // field z 1342 // field z
1342 { 1343 {
1343 DeclData: test.newShortDeclDataAO(2, - 1, "z", &[]mojom_types.Attribute{{"MinVersion", &mojom_types.LiteralValueInt8Val ue{1}}}), 1344 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 Type: &mojom_types.TypeArrayType{m ojom_types.ArrayType{true, -1, &mojom_types.TypeSimpleType{mojom_types.SimpleTyp e_Int32}}},
1345 MinVersion: 1, 1346 MinVersion: 1,
1347 Offset: 8,
1346 }, 1348 },
1347 // field w 1349 // field w
1348 { 1350 {
1349 DeclData: test.newShortDeclDataAO(3, - 1, "w", &[]mojom_types.Attribute{{"MinVersion", &mojom_types.LiteralValueInt8Val ue{1}}}), 1351 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}}}, 1352 Type: &mojom_types.TypeArrayType{m ojom_types.ArrayType{true, -1, &mojom_types.TypeSimpleType{mojom_types.SimpleTyp e_Int32}}},
1351 MinVersion: 1, 1353 MinVersion: 1,
1354 Offset: 16,
1352 }, 1355 },
1353 }, 1356 },
1354 VersionInfo: &[]mojom_types.StructVersion{ 1357 VersionInfo: &[]mojom_types.StructVersion{
1355 mojom_types.StructVersion{ 1358 mojom_types.StructVersion{
1356 VersionNumber: 0, 1359 VersionNumber: 0,
1357 NumFields: 2, 1360 NumFields: 2,
1358 » » » » » NumBytes: 0, 1361 » » » » » NumBytes: 16,
1359 }, 1362 },
1360 mojom_types.StructVersion{ 1363 mojom_types.StructVersion{
1361 VersionNumber: 1, 1364 VersionNumber: 1,
1362 NumFields: 4, 1365 NumFields: 4,
1363 » » » » » NumBytes: 0, 1366 » » » » » NumBytes: 32,
1364 }, 1367 },
1365 }, 1368 },
1366 }} 1369 }}
1367 1370
1368 test.endTestCase() 1371 test.endTestCase()
1369 } 1372 }
1370 1373
1371 //////////////////////////////////////////////////////////// 1374 ////////////////////////////////////////////////////////////
1372 // Test Case: Test struct field min versions: 1,2 with specified ordinal s 1375 // Test Case: Test struct field min versions: 1,2 with specified ordinal s
1373 //////////////////////////////////////////////////////////// 1376 ////////////////////////////////////////////////////////////
1374 { 1377 {
1375 contents := ` 1378 contents := `
1376 struct Foo{ 1379 struct Foo{
1377 int32 y@1; 1380 int32 y@1;
1378 1381
1379 [MinVersion = 1] 1382 [MinVersion = 1]
1380 array<int32>? z@2; 1383 array<int32>? z@2;
1381 1384
1382 [MinVersion = 2] 1385 [MinVersion = 2]
1383 array<int32>? w@3; 1386 array<int32>? w@3;
1384 1387
1385 int32 x@0; 1388 int32 x@0;
1386 };` 1389 };`
1387 1390
1388 test.addTestCase("", contents) 1391 test.addTestCase("", contents)
1389 1392
1390 test.expectedFile().DeclaredMojomObjects.Structs = &[]string{"TY PE_KEY:Foo"} 1393 test.expectedFile().DeclaredMojomObjects.Structs = &[]string{"TY PE_KEY:Foo"}
1391 1394
1392 // ResolvedTypes
1393
1394 // struct Foo
1395 test.expectedGraph().ResolvedTypes["TYPE_KEY:Foo"] = &mojom_type s.UserDefinedTypeStructType{mojom_types.MojomStruct{ 1395 test.expectedGraph().ResolvedTypes["TYPE_KEY:Foo"] = &mojom_type s.UserDefinedTypeStructType{mojom_types.MojomStruct{
1396 DeclData: test.newDeclData("Foo", "Foo"), 1396 DeclData: test.newDeclData("Foo", "Foo"),
1397 Fields: []mojom_types.StructField{ 1397 Fields: []mojom_types.StructField{
1398 // The fields are in ordinal order and the first two arguments to newShortDeclDataO() are 1398 // The fields are in ordinal order and the first two arguments to newShortDeclDataO() are
1399 // declarationOrder and declaredOrdinal. 1399 // declarationOrder and declaredOrdinal.
1400 // field x 1400 // field x
1401 { 1401 {
1402 DeclData: test.newShortDeclDataO(3, 0, " x"), 1402 DeclData: test.newShortDeclDataO(3, 0, " x"),
1403 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Int32}, 1403 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Int32},
1404 Offset: 0,
1404 }, 1405 },
1405 // field y 1406 // field y
1406 { 1407 {
1407 DeclData: test.newShortDeclDataO(0, 1, " y"), 1408 DeclData: test.newShortDeclDataO(0, 1, " y"),
1408 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Int32}, 1409 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Int32},
1410 Offset: 4,
1409 }, 1411 },
1410 // field z 1412 // field z
1411 { 1413 {
1412 DeclData: test.newShortDeclDataAO(1, 2 , "z", &[]mojom_types.Attribute{{"MinVersion", &mojom_types.LiteralValueInt8Valu e{1}}}), 1414 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}}}, 1415 Type: &mojom_types.TypeArrayType{m ojom_types.ArrayType{true, -1, &mojom_types.TypeSimpleType{mojom_types.SimpleTyp e_Int32}}},
1414 MinVersion: 1, 1416 MinVersion: 1,
1417 Offset: 8,
1415 }, 1418 },
1416 // field w 1419 // field w
1417 { 1420 {
1418 DeclData: test.newShortDeclDataAO(2, 3 , "w", &[]mojom_types.Attribute{{"MinVersion", &mojom_types.LiteralValueInt8Valu e{2}}}), 1421 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}}}, 1422 Type: &mojom_types.TypeArrayType{m ojom_types.ArrayType{true, -1, &mojom_types.TypeSimpleType{mojom_types.SimpleTyp e_Int32}}},
1420 MinVersion: 2, 1423 MinVersion: 2,
1424 Offset: 16,
1421 }, 1425 },
1422 }, 1426 },
1423 VersionInfo: &[]mojom_types.StructVersion{ 1427 VersionInfo: &[]mojom_types.StructVersion{
1424 mojom_types.StructVersion{ 1428 mojom_types.StructVersion{
1425 VersionNumber: 0, 1429 VersionNumber: 0,
1426 NumFields: 2, 1430 NumFields: 2,
1427 » » » » » NumBytes: 0, 1431 » » » » » NumBytes: 16,
1428 }, 1432 },
1429 mojom_types.StructVersion{ 1433 mojom_types.StructVersion{
1430 VersionNumber: 1, 1434 VersionNumber: 1,
1431 NumFields: 3, 1435 NumFields: 3,
1432 » » » » » NumBytes: 0, 1436 » » » » » NumBytes: 24,
1433 }, 1437 },
1434 mojom_types.StructVersion{ 1438 mojom_types.StructVersion{
1435 VersionNumber: 2, 1439 VersionNumber: 2,
1436 NumFields: 4, 1440 NumFields: 4,
1437 NumBytes: 0, 1441 NumBytes: 32,
1438 }, 1442 },
1439 }, 1443 },
1440 }} 1444 }}
1441 1445
1442 test.endTestCase() 1446 test.endTestCase()
1447 }
1448
1449 ////////////////////////////////////////////////////////////
1450 // Test Case: 3 boolean fields
1451 ////////////////////////////////////////////////////////////
1452 {
1453 contents := `
1454 struct MyStruct1 {
1455 bool b1;
1456 bool b2;
1457 bool b3;
1458 };`
1459
1460 test.addTestCase("", contents)
1461
1462 test.expectedFile().DeclaredMojomObjects.Structs = &[]string{"TY PE_KEY:MyStruct1"}
1463
1464 test.expectedGraph().ResolvedTypes["TYPE_KEY:MyStruct1"] = &mojo m_types.UserDefinedTypeStructType{mojom_types.MojomStruct{
1465 DeclData: test.newDeclData("MyStruct1", "MyStruct1"),
1466 Fields: []mojom_types.StructField{
1467 // The fields are in ordinal order and the first two arguments to newShortDeclDataO() are
1468 // declarationOrder and declaredOrdinal.
1469 // field b1
1470 {
1471 DeclData: test.newShortDeclDataO(0, -1, "b1"),
1472 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Bool},
1473 Offset: 0,
1474 Bit: 0,
1475 },
1476 // field b2
1477 {
1478 DeclData: test.newShortDeclDataO(1, -1, "b2"),
1479 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Bool},
1480 Offset: 0,
1481 Bit: 1,
1482 },
1483 // field b3
1484 {
1485 DeclData: test.newShortDeclDataO(2, -1, "b3"),
1486 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Bool},
1487 Offset: 0,
1488 Bit: 2,
1489 },
1490 },
1491 VersionInfo: &[]mojom_types.StructVersion{
1492 mojom_types.StructVersion{
1493 VersionNumber: 0,
1494 NumFields: 3,
1495 NumBytes: 16,
1496 },
1497 },
1498 }}
1499
1500 test.endTestCase()
1501 }
1502
1503 ////////////////////////////////////////////////////////////
1504 // Test Case: int8 field + 2 boolean fields + int32field + 2 boolean fie lds
1505 ////////////////////////////////////////////////////////////
1506 {
1507 contents := `
1508 struct MyStruct1 {
1509 int8 x;
1510
1511 bool b1;
1512 bool b2;
1513
1514 int32 y;
1515
1516 bool b3;
1517 bool b4;
1518 };`
1519
1520 test.addTestCase("", contents)
1521
1522 test.expectedFile().DeclaredMojomObjects.Structs = &[]string{"TY PE_KEY:MyStruct1"}
1523
1524 test.expectedGraph().ResolvedTypes["TYPE_KEY:MyStruct1"] = &mojo m_types.UserDefinedTypeStructType{mojom_types.MojomStruct{
1525 DeclData: test.newDeclData("MyStruct1", "MyStruct1"),
1526 Fields: []mojom_types.StructField{
1527 // The fields are in ordinal order and the first two arguments to newShortDeclDataO() are
1528 // declarationOrder and declaredOrdinal.
1529 // field x
1530 {
1531 DeclData: test.newShortDeclDataO(0, -1, "x"),
1532 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Int8},
1533 Offset: 0,
1534 },
1535 // field b1
1536 {
1537 DeclData: test.newShortDeclDataO(1, -1, "b1"),
1538 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Bool},
1539 Offset: 1,
1540 Bit: 0,
1541 },
1542 // field b2
1543 {
1544 DeclData: test.newShortDeclDataO(2, -1, "b2"),
1545 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Bool},
1546 Offset: 1,
1547 Bit: 1,
1548 },
1549 // field y
1550 {
1551 DeclData: test.newShortDeclDataO(3, -1, "y"),
1552 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Int32},
1553 Offset: 4,
1554 },
1555 // field b3
1556 {
1557 DeclData: test.newShortDeclDataO(4, -1, "b3"),
1558 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Bool},
1559 Offset: 1,
1560 Bit: 2,
1561 },
1562 // field b4
1563 {
1564 DeclData: test.newShortDeclDataO(5, -1, "b4"),
1565 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Bool},
1566 Offset: 1,
1567 Bit: 3,
1568 },
1569 },
1570 VersionInfo: &[]mojom_types.StructVersion{
1571 mojom_types.StructVersion{
1572 VersionNumber: 0,
1573 NumFields: 6,
1574 NumBytes: 16,
1575 },
1576 },
1577 }}
1578
1579 test.endTestCase()
1580 }
1581
1582 ////////////////////////////////////////////////////////////
1583 // Test Case: int8 + int64 + bool + int32 + int8 + bool + int16
1584 ////////////////////////////////////////////////////////////
1585 {
1586 contents := `
1587 struct MyStruct1 {
1588 int8 x;
1589 int64 y;
1590 bool b1;
1591 int32 z;
1592 int8 w;
1593 bool b2;
1594 int16 r;
1595 };`
1596
1597 test.addTestCase("", contents)
1598
1599 test.expectedFile().DeclaredMojomObjects.Structs = &[]string{"TY PE_KEY:MyStruct1"}
1600
1601 test.expectedGraph().ResolvedTypes["TYPE_KEY:MyStruct1"] = &mojo m_types.UserDefinedTypeStructType{mojom_types.MojomStruct{
1602 DeclData: test.newDeclData("MyStruct1", "MyStruct1"),
1603 Fields: []mojom_types.StructField{
1604 // The fields are in ordinal order and the first two arguments to newShortDeclDataO() are
1605 // declarationOrder and declaredOrdinal.
1606 // field x
1607 {
1608 DeclData: test.newShortDeclDataO(0, -1, "x"),
1609 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Int8},
1610 Offset: 0,
1611 },
1612 // field y
1613 {
1614 DeclData: test.newShortDeclDataO(1, -1, "y"),
1615 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Int64},
1616 Offset: 8,
1617 },
1618 // field b1
1619 {
1620 DeclData: test.newShortDeclDataO(2, -1, "b1"),
1621 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Bool},
1622 Offset: 1,
1623 Bit: 0,
1624 },
1625 // field z
1626 {
1627 DeclData: test.newShortDeclDataO(3, -1, "z"),
1628 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Int32},
1629 Offset: 4,
1630 },
1631 // field w
1632 {
1633 DeclData: test.newShortDeclDataO(4, -1, "w"),
1634 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Int8},
1635 Offset: 2,
1636 },
1637 // field b2
1638 {
1639 DeclData: test.newShortDeclDataO(5, -1, "b2"),
1640 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Bool},
1641 Offset: 1,
1642 Bit: 1,
1643 },
1644 // field r
1645 {
1646 DeclData: test.newShortDeclDataO(6, -1, "r"),
1647 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Int16},
1648 Offset: 16,
1649 },
1650 },
1651 VersionInfo: &[]mojom_types.StructVersion{
1652 mojom_types.StructVersion{
1653 VersionNumber: 0,
1654 NumFields: 7,
1655 NumBytes: 32,
1656 },
1657 },
1658 }}
1659
1660 test.endTestCase()
1661 }
1662
1663 ////////////////////////////////////////////////////////////
1664 // Test Case: Specified ordinals with int8 + int64 + bool + int32 + int8 + bool + int16
1665 ////////////////////////////////////////////////////////////
1666 {
1667 contents := `
1668 struct MyStruct1 {
1669 int64 y@1;
1670 bool b1@2;
1671 int32 z@3;
1672 bool b2@5;
1673 int16 r@6;
1674 int8 x@0;
1675 int8 w@4;
1676 };`
1677
1678 test.addTestCase("", contents)
1679
1680 test.expectedFile().DeclaredMojomObjects.Structs = &[]string{"TY PE_KEY:MyStruct1"}
1681
1682 test.expectedGraph().ResolvedTypes["TYPE_KEY:MyStruct1"] = &mojo m_types.UserDefinedTypeStructType{mojom_types.MojomStruct{
1683 DeclData: test.newDeclData("MyStruct1", "MyStruct1"),
1684 Fields: []mojom_types.StructField{
1685 // The fields are in ordinal order and the first two arguments to newShortDeclDataO() are
1686 // declarationOrder and declaredOrdinal.
1687 // field x
1688 {
1689 DeclData: test.newShortDeclDataO(5, 0, " x"),
1690 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Int8},
1691 Offset: 0,
1692 },
1693 // field y
1694 {
1695 DeclData: test.newShortDeclDataO(0, 1, " y"),
1696 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Int64},
1697 Offset: 8,
1698 },
1699 // field b1
1700 {
1701 DeclData: test.newShortDeclDataO(1, 2, " b1"),
1702 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Bool},
1703 Offset: 1,
1704 Bit: 0,
1705 },
1706 // field z
1707 {
1708 DeclData: test.newShortDeclDataO(2, 3, " z"),
1709 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Int32},
1710 Offset: 4,
1711 },
1712 // field w
1713 {
1714 DeclData: test.newShortDeclDataO(6, 4, " w"),
1715 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Int8},
1716 Offset: 2,
1717 },
1718 // field b2
1719 {
1720 DeclData: test.newShortDeclDataO(3, 5, " b2"),
1721 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Bool},
1722 Offset: 1,
1723 Bit: 1,
1724 },
1725 // field r
1726 {
1727 DeclData: test.newShortDeclDataO(4, 6, " r"),
1728 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Int16},
1729 Offset: 16,
1730 },
1731 },
1732 VersionInfo: &[]mojom_types.StructVersion{
1733 mojom_types.StructVersion{
1734 VersionNumber: 0,
1735 NumFields: 7,
1736 NumBytes: 32,
1737 },
1738 },
1739 }}
1740
1741 test.endTestCase()
1742 }
1743
1744 ////////////////////////////////////////////////////////////
1745 // Test Case: Ten bools
1746 ////////////////////////////////////////////////////////////
1747 {
1748 contents := `
1749 struct MyStruct1 {
1750 bool b0;
1751 bool b1;
1752 bool b2;
1753 bool b3;
1754 bool b4;
1755 bool b5;
1756 bool b6;
1757 bool b7;
1758 bool b8;
1759 bool b9;
1760 };`
1761
1762 test.addTestCase("", contents)
1763
1764 test.expectedFile().DeclaredMojomObjects.Structs = &[]string{"TY PE_KEY:MyStruct1"}
1765
1766 test.expectedGraph().ResolvedTypes["TYPE_KEY:MyStruct1"] = &mojo m_types.UserDefinedTypeStructType{mojom_types.MojomStruct{
1767 DeclData: test.newDeclData("MyStruct1", "MyStruct1"),
1768 Fields: []mojom_types.StructField{
1769 // The fields are in ordinal order and the first two arguments to newShortDeclDataO() are
1770 // declarationOrder and declaredOrdinal.
1771 {
1772 DeclData: test.newShortDeclDataO(0, -1, "b0"),
1773 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Bool},
1774 Offset: 0,
1775 Bit: 0,
1776 },
1777 {
1778 DeclData: test.newShortDeclDataO(1, -1, "b1"),
1779 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Bool},
1780 Offset: 0,
1781 Bit: 1,
1782 },
1783 {
1784 DeclData: test.newShortDeclDataO(2, -1, "b2"),
1785 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Bool},
1786 Offset: 0,
1787 Bit: 2,
1788 },
1789 {
1790 DeclData: test.newShortDeclDataO(3, -1, "b3"),
1791 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Bool},
1792 Offset: 0,
1793 Bit: 3,
1794 },
1795 {
1796 DeclData: test.newShortDeclDataO(4, -1, "b4"),
1797 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Bool},
1798 Offset: 0,
1799 Bit: 4,
1800 },
1801 {
1802 DeclData: test.newShortDeclDataO(5, -1, "b5"),
1803 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Bool},
1804 Offset: 0,
1805 Bit: 5,
1806 },
1807 {
1808 DeclData: test.newShortDeclDataO(6, -1, "b6"),
1809 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Bool},
1810 Offset: 0,
1811 Bit: 6,
1812 },
1813 {
1814 DeclData: test.newShortDeclDataO(7, -1, "b7"),
1815 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Bool},
1816 Offset: 0,
1817 Bit: 7,
1818 },
1819 {
1820 DeclData: test.newShortDeclDataO(8, -1, "b8"),
1821 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Bool},
1822 Offset: 1,
1823 Bit: 0,
1824 },
1825 {
1826 DeclData: test.newShortDeclDataO(9, -1, "b9"),
1827 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Bool},
1828 Offset: 1,
1829 Bit: 1,
1830 },
1831 },
1832 VersionInfo: &[]mojom_types.StructVersion{
1833 mojom_types.StructVersion{
1834 VersionNumber: 0,
1835 NumFields: 10,
1836 NumBytes: 16,
1837 },
1838 },
1839 }}
1840
1841 test.endTestCase()
1842 }
1843
1844 ////////////////////////////////////////////////////////////
1845 // Test Case: int8 + union + struct + interface-request + int32 + interf ace
1846 //
1847 // x intfcreqst my_union------------------------------------- ---> my_struct------------> y--------> my_interface--------->
1848 // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
1849 //
1850 ////////////////////////////////////////////////////////////
1851 {
1852 contents := `
1853 union MyUnion1{};
1854
1855 interface MyInterface1{};
1856
1857 struct MyStruct1 {
1858 int8 x;
1859 MyUnion1 my_union;
1860 MyStruct1 my_struct;
1861 MyInterface1& my_interface_request;
1862 int32 y;
1863 MyInterface1 my_interface;
1864 };`
1865
1866 test.addTestCase("", contents)
1867
1868 test.expectedFile().DeclaredMojomObjects.Unions = &[]string{"TYP E_KEY:MyUnion1"}
1869 test.expectedFile().DeclaredMojomObjects.Interfaces = &[]string{ "TYPE_KEY:MyInterface1"}
1870 test.expectedFile().DeclaredMojomObjects.Structs = &[]string{"TY PE_KEY:MyStruct1"}
1871
1872 // MyStruct1
1873 test.expectedGraph().ResolvedTypes["TYPE_KEY:MyStruct1"] = &mojo m_types.UserDefinedTypeStructType{mojom_types.MojomStruct{
1874 DeclData: test.newDeclData("MyStruct1", "MyStruct1"),
1875 Fields: []mojom_types.StructField{
1876 // The fields are in ordinal order and the first two arguments to newShortDeclDataO() are
1877 // declarationOrder and declaredOrdinal.
1878 // field x
1879 {
1880 DeclData: test.newShortDeclDataO(0, -1, "x"),
1881 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Int8},
1882 Offset: 0,
1883 },
1884 // field my_union
1885 {
1886 DeclData: test.newShortDeclDataO(1, -1, "my_union"),
1887 Type: &mojom_types.TypeTypeReference{moj om_types.TypeReference{
1888 false, false, stringPointer("MyU nion1"), stringPointer("TYPE_KEY:MyUnion1")}},
1889 Offset: 8,
1890 },
1891 // field my_struct
1892 {
1893 DeclData: test.newShortDeclDataO(2, -1, "my_struct"),
1894 Type: &mojom_types.TypeTypeReference{moj om_types.TypeReference{
1895 false, false, stringPointer("MyS truct1"), stringPointer("TYPE_KEY:MyStruct1")}},
1896 Offset: 24,
1897 },
1898 // field my_interface_request
1899 {
1900 DeclData: test.newShortDeclDataO(3, -1, "my_interface_request"),
1901 Type: &mojom_types.TypeTypeReference{moj om_types.TypeReference{
1902 false, true, stringPointer("MyIn terface1"), stringPointer("TYPE_KEY:MyInterface1")}},
1903 Offset: 4,
1904 },
1905 // field y
1906 {
1907 DeclData: test.newShortDeclDataO(4, -1, "y"),
1908 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Int32},
1909 Offset: 32,
1910 },
1911 // field my_interface
1912 {
1913 DeclData: test.newShortDeclDataO(5, -1, "my_interface"),
1914 Type: &mojom_types.TypeTypeReference{moj om_types.TypeReference{
1915 false, false, stringPointer("MyI nterface1"), stringPointer("TYPE_KEY:MyInterface1")}},
1916 Offset: 36,
1917 },
1918 },
1919 VersionInfo: &[]mojom_types.StructVersion{
1920 mojom_types.StructVersion{
1921 VersionNumber: 0,
1922 NumFields: 6,
1923 NumBytes: 56,
1924 },
1925 },
1926 }}
1927
1928 // MyUnion1
1929 test.expectedGraph().ResolvedTypes["TYPE_KEY:MyUnion1"] = &mojom _types.UserDefinedTypeUnionType{mojom_types.MojomUnion{
1930 DeclData: test.newDeclData("MyUnion1", "MyUnion1"),
1931 Fields: []mojom_types.UnionField{},
1932 }}
1933
1934 // MyInterface1
1935 test.expectedGraph().ResolvedTypes["TYPE_KEY:MyInterface1"] = &m ojom_types.UserDefinedTypeInterfaceType{mojom_types.MojomInterface{
1936 DeclData: test.newDeclData("MyInterface1", "MyInterface1 "),
1937 Methods: map[uint32]mojom_types.MojomMethod{},
1938 }}
1939
1940 test.endTestCase()
1941 }
1942
1943 ////////////////////////////////////////////////////////////
1944 // Test Case: Multiple versions with int8 + union + struct + interface-r equest + handle + interface
1945 //
1946 // x intfcreqst my_union------------------------------------- ---> my_struct------------> y--------> my_interface--------->
1947 // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
1948 //
1949 ////////////////////////////////////////////////////////////
1950 {
1951 contents := `
1952 union MyUnion1{};
1953
1954 interface MyInterface1{};
1955
1956 struct MyStruct1 {
1957 int8 x;
1958 MyUnion1 my_union;
1959 MyStruct1 my_struct;
1960
1961 [MinVersion=1]
1962 MyInterface1&? my_interface_request;
1963
1964 [MinVersion=2]
1965 handle? y;
1966
1967 [MinVersion=2]
1968 MyInterface1? my_interface;
1969 };`
1970
1971 test.addTestCase("", contents)
1972
1973 test.expectedFile().DeclaredMojomObjects.Unions = &[]string{"TYP E_KEY:MyUnion1"}
1974 test.expectedFile().DeclaredMojomObjects.Interfaces = &[]string{ "TYPE_KEY:MyInterface1"}
1975 test.expectedFile().DeclaredMojomObjects.Structs = &[]string{"TY PE_KEY:MyStruct1"}
1976
1977 // MyStruct1
1978 test.expectedGraph().ResolvedTypes["TYPE_KEY:MyStruct1"] = &mojo m_types.UserDefinedTypeStructType{mojom_types.MojomStruct{
1979 DeclData: test.newDeclData("MyStruct1", "MyStruct1"),
1980 Fields: []mojom_types.StructField{
1981 // The fields are in ordinal order and the first two arguments to newShortDeclDataO() are
1982 // declarationOrder and declaredOrdinal.
1983 // field x
1984 {
1985 DeclData: test.newShortDeclDataO(0, -1, "x"),
1986 Type: &mojom_types.TypeSimpleType{mo jom_types.SimpleType_Int8},
1987 Offset: 0,
1988 },
1989 // field my_union
1990 {
1991 DeclData: test.newShortDeclDataO(1, -1, "my_union"),
1992 Type: &mojom_types.TypeTypeReference{moj om_types.TypeReference{
1993 false, false, stringPointer("MyU nion1"), stringPointer("TYPE_KEY:MyUnion1")}},
1994 Offset: 8,
1995 },
1996 // field my_struct
1997 {
1998 DeclData: test.newShortDeclDataO(2, -1, "my_struct"),
1999 Type: &mojom_types.TypeTypeReference{moj om_types.TypeReference{
2000 false, false, stringPointer("MyS truct1"), stringPointer("TYPE_KEY:MyStruct1")}},
2001 Offset: 24,
2002 },
2003 // field my_interface_request
2004 {
2005 DeclData: test.newShortDeclDataAO(3, -1, "my_interface_request", &[]mojom_types.Attribute{{"MinVersion", &mojom_types.Li teralValueInt8Value{1}}}),
2006 Type: &mojom_types.TypeTypeReference{moj om_types.TypeReference{
2007 true, true, stringPointer("MyInt erface1"), stringPointer("TYPE_KEY:MyInterface1")}},
2008 Offset: 4,
2009 MinVersion: 1,
2010 },
2011 // field y
2012 {
2013 DeclData: test.newShortDeclDataAO(4, - 1, "y", &[]mojom_types.Attribute{{"MinVersion", &mojom_types.LiteralValueInt8Val ue{2}}}),
2014 Type: &mojom_types.TypeHandleType{ mojom_types.HandleType{Nullable: true}},
2015 Offset: 32,
2016 MinVersion: 2,
2017 },
2018 // field my_interface
2019 {
2020 DeclData: test.newShortDeclDataAO(5, -1, "my_interface", &[]mojom_types.Attribute{{"MinVersion", &mojom_types.LiteralVal ueInt8Value{2}}}),
2021 Type: &mojom_types.TypeTypeReference{moj om_types.TypeReference{
2022 true, false, stringPointer("MyIn terface1"), stringPointer("TYPE_KEY:MyInterface1")}},
2023 Offset: 36,
2024 MinVersion: 2,
2025 },
2026 },
2027 VersionInfo: &[]mojom_types.StructVersion{
2028 mojom_types.StructVersion{
2029 VersionNumber: 0,
2030 NumFields: 3,
2031 NumBytes: 40,
2032 },
2033 mojom_types.StructVersion{
2034 VersionNumber: 1,
2035 NumFields: 4,
2036 NumBytes: 40,
2037 },
2038 mojom_types.StructVersion{
2039 VersionNumber: 2,
2040 NumFields: 6,
2041 NumBytes: 56,
2042 },
2043 },
2044 }}
2045
2046 // MyUnion1
2047 test.expectedGraph().ResolvedTypes["TYPE_KEY:MyUnion1"] = &mojom _types.UserDefinedTypeUnionType{mojom_types.MojomUnion{
2048 DeclData: test.newDeclData("MyUnion1", "MyUnion1"),
2049 Fields: []mojom_types.UnionField{},
2050 }}
2051
2052 // MyInterface1
2053 test.expectedGraph().ResolvedTypes["TYPE_KEY:MyInterface1"] = &m ojom_types.UserDefinedTypeInterfaceType{mojom_types.MojomInterface{
2054 DeclData: test.newDeclData("MyInterface1", "MyInterface1 "),
2055 Methods: map[uint32]mojom_types.MojomMethod{},
2056 }}
2057
2058 test.endTestCase()
1443 } 2059 }
1444 2060
1445 //////////////////////////////////////////////////////////// 2061 ////////////////////////////////////////////////////////////
1446 // Execute all of the test cases. 2062 // Execute all of the test cases.
1447 //////////////////////////////////////////////////////////// 2063 ////////////////////////////////////////////////////////////
1448 for _, c := range test.cases { 2064 for _, c := range test.cases {
1449 // Parse and resolve the mojom input. 2065 // Parse and resolve the mojom input.
1450 descriptor := mojom.NewMojomDescriptor() 2066 descriptor := mojom.NewMojomDescriptor()
1451 parser := parser.MakeParser(c.fileName, c.fileName, c.mojomConte nts, descriptor, nil) 2067 parser := parser.MakeParser(c.fileName, c.fileName, c.mojomConte nts, descriptor, nil)
1452 parser.Parse() 2068 parser.Parse()
(...skipping 1116 matching lines...) Expand 10 before | Expand all | Expand 10 after
2569 } 3185 }
2570 return fmt.Errorf("*****\nexpected=\n*****\n%q\n*****\na ctual=\n*****\n%q\n*****\n"+ 3186 return fmt.Errorf("*****\nexpected=\n*****\n%q\n*****\na ctual=\n*****\n%q\n*****\n"+
2571 "match failed at position %d: expected=\n*****\n %q\n******\nactual=\n*****\n%q\n******\n", 3187 "match failed at position %d: expected=\n*****\n %q\n******\nactual=\n*****\n%q\n******\n",
2572 expectedString, actualString, diffPos, mismatchE xpected, mismatchActual) 3188 expectedString, actualString, diffPos, mismatchE xpected, mismatchActual)
2573 } else { 3189 } else {
2574 return fmt.Errorf("expected != actual but the two printe d equal.") 3190 return fmt.Errorf("expected != actual but the two printe d equal.")
2575 } 3191 }
2576 } 3192 }
2577 return nil 3193 return nil
2578 } 3194 }
OLDNEW
« no previous file with comments | « mojom/mojom_parser/mojom/user_defined_types.go ('k') | mojom/mojom_parser/utils/math_utils.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698