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

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

Issue 1717583003: Mojom compiler: Move RuntimeTypeInfo from mojom_files.mojom to mojom_types.mojom. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: New sha1s Created 4 years, 10 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/serialization/serialization.go ('k') | no next file » | 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 "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 1251 matching lines...) Expand 10 before | Expand all | Expand 10 after
1262 } 1262 }
1263 1263
1264 //////////////////////////////////////////// 1264 ////////////////////////////////////////////
1265 /// Serialized Runtime Type Info Tests 1265 /// Serialized Runtime Type Info Tests
1266 /////////////////////////////////////////// 1266 ///////////////////////////////////////////
1267 1267
1268 type runtimeTypeInfoTestCase struct { 1268 type runtimeTypeInfoTestCase struct {
1269 // The contents of the two files 1269 // The contents of the two files
1270 mojomContentsA string 1270 mojomContentsA string
1271 mojomContentsB string 1271 mojomContentsB string
1272 » expectedRuntimeTypeInfoA *mojom_files.RuntimeTypeInfo 1272 » expectedRuntimeTypeInfoA *mojom_types.RuntimeTypeInfo
1273 » expectedRuntimeTypeInfoB *mojom_files.RuntimeTypeInfo 1273 » expectedRuntimeTypeInfoB *mojom_types.RuntimeTypeInfo
1274 } 1274 }
1275 1275
1276 type runtimeTypeInfoTest struct { 1276 type runtimeTypeInfoTest struct {
1277 cases []runtimeTypeInfoTestCase 1277 cases []runtimeTypeInfoTestCase
1278 testCaseNum int 1278 testCaseNum int
1279 } 1279 }
1280 1280
1281 func (t *runtimeTypeInfoTest) expectedRuntimeTypeInfoA() *mojom_files.RuntimeTyp eInfo { 1281 func (t *runtimeTypeInfoTest) expectedRuntimeTypeInfoA() *mojom_types.RuntimeTyp eInfo {
1282 return t.cases[t.testCaseNum].expectedRuntimeTypeInfoA 1282 return t.cases[t.testCaseNum].expectedRuntimeTypeInfoA
1283 } 1283 }
1284 1284
1285 func (t *runtimeTypeInfoTest) expectedRuntimeTypeInfoB() *mojom_files.RuntimeTyp eInfo { 1285 func (t *runtimeTypeInfoTest) expectedRuntimeTypeInfoB() *mojom_types.RuntimeTyp eInfo {
1286 return t.cases[t.testCaseNum].expectedRuntimeTypeInfoB 1286 return t.cases[t.testCaseNum].expectedRuntimeTypeInfoB
1287 } 1287 }
1288 1288
1289 func (test *runtimeTypeInfoTest) addTestCase(contentsA, contentsB string) { 1289 func (test *runtimeTypeInfoTest) addTestCase(contentsA, contentsB string) {
1290 » test.cases = append(test.cases, runtimeTypeInfoTestCase{contentsA, conte ntsB, new(mojom_files.RuntimeTypeInfo), new(mojom_files.RuntimeTypeInfo)}) 1290 » test.cases = append(test.cases, runtimeTypeInfoTestCase{contentsA, conte ntsB, new(mojom_types.RuntimeTypeInfo), new(mojom_types.RuntimeTypeInfo)})
1291 » test.expectedRuntimeTypeInfoA().ServicesByName = make(map[string]mojom_f iles.ServiceTypeInfo) 1291 » test.expectedRuntimeTypeInfoA().ServicesByName = make(map[string]mojom_t ypes.ServiceTypeInfo)
1292 test.expectedRuntimeTypeInfoA().TypeMap = make(map[string]mojom_types.Us erDefinedType) 1292 test.expectedRuntimeTypeInfoA().TypeMap = make(map[string]mojom_types.Us erDefinedType)
1293 » test.expectedRuntimeTypeInfoB().ServicesByName = make(map[string]mojom_f iles.ServiceTypeInfo) 1293 » test.expectedRuntimeTypeInfoB().ServicesByName = make(map[string]mojom_t ypes.ServiceTypeInfo)
1294 test.expectedRuntimeTypeInfoB().TypeMap = make(map[string]mojom_types.Us erDefinedType) 1294 test.expectedRuntimeTypeInfoB().TypeMap = make(map[string]mojom_types.Us erDefinedType)
1295 } 1295 }
1296 1296
1297 func (test *runtimeTypeInfoTest) fileNameA() string { 1297 func (test *runtimeTypeInfoTest) fileNameA() string {
1298 return fmt.Sprintf("file%dA", test.testCaseNum) 1298 return fmt.Sprintf("file%dA", test.testCaseNum)
1299 } 1299 }
1300 1300
1301 func (test *runtimeTypeInfoTest) fileNameB() string { 1301 func (test *runtimeTypeInfoTest) fileNameB() string {
1302 return fmt.Sprintf("file%dB", test.testCaseNum) 1302 return fmt.Sprintf("file%dB", test.testCaseNum)
1303 } 1303 }
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
1469 }; 1469 };
1470 1470
1471 interface InterfaceB { 1471 interface InterfaceB {
1472 DoIt(a.b.c.FooA x) => (FooB? y); 1472 DoIt(a.b.c.FooA x) => (FooB? y);
1473 }; 1473 };
1474 1474
1475 ` 1475 `
1476 test.addTestCase(contentsA, contentsB) 1476 test.addTestCase(contentsA, contentsB)
1477 1477
1478 // ServicesByName for file A 1478 // ServicesByName for file A
1479 » » test.expectedRuntimeTypeInfoA().ServicesByName["AwesomeService"] = mojom_files.ServiceTypeInfo{ 1479 » » test.expectedRuntimeTypeInfoA().ServicesByName["AwesomeService"] = mojom_types.ServiceTypeInfo{
1480 TopLevelInterface: "TYPE_KEY:a.b.c.InterfaceA", 1480 TopLevelInterface: "TYPE_KEY:a.b.c.InterfaceA",
1481 CompleteTypeSet: []string{"TYPE_KEY:a.b.c.FooA", "TYPE _KEY:a.b.c.InterfaceA", "TYPE_KEY:b.c.d.FooB"}, 1481 CompleteTypeSet: []string{"TYPE_KEY:a.b.c.FooA", "TYPE _KEY:a.b.c.InterfaceA", "TYPE_KEY:b.c.d.FooB"},
1482 } 1482 }
1483 1483
1484 // TypeMap for file A 1484 // TypeMap for file A
1485 1485
1486 // FooA 1486 // FooA
1487 test.expectedRuntimeTypeInfoA().TypeMap["TYPE_KEY:a.b.c.FooA"] = &mojom_types.UserDefinedTypeStructType{mojom_types.MojomStruct{ 1487 test.expectedRuntimeTypeInfoA().TypeMap["TYPE_KEY:a.b.c.FooA"] = &mojom_types.UserDefinedTypeStructType{mojom_types.MojomStruct{
1488 DeclData: newDeclData(test.fileNameA(), "FooA", "a.b.c.F ooA"), 1488 DeclData: newDeclData(test.fileNameA(), "FooA", "a.b.c.F ooA"),
1489 Fields: []mojom_types.StructField{}}} 1489 Fields: []mojom_types.StructField{}}}
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1585 1585
1586 [ServiceName = 42] 1586 [ServiceName = 42]
1587 interface InterfaceB { 1587 interface InterfaceB {
1588 DoIt(a.b.c.FooA x) => (FooB? y); 1588 DoIt(a.b.c.FooA x) => (FooB? y);
1589 }; 1589 };
1590 1590
1591 ` 1591 `
1592 test.addTestCase(contentsA, contentsB) 1592 test.addTestCase(contentsA, contentsB)
1593 1593
1594 // ServicesByName for file A 1594 // ServicesByName for file A
1595 » » test.expectedRuntimeTypeInfoA().ServicesByName["AwesomeService"] = mojom_files.ServiceTypeInfo{ 1595 » » test.expectedRuntimeTypeInfoA().ServicesByName["AwesomeService"] = mojom_types.ServiceTypeInfo{
1596 TopLevelInterface: "TYPE_KEY:a.b.c.InterfaceA", 1596 TopLevelInterface: "TYPE_KEY:a.b.c.InterfaceA",
1597 CompleteTypeSet: []string{"TYPE_KEY:a.b.c.FooA", "TYPE _KEY:a.b.c.InterfaceA", "TYPE_KEY:b.c.d.FooB"}, 1597 CompleteTypeSet: []string{"TYPE_KEY:a.b.c.FooA", "TYPE _KEY:a.b.c.InterfaceA", "TYPE_KEY:b.c.d.FooB"},
1598 } 1598 }
1599 1599
1600 // TypeMap for file A 1600 // TypeMap for file A
1601 1601
1602 // FooA 1602 // FooA
1603 test.expectedRuntimeTypeInfoA().TypeMap["TYPE_KEY:a.b.c.FooA"] = &mojom_types.UserDefinedTypeStructType{mojom_types.MojomStruct{ 1603 test.expectedRuntimeTypeInfoA().TypeMap["TYPE_KEY:a.b.c.FooA"] = &mojom_types.UserDefinedTypeStructType{mojom_types.MojomStruct{
1604 DeclData: newDeclData(test.fileNameA(), "FooA", "a.b.c.F ooA"), 1604 DeclData: newDeclData(test.fileNameA(), "FooA", "a.b.c.F ooA"),
1605 Fields: []mojom_types.StructField{}}} 1605 Fields: []mojom_types.StructField{}}}
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
1710 }; 1710 };
1711 1711
1712 interface InterfaceB { 1712 interface InterfaceB {
1713 DoIt(a.b.c.FooA x) => (FooB? y, Enum2 z); 1713 DoIt(a.b.c.FooA x) => (FooB? y, Enum2 z);
1714 }; 1714 };
1715 1715
1716 ` 1716 `
1717 test.addTestCase(contentsA, contentsB) 1717 test.addTestCase(contentsA, contentsB)
1718 1718
1719 // ServicesByName for file A 1719 // ServicesByName for file A
1720 » » test.expectedRuntimeTypeInfoA().ServicesByName["AwesomeService"] = mojom_files.ServiceTypeInfo{ 1720 » » test.expectedRuntimeTypeInfoA().ServicesByName["AwesomeService"] = mojom_types.ServiceTypeInfo{
1721 TopLevelInterface: "TYPE_KEY:a.b.c.InterfaceA", 1721 TopLevelInterface: "TYPE_KEY:a.b.c.InterfaceA",
1722 CompleteTypeSet: []string{"TYPE_KEY:a.b.c.FooA", "TYPE _KEY:a.b.c.InterfaceA", "TYPE_KEY:b.c.d.Enum1", "TYPE_KEY:b.c.d.FooB"}, 1722 CompleteTypeSet: []string{"TYPE_KEY:a.b.c.FooA", "TYPE _KEY:a.b.c.InterfaceA", "TYPE_KEY:b.c.d.Enum1", "TYPE_KEY:b.c.d.FooB"},
1723 } 1723 }
1724 1724
1725 // TypeMap for file A 1725 // TypeMap for file A
1726 1726
1727 // FooA 1727 // FooA
1728 test.expectedRuntimeTypeInfoA().TypeMap["TYPE_KEY:a.b.c.FooA"] = &mojom_types.UserDefinedTypeStructType{mojom_types.MojomStruct{ 1728 test.expectedRuntimeTypeInfoA().TypeMap["TYPE_KEY:a.b.c.FooA"] = &mojom_types.UserDefinedTypeStructType{mojom_types.MojomStruct{
1729 DeclData: newDeclData(test.fileNameA(), "FooA", "a.b.c.F ooA"), 1729 DeclData: newDeclData(test.fileNameA(), "FooA", "a.b.c.F ooA"),
1730 Fields: []mojom_types.StructField{}}} 1730 Fields: []mojom_types.StructField{}}}
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1872 continue 1872 continue
1873 } 1873 }
1874 1874
1875 // Deserialize 1875 // Deserialize
1876 decoder := bindings.NewDecoder(bytes, nil) 1876 decoder := bindings.NewDecoder(bytes, nil)
1877 fileGraph := mojom_files.MojomFileGraph{} 1877 fileGraph := mojom_files.MojomFileGraph{}
1878 fileGraph.Decode(decoder) 1878 fileGraph.Decode(decoder)
1879 1879
1880 // Deserialize RuntimeTypeInfo A 1880 // Deserialize RuntimeTypeInfo A
1881 decoder = bindings.NewDecoder(*fileGraph.Files[fileNameA].Serial izedRuntimeTypeInfo, nil) 1881 decoder = bindings.NewDecoder(*fileGraph.Files[fileNameA].Serial izedRuntimeTypeInfo, nil)
1882 » » runtimeTypeInfoA := mojom_files.RuntimeTypeInfo{} 1882 » » runtimeTypeInfoA := mojom_types.RuntimeTypeInfo{}
1883 runtimeTypeInfoA.Decode(decoder) 1883 runtimeTypeInfoA.Decode(decoder)
1884 1884
1885 // Deserialize RuntimeTypeInfo B 1885 // Deserialize RuntimeTypeInfo B
1886 decoder = bindings.NewDecoder(*fileGraph.Files[fileNameB].Serial izedRuntimeTypeInfo, nil) 1886 decoder = bindings.NewDecoder(*fileGraph.Files[fileNameB].Serial izedRuntimeTypeInfo, nil)
1887 » » runtimeTypeInfoB := mojom_files.RuntimeTypeInfo{} 1887 » » runtimeTypeInfoB := mojom_types.RuntimeTypeInfo{}
1888 runtimeTypeInfoB.Decode(decoder) 1888 runtimeTypeInfoB.Decode(decoder)
1889 1889
1890 // Compare A 1890 // Compare A
1891 if err := compareTwoGoObjects(c.expectedRuntimeTypeInfoA, &runti meTypeInfoA); err != nil { 1891 if err := compareTwoGoObjects(c.expectedRuntimeTypeInfoA, &runti meTypeInfoA); err != nil {
1892 t.Errorf("case %d A:\n%s", i, err.Error()) 1892 t.Errorf("case %d A:\n%s", i, err.Error())
1893 } 1893 }
1894 1894
1895 // Compare B 1895 // Compare B
1896 if err := compareTwoGoObjects(c.expectedRuntimeTypeInfoB, &runti meTypeInfoB); err != nil { 1896 if err := compareTwoGoObjects(c.expectedRuntimeTypeInfoB, &runti meTypeInfoB); err != nil {
1897 t.Errorf("case %d B:\n%s", i, err.Error()) 1897 t.Errorf("case %d B:\n%s", i, err.Error())
(...skipping 29 matching lines...) Expand all
1927 } 1927 }
1928 return fmt.Errorf("*****\nexpected=\n*****\n%q\n*****\na ctual=\n*****\n%q\n*****\n"+ 1928 return fmt.Errorf("*****\nexpected=\n*****\n%q\n*****\na ctual=\n*****\n%q\n*****\n"+
1929 "match failed at position %d: expected=\n*****\n %q\n******\nactual=\n*****\n%q\n******\n", 1929 "match failed at position %d: expected=\n*****\n %q\n******\nactual=\n*****\n%q\n******\n",
1930 expectedString, actualString, diffPos, mismatchE xpected, mismatchActual) 1930 expectedString, actualString, diffPos, mismatchE xpected, mismatchActual)
1931 } else { 1931 } else {
1932 return fmt.Errorf("expected != actual but the two printe d equal.") 1932 return fmt.Errorf("expected != actual but the two printe d equal.")
1933 } 1933 }
1934 } 1934 }
1935 return nil 1935 return nil
1936 } 1936 }
OLDNEW
« no previous file with comments | « mojom/mojom_parser/serialization/serialization.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698