OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [go/] [archive/] [zip/] [zip_test.go] - Blame information for rev 760

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
// Copyright 2011 The Go Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
4
 
5
// Tests that involve both reading and writing.
6
 
7
package zip
8
 
9
import (
10
        "bytes"
11
        "fmt"
12
        "io"
13
        "reflect"
14
        "testing"
15
        "time"
16
)
17
 
18
type stringReaderAt string
19
 
20
func (s stringReaderAt) ReadAt(p []byte, off int64) (n int, err error) {
21
        if off >= int64(len(s)) {
22
                return 0, io.EOF
23
        }
24
        n = copy(p, s[off:])
25
        return
26
}
27
 
28
func TestOver65kFiles(t *testing.T) {
29
        if testing.Short() {
30
                t.Logf("slow test; skipping")
31
                return
32
        }
33
        buf := new(bytes.Buffer)
34
        w := NewWriter(buf)
35
        const nFiles = (1 << 16) + 42
36
        for i := 0; i < nFiles; i++ {
37
                _, err := w.Create(fmt.Sprintf("%d.dat", i))
38
                if err != nil {
39
                        t.Fatalf("creating file %d: %v", i, err)
40
                }
41
        }
42
        if err := w.Close(); err != nil {
43
                t.Fatalf("Writer.Close: %v", err)
44
        }
45
        rat := stringReaderAt(buf.String())
46
        zr, err := NewReader(rat, int64(len(rat)))
47
        if err != nil {
48
                t.Fatalf("NewReader: %v", err)
49
        }
50
        if got := len(zr.File); got != nFiles {
51
                t.Fatalf("File contains %d files, want %d", got, nFiles)
52
        }
53
        for i := 0; i < nFiles; i++ {
54
                want := fmt.Sprintf("%d.dat", i)
55
                if zr.File[i].Name != want {
56
                        t.Fatalf("File(%d) = %q, want %q", i, zr.File[i].Name, want)
57
                }
58
        }
59
}
60
 
61
func TestModTime(t *testing.T) {
62
        var testTime = time.Date(2009, time.November, 10, 23, 45, 58, 0, time.UTC)
63
        fh := new(FileHeader)
64
        fh.SetModTime(testTime)
65
        outTime := fh.ModTime()
66
        if !outTime.Equal(testTime) {
67
                t.Errorf("times don't match: got %s, want %s", outTime, testTime)
68
        }
69
}
70
 
71
func TestFileHeaderRoundTrip(t *testing.T) {
72
        fh := &FileHeader{
73
                Name:             "foo.txt",
74
                UncompressedSize: 987654321,
75
                ModifiedTime:     1234,
76
                ModifiedDate:     5678,
77
        }
78
        fi := fh.FileInfo()
79
        fh2, err := FileInfoHeader(fi)
80
 
81
        // Ignore these fields:
82
        fh2.CreatorVersion = 0
83
        fh2.ExternalAttrs = 0
84
 
85
        if !reflect.DeepEqual(fh, fh2) {
86
                t.Errorf("mismatch\n input=%#v\noutput=%#v\nerr=%v", fh, fh2, err)
87
        }
88
        if sysfh, ok := fi.Sys().(*FileHeader); !ok && sysfh != fh {
89
                t.Errorf("Sys didn't return original *FileHeader")
90
        }
91
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.