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

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

Issue 1786543002: Mojom parser: Stop populating the complete_typeset field. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: 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/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 "bytes" 8 "bytes"
9 "compress/gzip" 9 "compress/gzip"
10 "encoding/base64" 10 "encoding/base64"
(...skipping 989 matching lines...) Expand 10 before | Expand all | Expand 10 after
1000 // Simulate setting the canonical file name for the imported fil es. In real operation 1000 // Simulate setting the canonical file name for the imported fil es. In real operation
1001 // this step is done in parser_driver.go when each of the import ed files are parsed. 1001 // this step is done in parser_driver.go when each of the import ed files are parsed.
1002 mojomFile := parser.GetMojomFile() 1002 mojomFile := parser.GetMojomFile()
1003 if mojomFile.Imports != nil { 1003 if mojomFile.Imports != nil {
1004 for _, imp := range mojomFile.Imports { 1004 for _, imp := range mojomFile.Imports {
1005 imp.CanonicalFileName = fmt.Sprintf("%s.canonica l", imp.SpecifiedName) 1005 imp.CanonicalFileName = fmt.Sprintf("%s.canonica l", imp.SpecifiedName)
1006 } 1006 }
1007 } 1007 }
1008 1008
1009 // Serialize 1009 // Serialize
1010 » » bytes, _, err := serialize(descriptor, false, c.lineAndcolumnNum bers, false) 1010 » » bytes, _, err := serialize(descriptor, false, c.lineAndcolumnNum bers, false, false)
1011 if err != nil { 1011 if err != nil {
1012 t.Errorf("Serialization error for %s: %s", c.fileName, e rr.Error()) 1012 t.Errorf("Serialization error for %s: %s", c.fileName, e rr.Error())
1013 continue 1013 continue
1014 } 1014 }
1015 1015
1016 // Serialize again and check for consistency. 1016 // Serialize again and check for consistency.
1017 » » bytes2, _, err := serialize(descriptor, false, c.lineAndcolumnNu mbers, false) 1017 » » bytes2, _, err := serialize(descriptor, false, c.lineAndcolumnNu mbers, false, false)
1018 if err != nil { 1018 if err != nil {
1019 t.Errorf("Serialization error for %s: %s", c.fileName, e rr.Error()) 1019 t.Errorf("Serialization error for %s: %s", c.fileName, e rr.Error())
1020 continue 1020 continue
1021 } 1021 }
1022 1022
1023 if !reflect.DeepEqual(bytes, bytes2) { 1023 if !reflect.DeepEqual(bytes, bytes2) {
1024 t.Errorf("Inconsistent serialization for %s:\nbytes=%v\n bytes2=%v\n", 1024 t.Errorf("Inconsistent serialization for %s:\nbytes=%v\n bytes2=%v\n",
1025 c.fileName, bytes, bytes2) 1025 c.fileName, bytes, bytes2)
1026 continue 1026 continue
1027 } 1027 }
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1104 if err := descriptor.ComputeEnumValueIntegers(); err != nil { 1104 if err := descriptor.ComputeEnumValueIntegers(); err != nil {
1105 t.Errorf("ComputeEnumValueIntegers error for %s: %s", c. fileName, err.Error()) 1105 t.Errorf("ComputeEnumValueIntegers error for %s: %s", c. fileName, err.Error())
1106 continue 1106 continue
1107 } 1107 }
1108 if err := descriptor.ComputeDataForGenerators(); err != nil { 1108 if err := descriptor.ComputeDataForGenerators(); err != nil {
1109 t.Errorf("ComputeDataForGenerators error for %s: %s", c. fileName, err.Error()) 1109 t.Errorf("ComputeDataForGenerators error for %s: %s", c. fileName, err.Error())
1110 continue 1110 continue
1111 } 1111 }
1112 1112
1113 // Serialize 1113 // Serialize
1114 » » bytes, _, err := serialize(descriptor, false, c.lineAndcolumnNum bers, false) 1114 » » bytes, _, err := serialize(descriptor, false, c.lineAndcolumnNum bers, false, false)
1115 if err != nil { 1115 if err != nil {
1116 t.Errorf("Serialization error for %s: %s", c.fileName, e rr.Error()) 1116 t.Errorf("Serialization error for %s: %s", c.fileName, e rr.Error())
1117 continue 1117 continue
1118 } 1118 }
1119 1119
1120 // Deserialize 1120 // Deserialize
1121 decoder := bindings.NewDecoder(bytes, nil) 1121 decoder := bindings.NewDecoder(bytes, nil)
1122 fileGraph := mojom_files.MojomFileGraph{} 1122 fileGraph := mojom_files.MojomFileGraph{}
1123 fileGraph.Decode(decoder) 1123 fileGraph.Decode(decoder)
1124 1124
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
1383 if err := descriptor.ComputeEnumValueIntegers(); err != nil { 1383 if err := descriptor.ComputeEnumValueIntegers(); err != nil {
1384 t.Errorf("ComputeEnumValueIntegers error for case %d: %s ", i, err.Error()) 1384 t.Errorf("ComputeEnumValueIntegers error for case %d: %s ", i, err.Error())
1385 continue 1385 continue
1386 } 1386 }
1387 if err := descriptor.ComputeDataForGenerators(); err != nil { 1387 if err := descriptor.ComputeDataForGenerators(); err != nil {
1388 t.Errorf("ComputeDataForGenerators error for case %d: %s ", i, err.Error()) 1388 t.Errorf("ComputeDataForGenerators error for case %d: %s ", i, err.Error())
1389 continue 1389 continue
1390 } 1390 }
1391 1391
1392 // Serialize 1392 // Serialize
1393 » » bytes, _, err := serialize(descriptor, false, c.lineAndcolumnNum bers, false) 1393 » » bytes, _, err := serialize(descriptor, false, c.lineAndcolumnNum bers, false, false)
1394 if err != nil { 1394 if err != nil {
1395 t.Errorf("Serialization error for case %d: %s", i, err.E rror()) 1395 t.Errorf("Serialization error for case %d: %s", i, err.E rror())
1396 continue 1396 continue
1397 } 1397 }
1398 1398
1399 // Deserialize 1399 // Deserialize
1400 decoder := bindings.NewDecoder(bytes, nil) 1400 decoder := bindings.NewDecoder(bytes, nil)
1401 fileGraph := mojom_files.MojomFileGraph{} 1401 fileGraph := mojom_files.MojomFileGraph{}
1402 fileGraph.Decode(decoder) 1402 fileGraph.Decode(decoder)
1403 1403
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after
2007 if err := descriptor.ComputeEnumValueIntegers(); err != nil { 2007 if err := descriptor.ComputeEnumValueIntegers(); err != nil {
2008 t.Errorf("ComputeEnumValueIntegers error for case %d: %s ", i, err.Error()) 2008 t.Errorf("ComputeEnumValueIntegers error for case %d: %s ", i, err.Error())
2009 continue 2009 continue
2010 } 2010 }
2011 if err := descriptor.ComputeDataForGenerators(); err != nil { 2011 if err := descriptor.ComputeDataForGenerators(); err != nil {
2012 t.Errorf("ComputeDataForGenerators error for case %d: %s ", i, err.Error()) 2012 t.Errorf("ComputeDataForGenerators error for case %d: %s ", i, err.Error())
2013 continue 2013 continue
2014 } 2014 }
2015 2015
2016 // Serialize 2016 // Serialize
2017 » » bytes, _, err := serialize(descriptor, false, false, true) 2017 » » bytes, _, err := serialize(descriptor, false, false, true, true)
2018 if err != nil { 2018 if err != nil {
2019 t.Errorf("Serialization error for case %d: %s", i, err.E rror()) 2019 t.Errorf("Serialization error for case %d: %s", i, err.E rror())
2020 continue 2020 continue
2021 } 2021 }
2022 2022
2023 // Deserialize 2023 // Deserialize
2024 decoder := bindings.NewDecoder(bytes, nil) 2024 decoder := bindings.NewDecoder(bytes, nil)
2025 fileGraph := mojom_files.MojomFileGraph{} 2025 fileGraph := mojom_files.MojomFileGraph{}
2026 fileGraph.Decode(decoder) 2026 fileGraph.Decode(decoder)
2027 2027
2028 // Deserialize RuntimeTypeInfo A 2028 // Deserialize RuntimeTypeInfo A
2029 runtimeTypeInfoA := deserializeRuntimeTypeInfo(*fileGraph.Files[ fileNameA].SerializedRuntimeTypeInfo) 2029 runtimeTypeInfoA := deserializeRuntimeTypeInfo(*fileGraph.Files[ fileNameA].SerializedRuntimeTypeInfo)
2030 2030
2031 // Deserialize RuntimeTypeInfo B 2031 // Deserialize RuntimeTypeInfo B
2032 runtimeTypeInfoB := deserializeRuntimeTypeInfo(*fileGraph.Files[ fileNameB].SerializedRuntimeTypeInfo) 2032 runtimeTypeInfoB := deserializeRuntimeTypeInfo(*fileGraph.Files[ fileNameB].SerializedRuntimeTypeInfo)
2033 2033
2034 // Compare A 2034 // Compare A
2035 if err := compareTwoGoObjects(c.expectedRuntimeTypeInfoA, &runti meTypeInfoA); err != nil { 2035 if err := compareTwoGoObjects(c.expectedRuntimeTypeInfoA, &runti meTypeInfoA); err != nil {
2036 t.Errorf("case %d A:\n%s", i, err.Error()) 2036 t.Errorf("case %d A:\n%s", i, err.Error())
2037 } 2037 }
2038 2038
2039 // Compare B 2039 // Compare B
2040 if err := compareTwoGoObjects(c.expectedRuntimeTypeInfoB, &runti meTypeInfoB); err != nil { 2040 if err := compareTwoGoObjects(c.expectedRuntimeTypeInfoB, &runti meTypeInfoB); err != nil {
2041 t.Errorf("case %d B:\n%s", i, err.Error()) 2041 t.Errorf("case %d B:\n%s", i, err.Error())
2042 } 2042 }
2043
2044 // Test the parameter populateCompleteTypeSet. We set the final
2045 // parameter to false.
2046 bytes, _, err = serialize(descriptor, false, false, true, false)
2047 if err != nil {
2048 t.Errorf("Serialization error for case %d: %s", i, err.E rror())
2049 continue
2050 }
2051
2052 // Deserialize
2053 decoder = bindings.NewDecoder(bytes, nil)
2054 fileGraph = mojom_files.MojomFileGraph{}
2055 fileGraph.Decode(decoder)
2056 runtimeTypeInfoA = deserializeRuntimeTypeInfo(*fileGraph.Files[f ileNameA].SerializedRuntimeTypeInfo)
2057
2058 // Check that CompleteTypeSet has not been populated for any ser vice.
2059 for name, service := range runtimeTypeInfoA.ServicesByName {
2060 length := len(service.CompleteTypeSet)
2061 if length != 0 {
2062 t.Errorf("len(CompleteTypeSet)=%d for service=%q ", length, name)
2063 }
2064 }
2043 } 2065 }
2044 } 2066 }
2045 2067
2046 func deserializeRuntimeTypeInfo(base64String string) mojom_types.RuntimeTypeInfo { 2068 func deserializeRuntimeTypeInfo(base64String string) mojom_types.RuntimeTypeInfo {
2047 compressedBytes, err := base64.StdEncoding.DecodeString(base64String) 2069 compressedBytes, err := base64.StdEncoding.DecodeString(base64String)
2048 if err != nil { 2070 if err != nil {
2049 panic(fmt.Sprintf("Error while unencoding runtimeTypeInfo: %s", err.Error())) 2071 panic(fmt.Sprintf("Error while unencoding runtimeTypeInfo: %s", err.Error()))
2050 } 2072 }
2051 reader, err2 := gzip.NewReader(bytes.NewBuffer(compressedBytes)) 2073 reader, err2 := gzip.NewReader(bytes.NewBuffer(compressedBytes))
2052 if err2 != nil { 2074 if err2 != nil {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2093 } 2115 }
2094 return fmt.Errorf("*****\nexpected=\n*****\n%q\n*****\na ctual=\n*****\n%q\n*****\n"+ 2116 return fmt.Errorf("*****\nexpected=\n*****\n%q\n*****\na ctual=\n*****\n%q\n*****\n"+
2095 "match failed at position %d: expected=\n*****\n %q\n******\nactual=\n*****\n%q\n******\n", 2117 "match failed at position %d: expected=\n*****\n %q\n******\nactual=\n*****\n%q\n******\n",
2096 expectedString, actualString, diffPos, mismatchE xpected, mismatchActual) 2118 expectedString, actualString, diffPos, mismatchE xpected, mismatchActual)
2097 } else { 2119 } else {
2098 return fmt.Errorf("expected != actual but the two printe d equal.") 2120 return fmt.Errorf("expected != actual but the two printe d equal.")
2099 } 2121 }
2100 } 2122 }
2101 return nil 2123 return nil
2102 } 2124 }
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