(t *testing.T)
| 15 | ) |
| 16 | |
| 17 | func TestBuilder(t *testing.T) { |
| 18 | r := make([]byte, 4096) |
| 19 | _, err := rand.Read(r) |
| 20 | if err != nil { |
| 21 | t.Fatal(err) |
| 22 | } |
| 23 | wg := sync.WaitGroup{} |
| 24 | wg.Add(4096) |
| 25 | for i := 0; i < 4096; i++ { |
| 26 | go func(exp []byte) { |
| 27 | defer wg.Done() |
| 28 | defer runtime.GC() |
| 29 | data := NewBuilder().WriteBytes(exp).ToBytes() |
| 30 | if !bytes.Equal(data, exp) { |
| 31 | panic(fmt.Sprint("expected ", hex.EncodeToString(exp), |
| 32 | " but got ", hex.EncodeToString(data))) |
| 33 | } |
| 34 | }(r[:i]) |
| 35 | } |
| 36 | wg.Wait() |
| 37 | wg.Add(256) |
| 38 | for i := 0; i < 256; i++ { |
| 39 | go func(exp []byte) { |
| 40 | defer wg.Done() |
| 41 | defer runtime.GC() |
| 42 | time.Sleep(time.Millisecond * time.Duration(mrand.Intn(10)+1)) |
| 43 | data := NewBuilder().WriteBytes(exp).Pack(0x2333) |
| 44 | for i := 0; i < 4096; i++ { |
| 45 | newdata := NewBuilder().WriteBytes(exp).Pack(0x2333) |
| 46 | if !bytes.Equal(data, newdata) { |
| 47 | panic("unexpected") |
| 48 | } |
| 49 | runtime.GC() |
| 50 | } |
| 51 | |
| 52 | }(r[:i]) |
| 53 | } |
| 54 | wg.Wait() |
| 55 | } |
| 56 | |
| 57 | func TestBuilderTEA(t *testing.T) { |
| 58 | k := make([]byte, 16) |
nothing calls this directly
no test coverage detected