Files
monibuca/pkg/util/buffer_test.go
langhuihui 8a9fffb987 refactor: frame converter and mp4 track improvements
- Refactor frame converter implementation
- Update mp4 track to use ICodex
- General refactoring and code improvements

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-28 19:55:37 +08:00

50 lines
838 B
Go

package util
import (
"math/rand"
"testing"
"time"
)
func TestBuffer(t *testing.T) {
t.Run(t.Name(), func(t *testing.T) {
var b Buffer
t.Log(b == nil)
b.Write([]byte{1, 2, 3})
if b == nil {
t.Fail()
} else {
t.Logf("b:% x", b)
}
})
}
func TestReadBytesTo(t *testing.T) {
t.Run(t.Name(), func(t *testing.T) {
s := RandomString(100)
t.Logf("s:%s", s)
var m Memory
m.PushOne([]byte(s))
r := m.NewReader()
seededRand := rand.New(rand.NewSource(time.Now().UnixNano()))
var total []byte
for {
i := seededRand.Intn(10)
if i == 0 {
continue
}
buf := make([]byte, i)
n, _ := r.Read(buf)
t.Logf("n:%d buf:%s", n, string(buf))
total = append(total, buf[:n]...)
if n == 0 {
if string(total) != s {
t.Logf("total:%s", total)
t.Fail()
}
return
}
}
})
}