Chromium Code Reviews| Index: common/recordio/size_test.go |
| diff --git a/common/recordio/size_test.go b/common/recordio/size_test.go |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5376fb8217d112bd90ed2b96efdb59c26d570c40 |
| --- /dev/null |
| +++ b/common/recordio/size_test.go |
| @@ -0,0 +1,48 @@ |
| +// Copyright 2015 The Chromium 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 recordio |
| + |
| +import ( |
| + "bytes" |
| + "fmt" |
| + "testing" |
| + |
| + . "github.com/smartystreets/goconvey/convey" |
| +) |
| + |
| +func TestFrameHeaderSize(t *testing.T) { |
| + t.Parallel() |
| + |
| + Convey(`Testing FrameHeaderSize`, t, func() { |
|
nodir
2016/04/19 23:41:16
I believe this test must use binary.PutUvarint
dnj
2016/04/20 00:45:07
I'm not sure what you mean by "must use"? It indir
nodir
2016/04/20 16:42:57
yeah indeed
|
| + prev := -1 |
| + for i := 0; i < 5; i++ { |
| + base := 1 << uint(7*i) |
| + for delta := range []int{-1, 0, 1} { |
| + base += delta |
| + if base <= prev { |
| + continue |
| + } |
| + prev = base |
| + |
| + Convey(fmt.Sprintf(`Is accurate for buffer size %d.`, base), func() { |
| + data := bytes.Repeat([]byte{0x55}, base) |
| + |
| + amt, err := WriteFrame(devNull{}, data) |
| + if err != nil { |
| + panic(err) |
| + } |
| + |
| + So(amt-len(data), ShouldEqual, FrameHeaderSize(int64(len(data)))) |
| + }) |
| + } |
| + } |
| + }) |
| +} |
| + |
| +type devNull struct{} |
|
nodir
2016/04/19 23:41:17
Use ioutil.Discard
dnj
2016/04/20 00:45:07
Done.
|
| + |
| +func (devNull) Write(d []byte) (int, error) { |
| + return len(d), nil |
| +} |