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

Unified Diff: mojom/mojom_parser/serialization/serialization_test.go

Issue 1776243004: Mojom runtime type info: Use compression and base64 encoding. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Rebasing 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojom/mojom_parser/serialization/serialization.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojom/mojom_parser/serialization/serialization_test.go
diff --git a/mojom/mojom_parser/serialization/serialization_test.go b/mojom/mojom_parser/serialization/serialization_test.go
index 49748a92c24d5e5a538c7d528b94bec3578b482a..d97459b99421ea0bc93df3ca816414bb26f07b76 100644
--- a/mojom/mojom_parser/serialization/serialization_test.go
+++ b/mojom/mojom_parser/serialization/serialization_test.go
@@ -5,7 +5,11 @@
package serialization
import (
+ "bytes"
+ "compress/gzip"
+ "encoding/base64"
"fmt"
+ "io/ioutil"
"mojo/public/go/bindings"
"mojom/mojom_parser/generated/mojom_files"
"mojom/mojom_parser/generated/mojom_types"
@@ -2022,14 +2026,10 @@ func TestRuntimeTypeInfo(t *testing.T) {
fileGraph.Decode(decoder)
// Deserialize RuntimeTypeInfo A
- decoder = bindings.NewDecoder(*fileGraph.Files[fileNameA].SerializedRuntimeTypeInfo, nil)
- runtimeTypeInfoA := mojom_types.RuntimeTypeInfo{}
- runtimeTypeInfoA.Decode(decoder)
+ runtimeTypeInfoA := deserializeRuntimeTypeInfo(*fileGraph.Files[fileNameA].SerializedRuntimeTypeInfo)
// Deserialize RuntimeTypeInfo B
- decoder = bindings.NewDecoder(*fileGraph.Files[fileNameB].SerializedRuntimeTypeInfo, nil)
- runtimeTypeInfoB := mojom_types.RuntimeTypeInfo{}
- runtimeTypeInfoB.Decode(decoder)
+ runtimeTypeInfoB := deserializeRuntimeTypeInfo(*fileGraph.Files[fileNameB].SerializedRuntimeTypeInfo)
// Compare A
if err := compareTwoGoObjects(c.expectedRuntimeTypeInfoA, &runtimeTypeInfoA); err != nil {
@@ -2043,6 +2043,28 @@ func TestRuntimeTypeInfo(t *testing.T) {
}
}
+func deserializeRuntimeTypeInfo(base64String string) mojom_types.RuntimeTypeInfo {
+ compressedBytes, err := base64.StdEncoding.DecodeString(base64String)
+ if err != nil {
+ panic(fmt.Sprintf("Error while unencoding runtimeTypeInfo: %s", err.Error()))
+ }
+ reader, err2 := gzip.NewReader(bytes.NewBuffer(compressedBytes))
+ if err2 != nil {
+ panic(fmt.Sprintf("Error while decompressing runtimeTypeInfo: %s", err.Error()))
+ }
+ uncompressedBytes, err3 := ioutil.ReadAll(reader)
+ if err3 != nil {
+ panic(fmt.Sprintf("Error while decompressing runtimeTypeInfo: %s", err2.Error()))
+ }
+ if err = reader.Close(); err != nil {
+ panic(fmt.Sprintf("Error while decompressing runtimeTypeInfo: %s", err.Error()))
+ }
+ decoder := bindings.NewDecoder(uncompressedBytes, nil)
+ runtimeTypeInfo := mojom_types.RuntimeTypeInfo{}
+ runtimeTypeInfo.Decode(decoder)
+ return runtimeTypeInfo
+}
+
// compareTwoGoObjects compares |expected| and |actual| and returns a non-nil
// error if they are not deeply equal. The error message contains a human-readable
// string containing a deep-print of expected and actual along with the substrings
« 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