mirror of
https://github.com/langhuihui/monibuca.git
synced 2025-10-05 18:06:51 +08:00

- 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>
50 lines
838 B
Go
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
|
|
}
|
|
}
|
|
})
|
|
}
|