2020-03-05 11:29:24 -05:00
|
|
|
// Copyright 2020 The Go Authors. All rights reserved.
|
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
|
|
package goobj2
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bufio"
|
|
|
|
|
"bytes"
|
|
|
|
|
"cmd/internal/bio"
|
|
|
|
|
"testing"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func dummyWriter() *Writer {
|
|
|
|
|
var buf bytes.Buffer
|
|
|
|
|
wr := &bio.Writer{Writer: bufio.NewWriter(&buf)} // hacky: no file, so cannot seek
|
|
|
|
|
return NewWriter(wr)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestSize(t *testing.T) {
|
|
|
|
|
// This test checks that hard-coded sizes match the actual sizes
|
|
|
|
|
// in the object file format.
|
2020-03-06 01:15:07 -05:00
|
|
|
tests := []struct {
|
|
|
|
|
x interface{ Write(*Writer) }
|
|
|
|
|
want uint32
|
|
|
|
|
}{
|
|
|
|
|
{&Reloc{}, RelocSize},
|
|
|
|
|
{&Aux{}, AuxSize},
|
|
|
|
|
}
|
2020-03-05 11:29:24 -05:00
|
|
|
w := dummyWriter()
|
2020-03-06 01:15:07 -05:00
|
|
|
for _, test := range tests {
|
|
|
|
|
off0 := w.off
|
|
|
|
|
test.x.Write(w)
|
|
|
|
|
got := w.off - off0
|
|
|
|
|
if got != test.want {
|
|
|
|
|
t.Errorf("size(%T) mismatch: %d bytes written, but size=%d", test.x, got, test.want)
|
|
|
|
|
}
|
2020-03-05 11:29:24 -05:00
|
|
|
}
|
|
|
|
|
}
|