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,33 +691,38 @@ func TestReadStdin(t *testing.T) {
},
}
)
for _, bufsize := range []int{1, 2, 3, 4, 5, 8, 10, 16, 20, 50, 100} {
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 {
n, err := input.Read(buf)
*done = uint32(n)
return err
}
*os.GetCPP = func() uint32 {
return test.cp
}
var bigbuf []byte
for len(bigbuf) < len([]byte(test.output)) {
buf := make([]byte, bufsize)
n, err := testConsole.Read(buf)
if err != nil {
t.Errorf("test=%d bufsize=%d: read failed: %v", ti, bufsize, err)
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
}
*os.GetCPP = func() uint32 {
return test.cp
}
var bigbuf []byte
for len(bigbuf) < len([]byte(test.output)) {
buf := make([]byte, consoleReadBufSize)
n, err := testConsole.Read(buf)
if err != nil {
t.Errorf("test=%d bufsizes=%d,%d: read failed: %v", ti, consoleReadBufSize, readFileBufSize, err)
continue nextTest
}
bigbuf = append(bigbuf, buf[:n]...)
}
have := hex.Dump(bigbuf)
expected := hex.Dump([]byte(test.output))
if have != expected {
t.Errorf("test=%d bufsizes=%d,%d: %q expected, but %q received", ti, consoleReadBufSize, readFileBufSize, expected, have)
continue nextTest
}
bigbuf = append(bigbuf, buf[:n]...)
}
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)
continue nextTest
}
}
}
......
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