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 1130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1141 continue | 1141 continue |
1142 } | 1142 } |
1143 if err := descriptor.Resolve(); err != nil { | 1143 if err := descriptor.Resolve(); err != nil { |
1144 t.Errorf("Resolve error for %s: %s", c.fileName, err.Err
or()) | 1144 t.Errorf("Resolve error for %s: %s", c.fileName, err.Err
or()) |
1145 continue | 1145 continue |
1146 } | 1146 } |
1147 if err := descriptor.ComputeFinalData(); err != nil { | 1147 if err := descriptor.ComputeFinalData(); err != nil { |
1148 t.Errorf("ComputeFinalData error for %s: %s", c.fileName
, err.Error()) | 1148 t.Errorf("ComputeFinalData error for %s: %s", c.fileName
, err.Error()) |
1149 continue | 1149 continue |
1150 } | 1150 } |
| 1151 if err := descriptor.DetectIllFoundedTypes(); err != nil { |
| 1152 t.Errorf("DetectIllFoundedTypes error for %s: %s", c.fil
eName, err.Error()) |
| 1153 continue |
| 1154 } |
1151 | 1155 |
1152 // Simulate setting the canonical file name for the imported fil
es. In real operation | 1156 // Simulate setting the canonical file name for the imported fil
es. In real operation |
1153 // this step is done in parser_driver.go when each of the import
ed files are parsed. | 1157 // this step is done in parser_driver.go when each of the import
ed files are parsed. |
1154 mojomFile := parser.GetMojomFile() | 1158 mojomFile := parser.GetMojomFile() |
1155 if mojomFile.Imports != nil { | 1159 if mojomFile.Imports != nil { |
1156 for _, imp := range mojomFile.Imports { | 1160 for _, imp := range mojomFile.Imports { |
1157 imp.CanonicalFileName = fmt.Sprintf("%s.canonica
l", imp.SpecifiedName) | 1161 imp.CanonicalFileName = fmt.Sprintf("%s.canonica
l", imp.SpecifiedName) |
1158 } | 1162 } |
1159 } | 1163 } |
1160 | 1164 |
(...skipping 914 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2075 //////////////////////////////////////////////////////////// | 2079 //////////////////////////////////////////////////////////// |
2076 { | 2080 { |
2077 contents := ` | 2081 contents := ` |
2078 union MyUnion1{}; | 2082 union MyUnion1{}; |
2079 | 2083 |
2080 interface MyInterface1{}; | 2084 interface MyInterface1{}; |
2081 | 2085 |
2082 struct MyStruct1 { | 2086 struct MyStruct1 { |
2083 int8 x; | 2087 int8 x; |
2084 MyUnion1 my_union; | 2088 MyUnion1 my_union; |
2085 » MyStruct1 my_struct; | 2089 » MyStruct1? my_struct; |
2086 MyInterface1& my_interface_request; | 2090 MyInterface1& my_interface_request; |
2087 int32 y; | 2091 int32 y; |
2088 MyInterface1 my_interface; | 2092 MyInterface1 my_interface; |
2089 };` | 2093 };` |
2090 | 2094 |
2091 test.addTestCase("", contents) | 2095 test.addTestCase("", contents) |
2092 | 2096 |
2093 test.expectedFile().DeclaredMojomObjects.Unions = &[]string{"TYP
E_KEY:MyUnion1"} | 2097 test.expectedFile().DeclaredMojomObjects.Unions = &[]string{"TYP
E_KEY:MyUnion1"} |
2094 test.expectedFile().DeclaredMojomObjects.Interfaces = &[]string{
"TYPE_KEY:MyInterface1"} | 2098 test.expectedFile().DeclaredMojomObjects.Interfaces = &[]string{
"TYPE_KEY:MyInterface1"} |
2095 test.expectedFile().DeclaredMojomObjects.Structs = &[]string{"TY
PE_KEY:MyStruct1"} | 2099 test.expectedFile().DeclaredMojomObjects.Structs = &[]string{"TY
PE_KEY:MyStruct1"} |
(...skipping 14 matching lines...) Expand all Loading... |
2110 { | 2114 { |
2111 DeclData: test.newShortDeclDataO(1, -1,
"my_union"), | 2115 DeclData: test.newShortDeclDataO(1, -1,
"my_union"), |
2112 Type: &mojom_types.TypeTypeReference{moj
om_types.TypeReference{ | 2116 Type: &mojom_types.TypeTypeReference{moj
om_types.TypeReference{ |
2113 false, false, stringPointer("MyU
nion1"), stringPointer("TYPE_KEY:MyUnion1")}}, | 2117 false, false, stringPointer("MyU
nion1"), stringPointer("TYPE_KEY:MyUnion1")}}, |
2114 Offset: 8, | 2118 Offset: 8, |
2115 }, | 2119 }, |
2116 // field my_struct | 2120 // field my_struct |
2117 { | 2121 { |
2118 DeclData: test.newShortDeclDataO(2, -1,
"my_struct"), | 2122 DeclData: test.newShortDeclDataO(2, -1,
"my_struct"), |
2119 Type: &mojom_types.TypeTypeReference{moj
om_types.TypeReference{ | 2123 Type: &mojom_types.TypeTypeReference{moj
om_types.TypeReference{ |
2120 » » » » » » false, false, stringPointer("MyS
truct1"), stringPointer("TYPE_KEY:MyStruct1")}}, | 2124 » » » » » » true, false, stringPointer("MySt
ruct1"), stringPointer("TYPE_KEY:MyStruct1")}}, |
2121 Offset: 24, | 2125 Offset: 24, |
2122 }, | 2126 }, |
2123 // field my_interface_request | 2127 // field my_interface_request |
2124 { | 2128 { |
2125 DeclData: test.newShortDeclDataO(3, -1,
"my_interface_request"), | 2129 DeclData: test.newShortDeclDataO(3, -1,
"my_interface_request"), |
2126 Type: &mojom_types.TypeTypeReference{moj
om_types.TypeReference{ | 2130 Type: &mojom_types.TypeTypeReference{moj
om_types.TypeReference{ |
2127 false, true, stringPointer("MyIn
terface1"), stringPointer("TYPE_KEY:MyInterface1")}}, | 2131 false, true, stringPointer("MyIn
terface1"), stringPointer("TYPE_KEY:MyInterface1")}}, |
2128 Offset: 4, | 2132 Offset: 4, |
2129 }, | 2133 }, |
2130 // field y | 2134 // field y |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2174 //////////////////////////////////////////////////////////// | 2178 //////////////////////////////////////////////////////////// |
2175 { | 2179 { |
2176 contents := ` | 2180 contents := ` |
2177 union MyUnion1{}; | 2181 union MyUnion1{}; |
2178 | 2182 |
2179 interface MyInterface1{}; | 2183 interface MyInterface1{}; |
2180 | 2184 |
2181 struct MyStruct1 { | 2185 struct MyStruct1 { |
2182 int8 x; | 2186 int8 x; |
2183 MyUnion1 my_union; | 2187 MyUnion1 my_union; |
2184 » MyStruct1 my_struct; | 2188 » MyStruct1? my_struct; |
2185 | 2189 |
2186 [MinVersion=1] | 2190 [MinVersion=1] |
2187 MyInterface1&? my_interface_request; | 2191 MyInterface1&? my_interface_request; |
2188 | 2192 |
2189 [MinVersion=2] | 2193 [MinVersion=2] |
2190 int32 y; | 2194 int32 y; |
2191 | 2195 |
2192 [MinVersion=2] | 2196 [MinVersion=2] |
2193 MyInterface1? my_interface; | 2197 MyInterface1? my_interface; |
2194 };` | 2198 };` |
(...skipping 20 matching lines...) Expand all Loading... |
2215 { | 2219 { |
2216 DeclData: test.newShortDeclDataO(1, -1,
"my_union"), | 2220 DeclData: test.newShortDeclDataO(1, -1,
"my_union"), |
2217 Type: &mojom_types.TypeTypeReference{moj
om_types.TypeReference{ | 2221 Type: &mojom_types.TypeTypeReference{moj
om_types.TypeReference{ |
2218 false, false, stringPointer("MyU
nion1"), stringPointer("TYPE_KEY:MyUnion1")}}, | 2222 false, false, stringPointer("MyU
nion1"), stringPointer("TYPE_KEY:MyUnion1")}}, |
2219 Offset: 8, | 2223 Offset: 8, |
2220 }, | 2224 }, |
2221 // field my_struct | 2225 // field my_struct |
2222 { | 2226 { |
2223 DeclData: test.newShortDeclDataO(2, -1,
"my_struct"), | 2227 DeclData: test.newShortDeclDataO(2, -1,
"my_struct"), |
2224 Type: &mojom_types.TypeTypeReference{moj
om_types.TypeReference{ | 2228 Type: &mojom_types.TypeTypeReference{moj
om_types.TypeReference{ |
2225 » » » » » » false, false, stringPointer("MyS
truct1"), stringPointer("TYPE_KEY:MyStruct1")}}, | 2229 » » » » » » true, false, stringPointer("MySt
ruct1"), stringPointer("TYPE_KEY:MyStruct1")}}, |
2226 Offset: 24, | 2230 Offset: 24, |
2227 }, | 2231 }, |
2228 // field my_interface_request | 2232 // field my_interface_request |
2229 { | 2233 { |
2230 DeclData: test.newShortDeclDataAO(3, -1,
"my_interface_request", &[]mojom_types.Attribute{{"MinVersion", &mojom_types.Li
teralValueInt8Value{1}}}), | 2234 DeclData: test.newShortDeclDataAO(3, -1,
"my_interface_request", &[]mojom_types.Attribute{{"MinVersion", &mojom_types.Li
teralValueInt8Value{1}}}), |
2231 Type: &mojom_types.TypeTypeReference{moj
om_types.TypeReference{ | 2235 Type: &mojom_types.TypeTypeReference{moj
om_types.TypeReference{ |
2232 true, true, stringPointer("MyInt
erface1"), stringPointer("TYPE_KEY:MyInterface1")}}, | 2236 true, true, stringPointer("MyInt
erface1"), stringPointer("TYPE_KEY:MyInterface1")}}, |
2233 Offset: 4, | 2237 Offset: 4, |
2234 MinVersion: 1, | 2238 MinVersion: 1, |
2235 }, | 2239 }, |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2296 continue | 2300 continue |
2297 } | 2301 } |
2298 if err := descriptor.Resolve(); err != nil { | 2302 if err := descriptor.Resolve(); err != nil { |
2299 t.Errorf("Resolve error for %s: %s", c.fileName, err.Err
or()) | 2303 t.Errorf("Resolve error for %s: %s", c.fileName, err.Err
or()) |
2300 continue | 2304 continue |
2301 } | 2305 } |
2302 if err := descriptor.ComputeFinalData(); err != nil { | 2306 if err := descriptor.ComputeFinalData(); err != nil { |
2303 t.Errorf("ComputeFinalData error for %s: %s", c.fileName
, err.Error()) | 2307 t.Errorf("ComputeFinalData error for %s: %s", c.fileName
, err.Error()) |
2304 continue | 2308 continue |
2305 } | 2309 } |
| 2310 if err := descriptor.DetectIllFoundedTypes(); err != nil { |
| 2311 t.Errorf("DetectIllFoundedTypes error for %s: %s", c.fil
eName, err.Error()) |
| 2312 continue |
| 2313 } |
2306 | 2314 |
2307 // Simulate setting the canonical file name for the imported fil
es. In real operation | 2315 // Simulate setting the canonical file name for the imported fil
es. In real operation |
2308 // this step is done in parser_driver.go when each of the import
ed files are parsed. | 2316 // this step is done in parser_driver.go when each of the import
ed files are parsed. |
2309 mojomFile := parser.GetMojomFile() | 2317 mojomFile := parser.GetMojomFile() |
2310 if mojomFile.Imports != nil { | 2318 if mojomFile.Imports != nil { |
2311 for _, imp := range mojomFile.Imports { | 2319 for _, imp := range mojomFile.Imports { |
2312 imp.CanonicalFileName = fmt.Sprintf("%s.canonica
l", imp.SpecifiedName) | 2320 imp.CanonicalFileName = fmt.Sprintf("%s.canonica
l", imp.SpecifiedName) |
2313 } | 2321 } |
2314 } | 2322 } |
2315 | 2323 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2405 continue | 2413 continue |
2406 } | 2414 } |
2407 if err := descriptor.Resolve(); err != nil { | 2415 if err := descriptor.Resolve(); err != nil { |
2408 t.Errorf("Resolve error for %s: %s", c.fileName, err.Err
or()) | 2416 t.Errorf("Resolve error for %s: %s", c.fileName, err.Err
or()) |
2409 continue | 2417 continue |
2410 } | 2418 } |
2411 if err := descriptor.ComputeFinalData(); err != nil { | 2419 if err := descriptor.ComputeFinalData(); err != nil { |
2412 t.Errorf("ComputeFinalData error for %s: %s", c.fileName
, err.Error()) | 2420 t.Errorf("ComputeFinalData error for %s: %s", c.fileName
, err.Error()) |
2413 continue | 2421 continue |
2414 } | 2422 } |
| 2423 if err := descriptor.DetectIllFoundedTypes(); err != nil { |
| 2424 t.Errorf("DetectIllFoundedTypes error for %s: %s", c.fil
eName, err.Error()) |
| 2425 continue |
| 2426 } |
2415 | 2427 |
2416 // Serialize | 2428 // Serialize |
2417 bytes, _, err := serialize(descriptor, false, false, c.lineAndco
lumnNumbers, false) | 2429 bytes, _, err := serialize(descriptor, false, false, c.lineAndco
lumnNumbers, false) |
2418 if err != nil { | 2430 if err != nil { |
2419 t.Errorf("Serialization error for %s: %s", c.fileName, e
rr.Error()) | 2431 t.Errorf("Serialization error for %s: %s", c.fileName, e
rr.Error()) |
2420 continue | 2432 continue |
2421 } | 2433 } |
2422 | 2434 |
2423 // Deserialize | 2435 // Deserialize |
2424 decoder := bindings.NewDecoder(bytes, nil) | 2436 decoder := bindings.NewDecoder(bytes, nil) |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2680 | 2692 |
2681 // Resolve | 2693 // Resolve |
2682 if err := descriptor.Resolve(); err != nil { | 2694 if err := descriptor.Resolve(); err != nil { |
2683 t.Errorf("Resolve error for case %d: %s", i, err.Error()
) | 2695 t.Errorf("Resolve error for case %d: %s", i, err.Error()
) |
2684 continue | 2696 continue |
2685 } | 2697 } |
2686 if err := descriptor.ComputeFinalData(); err != nil { | 2698 if err := descriptor.ComputeFinalData(); err != nil { |
2687 t.Errorf("ComputeFinalData error for case %d: %s", i, er
r.Error()) | 2699 t.Errorf("ComputeFinalData error for case %d: %s", i, er
r.Error()) |
2688 continue | 2700 continue |
2689 } | 2701 } |
| 2702 if err := descriptor.DetectIllFoundedTypes(); err != nil { |
| 2703 t.Errorf("DetectIllFoundedTypes error for case %d: %s",
i, err.Error()) |
| 2704 continue |
| 2705 } |
2690 | 2706 |
2691 // Serialize | 2707 // Serialize |
2692 bytes, _, err := serialize(descriptor, false, false, c.lineAndco
lumnNumbers, false) | 2708 bytes, _, err := serialize(descriptor, false, false, c.lineAndco
lumnNumbers, false) |
2693 if err != nil { | 2709 if err != nil { |
2694 t.Errorf("Serialization error for case %d: %s", i, err.E
rror()) | 2710 t.Errorf("Serialization error for case %d: %s", i, err.E
rror()) |
2695 continue | 2711 continue |
2696 } | 2712 } |
2697 | 2713 |
2698 // Deserialize | 2714 // Deserialize |
2699 decoder := bindings.NewDecoder(bytes, nil) | 2715 decoder := bindings.NewDecoder(bytes, nil) |
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3289 | 3305 |
3290 // Resolve | 3306 // Resolve |
3291 if err := descriptor.Resolve(); err != nil { | 3307 if err := descriptor.Resolve(); err != nil { |
3292 t.Errorf("Resolve error for case %d: %s", i, err.Error()
) | 3308 t.Errorf("Resolve error for case %d: %s", i, err.Error()
) |
3293 continue | 3309 continue |
3294 } | 3310 } |
3295 if err := descriptor.ComputeFinalData(); err != nil { | 3311 if err := descriptor.ComputeFinalData(); err != nil { |
3296 t.Errorf("ComputeFinalData error for case %d: %s", i, er
r.Error()) | 3312 t.Errorf("ComputeFinalData error for case %d: %s", i, er
r.Error()) |
3297 continue | 3313 continue |
3298 } | 3314 } |
| 3315 if err := descriptor.DetectIllFoundedTypes(); err != nil { |
| 3316 t.Errorf("DetectIllFoundedTypes error for case %d: %s",
i, err.Error()) |
| 3317 continue |
| 3318 } |
3299 | 3319 |
3300 // Serialize | 3320 // Serialize |
3301 bytes, _, err := serialize(descriptor, false, false, false, true
) | 3321 bytes, _, err := serialize(descriptor, false, false, false, true
) |
3302 if err != nil { | 3322 if err != nil { |
3303 t.Errorf("Serialization error for case %d: %s", i, err.E
rror()) | 3323 t.Errorf("Serialization error for case %d: %s", i, err.E
rror()) |
3304 continue | 3324 continue |
3305 } | 3325 } |
3306 | 3326 |
3307 // Deserialize | 3327 // Deserialize |
3308 decoder := bindings.NewDecoder(bytes, nil) | 3328 decoder := bindings.NewDecoder(bytes, nil) |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3377 } | 3397 } |
3378 return fmt.Errorf("*****\nexpected=\n*****\n%q\n*****\na
ctual=\n*****\n%q\n*****\n"+ | 3398 return fmt.Errorf("*****\nexpected=\n*****\n%q\n*****\na
ctual=\n*****\n%q\n*****\n"+ |
3379 "match failed at position %d: expected=\n*****\n
%q\n******\nactual=\n*****\n%q\n******\n", | 3399 "match failed at position %d: expected=\n*****\n
%q\n******\nactual=\n*****\n%q\n******\n", |
3380 expectedString, actualString, diffPos, mismatchE
xpected, mismatchActual) | 3400 expectedString, actualString, diffPos, mismatchE
xpected, mismatchActual) |
3381 } else { | 3401 } else { |
3382 return fmt.Errorf("expected != actual but the two printe
d equal.") | 3402 return fmt.Errorf("expected != actual but the two printe
d equal.") |
3383 } | 3403 } |
3384 } | 3404 } |
3385 return nil | 3405 return nil |
3386 } | 3406 } |
OLD | NEW |