diff options
| author | Alex Brainman <alex.brainman@gmail.com> | 2016-11-10 13:00:35 +1100 |
|---|---|---|
| committer | Alex Brainman <alex.brainman@gmail.com> | 2016-11-17 07:03:49 +0000 |
| commit | dadfd14babccc30757ddb3f3eb8fbb7cd3bf4b5a (patch) | |
| tree | 1809b1fb7296fee5d109061d01a53b2ec7c726f1 /src | |
| parent | b8d56fdd9379bd5bb89454f3679f01acecd9df4d (diff) | |
| download | go-dadfd14babccc30757ddb3f3eb8fbb7cd3bf4b5a.tar.xz | |
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/33030
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src')
| -rw-r--r-- | src/os/os_windows_test.go | 55 |
1 files changed, 30 insertions, 25 deletions
diff --git a/src/os/os_windows_test.go b/src/os/os_windows_test.go index f03d91517d..91849e50c1 100644 --- a/src/os/os_windows_test.go +++ b/src/os/os_windows_test.go @@ -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 } } } |
