-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add more tests to audioSampleEntry
- Loading branch information
Showing
2 changed files
with
9 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,17 @@ | ||
package mp4 | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
"github.com/Eyevinn/mp4ff/bits" | ||
) | ||
|
||
func TestWriteReadOfAudioSampleEntry(t *testing.T) { | ||
ase := CreateAudioSampleEntryBox("mp4a", 2, 16, 48000, nil) | ||
|
||
// Write to a buffer so that we can read and check | ||
var buf bytes.Buffer | ||
err := ase.Encode(&buf) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// Read back from buffer | ||
encData := buf.Bytes() | ||
encBuf := bytes.NewBuffer(encData) | ||
decodedBox, err := DecodeBox(0, encBuf) | ||
if err != nil { | ||
t.Error("Did not get a box back") | ||
} | ||
outAse := decodedBox.(*AudioSampleEntryBox) | ||
if outAse.SampleRate != ase.SampleRate { | ||
t.Errorf("Out sampled rate %d differs from in %d", outAse.SampleRate, ase.SampleRate) | ||
} | ||
|
||
// Read back from buffer | ||
sr := bits.NewFixedSliceReader(encData) | ||
decodedBoxSR, err := DecodeBoxSR(0, sr) | ||
if err != nil { | ||
t.Error("Did not get a box back") | ||
} | ||
outAse = decodedBoxSR.(*AudioSampleEntryBox) | ||
if outAse.SampleRate != ase.SampleRate { | ||
t.Errorf("Out sampled rate %d differs from in %d for SliceReader", outAse.SampleRate, ase.SampleRate) | ||
ascBytes := []byte{0x11, 0x90} | ||
esds := CreateEsdsBox(ascBytes) | ||
ase := CreateAudioSampleEntryBox("mp4a", 2, 16, 48000, esds) | ||
boxDiffAfterEncodeAndDecode(t, ase) | ||
_, err := ase.RemoveEncryption() | ||
expectedErrMsg := "is not encrypted: mp4a" | ||
if err == nil || err.Error() != expectedErrMsg { | ||
t.Errorf("expected error with message: %q", err.Error()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters