Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
af7e0f1b
Commit
af7e0f1b
authored
Jan 30, 2010
by
Nigel Tao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a GZIP test for the empty payload.
R=rsc, r CC=golang-dev
https://golang.org/cl/194131
parent
84f9b702
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
37 deletions
+57
-37
gzip_test.go
src/pkg/compress/gzip/gzip_test.go
+57
-37
No files found.
src/pkg/compress/gzip/gzip_test.go
View file @
af7e0f1b
...
@@ -11,55 +11,75 @@ import (
...
@@ -11,55 +11,75 @@ import (
"testing"
"testing"
)
)
//
Tests that gzipping and then gunzipping is the identity function.
//
pipe creates two ends of a pipe that gzip and gunzip, and runs dfunc at the
func
TestWriter
(
t
*
testing
.
T
)
{
// writer end and ifunc at the reader end.
// Set up the Pipe to do the gzip and gunzip.
func
pipe
(
t
*
testing
.
T
,
dfunc
func
(
*
Deflater
),
ifunc
func
(
*
Inflater
))
{
piper
,
pipew
:=
io
.
Pipe
()
piper
,
pipew
:=
io
.
Pipe
()
defer
piper
.
Close
()
defer
piper
.
Close
()
go
func
()
{
go
func
()
{
defer
pipew
.
Close
()
defer
pipew
.
Close
()
deflater
,
err
:=
NewDeflater
(
pipew
)
deflater
,
err
:=
NewDeflater
(
pipew
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"%v"
,
err
)
t
.
Fatalf
(
"%v"
,
err
)
return
}
}
defer
deflater
.
Close
()
defer
deflater
.
Close
()
deflater
.
Comment
=
"comment"
dfunc
(
deflater
)
deflater
.
Extra
=
strings
.
Bytes
(
"extra"
)
deflater
.
Mtime
=
1e8
deflater
.
Name
=
"name"
_
,
err
=
deflater
.
Write
(
strings
.
Bytes
(
"payload"
))
if
err
!=
nil
{
t
.
Errorf
(
"%v"
,
err
)
return
}
}()
}()
inflater
,
err
:=
NewInflater
(
piper
)
inflater
,
err
:=
NewInflater
(
piper
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Errorf
(
"%v"
,
err
)
t
.
Fatalf
(
"%v"
,
err
)
return
}
}
defer
inflater
.
Close
()
defer
inflater
.
Close
()
ifunc
(
inflater
)
}
// Read and compare to the original input.
// Tests that an empty payload still forms a valid GZIP stream.
b
,
err
:=
ioutil
.
ReadAll
(
inflater
)
func
TestEmpty
(
t
*
testing
.
T
)
{
if
err
!=
nil
{
pipe
(
t
,
t
.
Errorf
(
": %v"
,
err
)
func
(
deflater
*
Deflater
)
{},
return
func
(
inflater
*
Inflater
)
{
}
b
,
err
:=
ioutil
.
ReadAll
(
inflater
)
if
string
(
b
)
!=
"payload"
{
if
err
!=
nil
{
t
.
Fatalf
(
"payload is %q, want %q"
,
string
(
b
),
"payload"
)
t
.
Fatalf
(
"%v"
,
err
)
}
}
if
inflater
.
Comment
!=
"comment"
{
if
len
(
b
)
!=
0
{
t
.
Fatalf
(
"comment is %q, want %q"
,
inflater
.
Comment
,
"comment"
)
t
.
Fatalf
(
"did not read an empty slice"
)
}
}
if
string
(
inflater
.
Extra
)
!=
"extra"
{
})
t
.
Fatalf
(
"extra is %q, want %q"
,
inflater
.
Extra
,
"extra"
)
}
}
if
inflater
.
Mtime
!=
1e8
{
// Tests that gzipping and then gunzipping is the identity function.
t
.
Fatalf
(
"mtime is %d, want %d"
,
inflater
.
Mtime
,
uint32
(
1e8
))
func
TestWriter
(
t
*
testing
.
T
)
{
}
pipe
(
t
,
if
inflater
.
Name
!=
"name"
{
func
(
deflater
*
Deflater
)
{
t
.
Fatalf
(
"name is %q, want %q"
,
inflater
.
Name
,
"name"
)
deflater
.
Comment
=
"comment"
}
deflater
.
Extra
=
strings
.
Bytes
(
"extra"
)
deflater
.
Mtime
=
1e8
deflater
.
Name
=
"name"
_
,
err
:=
deflater
.
Write
(
strings
.
Bytes
(
"payload"
))
if
err
!=
nil
{
t
.
Fatalf
(
"%v"
,
err
)
}
},
func
(
inflater
*
Inflater
)
{
b
,
err
:=
ioutil
.
ReadAll
(
inflater
)
if
err
!=
nil
{
t
.
Fatalf
(
"%v"
,
err
)
}
if
string
(
b
)
!=
"payload"
{
t
.
Fatalf
(
"payload is %q, want %q"
,
string
(
b
),
"payload"
)
}
if
inflater
.
Comment
!=
"comment"
{
t
.
Fatalf
(
"comment is %q, want %q"
,
inflater
.
Comment
,
"comment"
)
}
if
string
(
inflater
.
Extra
)
!=
"extra"
{
t
.
Fatalf
(
"extra is %q, want %q"
,
inflater
.
Extra
,
"extra"
)
}
if
inflater
.
Mtime
!=
1e8
{
t
.
Fatalf
(
"mtime is %d, want %d"
,
inflater
.
Mtime
,
uint32
(
1e8
))
}
if
inflater
.
Name
!=
"name"
{
t
.
Fatalf
(
"name is %q, want %q"
,
inflater
.
Name
,
"name"
)
}
})
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment