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 "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 991 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1002 } | 1002 } |
1003 } | 1003 } |
1004 | 1004 |
1005 // Serialize | 1005 // Serialize |
1006 bytes, _, err := serialize(descriptor, false, c.lineAndcolumnNum
bers, false) | 1006 bytes, _, err := serialize(descriptor, false, c.lineAndcolumnNum
bers, false) |
1007 if err != nil { | 1007 if err != nil { |
1008 t.Errorf("Serialization error for %s: %s", c.fileName, e
rr.Error()) | 1008 t.Errorf("Serialization error for %s: %s", c.fileName, e
rr.Error()) |
1009 continue | 1009 continue |
1010 } | 1010 } |
1011 | 1011 |
| 1012 // Serialize again and check for consistency. |
| 1013 bytes2, _, err := serialize(descriptor, false, c.lineAndcolumnNu
mbers, false) |
| 1014 if err != nil { |
| 1015 t.Errorf("Serialization error for %s: %s", c.fileName, e
rr.Error()) |
| 1016 continue |
| 1017 } |
| 1018 |
| 1019 if !reflect.DeepEqual(bytes, bytes2) { |
| 1020 t.Errorf("Inconsistent serialization for %s:\nbytes=%v\n
bytes2=%v\n", |
| 1021 c.fileName, bytes, bytes2) |
| 1022 continue |
| 1023 } |
| 1024 |
1012 // Deserialize | 1025 // Deserialize |
1013 decoder := bindings.NewDecoder(bytes, nil) | 1026 decoder := bindings.NewDecoder(bytes, nil) |
1014 fileGraph := mojom_files.MojomFileGraph{} | 1027 fileGraph := mojom_files.MojomFileGraph{} |
1015 fileGraph.Decode(decoder) | 1028 fileGraph.Decode(decoder) |
1016 | 1029 |
1017 // Compare | 1030 // Compare |
1018 if err := compareTwoGoObjects(c.expectedGraph, &fileGraph); err
!= nil { | 1031 if err := compareTwoGoObjects(c.expectedGraph, &fileGraph); err
!= nil { |
1019 t.Errorf("%s:\n%s", c.fileName, err.Error()) | 1032 t.Errorf("%s:\n%s", c.fileName, err.Error()) |
1020 continue | 1033 continue |
1021 } | 1034 } |
(...skipping 1036 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2058 } | 2071 } |
2059 return fmt.Errorf("*****\nexpected=\n*****\n%q\n*****\na
ctual=\n*****\n%q\n*****\n"+ | 2072 return fmt.Errorf("*****\nexpected=\n*****\n%q\n*****\na
ctual=\n*****\n%q\n*****\n"+ |
2060 "match failed at position %d: expected=\n*****\n
%q\n******\nactual=\n*****\n%q\n******\n", | 2073 "match failed at position %d: expected=\n*****\n
%q\n******\nactual=\n*****\n%q\n******\n", |
2061 expectedString, actualString, diffPos, mismatchE
xpected, mismatchActual) | 2074 expectedString, actualString, diffPos, mismatchE
xpected, mismatchActual) |
2062 } else { | 2075 } else { |
2063 return fmt.Errorf("expected != actual but the two printe
d equal.") | 2076 return fmt.Errorf("expected != actual but the two printe
d equal.") |
2064 } | 2077 } |
2065 } | 2078 } |
2066 return nil | 2079 return nil |
2067 } | 2080 } |
OLD | NEW |