diff options
author | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-11-21 07:03:38 +0000 |
---|---|---|
committer | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-11-21 07:03:38 +0000 |
commit | 79a796b7d3db5d100eedfc774954a6b44944363a (patch) | |
tree | 72455aea0286937aa08cc141e5efc800e4626577 /libgo/go/archive/tar/tar_test.go | |
parent | 7224cf54b3af2b931fb83af65f9cfab5c1df814a (diff) | |
download | gcc-79a796b7d3db5d100eedfc774954a6b44944363a.tar.gz |
libgo: Update to current version of master library.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@193688 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo/go/archive/tar/tar_test.go')
-rw-r--r-- | libgo/go/archive/tar/tar_test.go | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/libgo/go/archive/tar/tar_test.go b/libgo/go/archive/tar/tar_test.go index 0adc1790033..7b190b6a8b2 100644 --- a/libgo/go/archive/tar/tar_test.go +++ b/libgo/go/archive/tar/tar_test.go @@ -5,7 +5,10 @@ package tar import ( + "bytes" + "io/ioutil" "os" + "reflect" "testing" "time" ) @@ -54,3 +57,44 @@ func (symlink) Mode() os.FileMode { return os.ModeSymlink } func (symlink) ModTime() time.Time { return time.Time{} } func (symlink) IsDir() bool { return false } func (symlink) Sys() interface{} { return nil } + +func TestRoundTrip(t *testing.T) { + data := []byte("some file contents") + + var b bytes.Buffer + tw := NewWriter(&b) + hdr := &Header{ + Name: "file.txt", + Uid: 1 << 21, // too big for 8 octal digits + Size: int64(len(data)), + ModTime: time.Now(), + } + // tar only supports second precision. + hdr.ModTime = hdr.ModTime.Add(-time.Duration(hdr.ModTime.Nanosecond()) * time.Nanosecond) + if err := tw.WriteHeader(hdr); err != nil { + t.Fatalf("tw.WriteHeader: %v", err) + } + if _, err := tw.Write(data); err != nil { + t.Fatalf("tw.Write: %v", err) + } + if err := tw.Close(); err != nil { + t.Fatalf("tw.Close: %v", err) + } + + // Read it back. + tr := NewReader(&b) + rHdr, err := tr.Next() + if err != nil { + t.Fatalf("tr.Next: %v", err) + } + if !reflect.DeepEqual(rHdr, hdr) { + t.Errorf("Header mismatch.\n got %+v\nwant %+v", rHdr, hdr) + } + rData, err := ioutil.ReadAll(tr) + if err != nil { + t.Fatalf("Read: %v", err) + } + if !bytes.Equal(rData, data) { + t.Errorf("Data mismatch.\n got %q\nwant %q", rData, data) + } +} |