Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(249)

Unified Diff: snappy/snappy_test.go

Issue 5167058: snappy: add a reader and writer for the frame format.
Patch Set: diff -r fa2afaefa608 https://code.google.com/p/snappy-go/ Created 12 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « snappy/reader.go ('k') | snappy/writer.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: snappy/snappy_test.go
===================================================================
--- a/snappy/snappy_test.go
+++ b/snappy/snappy_test.go
@@ -5,8 +5,10 @@
package snappy
import (
+ "bufio"
"bytes"
"fmt"
+ "io"
"io/ioutil"
"os"
"rand"
@@ -63,6 +65,53 @@
}
}
+func TestReaderWriter(t *testing.T) {
+ // Test that pushing a file's contents through a pipe whose ends are
+ // wrapped with a snappy Reader and Writer is the identity transform.
+ const filename = "/usr/share/dict/words"
+ pr, pw := io.Pipe()
+ go func() {
+ f, err := os.Open(filename)
+ if err != nil {
+ pw.CloseWithError(err)
+ return
+ }
+ defer f.Close()
+ _, err = pw.Write([]byte(Magic))
+ if err != nil {
+ pw.CloseWithError(err)
+ return
+ }
+ w := NewWriter(pw)
+ _, err = io.Copy(w, f)
+ if err != nil {
+ pw.CloseWithError(err)
+ return
+ }
+ pw.CloseWithError(w.Flush())
+ }()
+ f, err := os.Open(filename)
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer f.Close()
+ b0 := bufio.NewReader(NewReader(pr))
+ b1 := bufio.NewReader(f)
+ for {
+ s0, err0 := b0.ReadString('\n')
+ s1, err1 := b1.ReadString('\n')
+ if err0 != nil || err1 != nil {
+ if err0 == os.EOF && err1 == os.EOF {
+ break
+ }
+ t.Fatalf("err0=%v, err1=%v", err0, err1)
+ }
+ if s0 != s1 {
+ t.Fatalf("s0=%q, s1=%q", s0, s1)
+ }
+ }
+}
+
func benchWords(b *testing.B, n int, decode bool) {
b.StopTimer()
« no previous file with comments | « snappy/reader.go ('k') | snappy/writer.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b