aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/archive/zip/writer_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/go/archive/zip/writer_test.go')
-rw-r--r--libgo/go/archive/zip/writer_test.go90
1 files changed, 80 insertions, 10 deletions
diff --git a/libgo/go/archive/zip/writer_test.go b/libgo/go/archive/zip/writer_test.go
index 86841c755f1..92fb6ecf0ed 100644
--- a/libgo/go/archive/zip/writer_test.go
+++ b/libgo/go/archive/zip/writer_test.go
@@ -87,6 +87,69 @@ func TestWriter(t *testing.T) {
}
}
+func TestWriterUTF8(t *testing.T) {
+ var utf8Tests = []struct {
+ name string
+ comment string
+ expect uint16
+ }{
+ {
+ name: "hi, hello",
+ comment: "in the world",
+ expect: 0x8,
+ },
+ {
+ name: "hi, こんにちわ",
+ comment: "in the world",
+ expect: 0x808,
+ },
+ {
+ name: "hi, hello",
+ comment: "in the 世界",
+ expect: 0x808,
+ },
+ {
+ name: "hi, こんにちわ",
+ comment: "in the 世界",
+ expect: 0x808,
+ },
+ }
+
+ // write a zip file
+ buf := new(bytes.Buffer)
+ w := NewWriter(buf)
+
+ for _, test := range utf8Tests {
+ h := &FileHeader{
+ Name: test.name,
+ Comment: test.comment,
+ Method: Deflate,
+ }
+ w, err := w.CreateHeader(h)
+ if err != nil {
+ t.Fatal(err)
+ }
+ w.Write([]byte{})
+ }
+
+ if err := w.Close(); err != nil {
+ t.Fatal(err)
+ }
+
+ // read it back
+ r, err := NewReader(bytes.NewReader(buf.Bytes()), int64(buf.Len()))
+ if err != nil {
+ t.Fatal(err)
+ }
+ for i, test := range utf8Tests {
+ got := r.File[i].Flags
+ t.Logf("name %v, comment %v", test.name, test.comment)
+ if got != test.expect {
+ t.Fatalf("Flags: got %v, want %v", got, test.expect)
+ }
+ }
+}
+
func TestWriterOffset(t *testing.T) {
largeData := make([]byte, 1<<17)
for i := range largeData {
@@ -181,12 +244,11 @@ func testReadFile(t *testing.T, f *File, wt *WriteTest) {
}
func BenchmarkCompressedZipGarbage(b *testing.B) {
- b.ReportAllocs()
- var buf bytes.Buffer
bigBuf := bytes.Repeat([]byte("a"), 1<<20)
- for i := 0; i <= b.N; i++ {
+
+ runOnce := func(buf *bytes.Buffer) {
buf.Reset()
- zw := NewWriter(&buf)
+ zw := NewWriter(buf)
for j := 0; j < 3; j++ {
w, _ := zw.CreateHeader(&FileHeader{
Name: "foo",
@@ -195,11 +257,19 @@ func BenchmarkCompressedZipGarbage(b *testing.B) {
w.Write(bigBuf)
}
zw.Close()
- if i == 0 {
- // Reset the timer after the first time through.
- // This effectively discards the very large initial flate setup cost,
- // as well as the initialization of bigBuf.
- b.ResetTimer()
- }
}
+
+ b.ReportAllocs()
+ // Run once and then reset the timer.
+ // This effectively discards the very large initial flate setup cost,
+ // as well as the initialization of bigBuf.
+ runOnce(&bytes.Buffer{})
+ b.ResetTimer()
+
+ b.RunParallel(func(pb *testing.PB) {
+ var buf bytes.Buffer
+ for pb.Next() {
+ runOnce(&buf)
+ }
+ })
}