Commit dadfd14b authored by Alex Brainman's avatar Alex Brainman

os: add more tests in TestReadStdin

TestReadStdin always fill up buffer provided by ReadFile caller full.
But we do not know if real ReadFile does the same. Add tests where
buffer is only filled with limited data.

Change-Id: I0fc776325c2b1fe60511126c439f4b0560e9d653
Reviewed-on: https://go-review.googlesource.com/33030Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent b8d56fdd
......@@ -691,11 +691,15 @@ func TestReadStdin(t *testing.T) {
},
}
)
for _, bufsize := range []int{1, 2, 3, 4, 5, 8, 10, 16, 20, 50, 100} {
for _, consoleReadBufSize := range []int{1, 2, 3, 4, 5, 8, 10, 16, 20, 50, 100} {
for _, readFileBufSize := range []int{1, 2, 3, 10, 16, 100, 1000} {
nextTest:
for ti, test := range tests {
input := bytes.NewBuffer(test.input)
*os.ReadFileP = func(h syscall.Handle, buf []byte, done *uint32, o *syscall.Overlapped) error {
if len(buf) > readFileBufSize {
buf = buf[:readFileBufSize]
}
n, err := input.Read(buf)
*done = uint32(n)
return err
......@@ -705,10 +709,10 @@ func TestReadStdin(t *testing.T) {
}
var bigbuf []byte
for len(bigbuf) < len([]byte(test.output)) {
buf := make([]byte, bufsize)
buf := make([]byte, consoleReadBufSize)
n, err := testConsole.Read(buf)
if err != nil {
t.Errorf("test=%d bufsize=%d: read failed: %v", ti, bufsize, err)
t.Errorf("test=%d bufsizes=%d,%d: read failed: %v", ti, consoleReadBufSize, readFileBufSize, err)
continue nextTest
}
bigbuf = append(bigbuf, buf[:n]...)
......@@ -716,11 +720,12 @@ func TestReadStdin(t *testing.T) {
have := hex.Dump(bigbuf)
expected := hex.Dump([]byte(test.output))
if have != expected {
t.Errorf("test=%d bufsize=%d: %q expected, but %q received", ti, bufsize, expected, have)
t.Errorf("test=%d bufsizes=%d,%d: %q expected, but %q received", ti, consoleReadBufSize, readFileBufSize, expected, have)
continue nextTest
}
}
}
}
}
func TestStatPagefile(t *testing.T) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment