123456789101112131415161718192021222324252627282930313233343536 |
- package main
- import (
- "io"
- "testing"
- )
- func TestSizableZeroReader(t *testing.T) {
- t.Log("Testng for SizableZeroReader...")
- TestingRead(t, 0)
- TestingRead(t, 1)
- TestingRead(t, 1024)
- TestingRead(t, 114514)
- TestingRead(t, 1919810)
- t.Log("Test SizableZeroReader OK.")
- }
- func TestingRead(t *testing.T, sz int) {
- rd := NewSizableZeroReader(sz)
- bin, err := io.ReadAll(rd)
- if err != nil {
- t.Errorf("failed test with size %d: %v", sz, err)
- return
- }
- l := len(bin)
- if l != sz {
- t.Errorf("length not match: realSize=%d, expectSize=%d", l, sz)
- return
- }
- for _, v := range bin {
- if v != 0 {
- t.Errorf("some value not zero")
- return
- }
- }
- }
|