mirror of
https://github.com/oscar-davids/lpmsdemo.git
synced 2025-12-24 12:37:59 +08:00
91 lines
2.2 KiB
Go
91 lines
2.2 KiB
Go
package ffmpeg
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestTranscoderAPI_InvalidFile(t *testing.T) {
|
|
// Test the following file open results on input: fail, success, fail, success
|
|
|
|
tc := NewTranscoder()
|
|
defer tc.StopTranscoder()
|
|
in := &TranscodeOptionsIn{}
|
|
out := []TranscodeOptions{{
|
|
Oname: "-",
|
|
AudioEncoder: ComponentOptions{Name: "copy"},
|
|
VideoEncoder: ComponentOptions{Name: "drop"},
|
|
Muxer: ComponentOptions{Name: "null"},
|
|
}}
|
|
|
|
// fail # 1
|
|
in.Fname = "none"
|
|
_, err := tc.Transcode(in, out)
|
|
if err == nil || err.Error() != "No such file or directory" {
|
|
t.Error("Expected 'No such file or directory', got ", err)
|
|
}
|
|
|
|
// success # 1
|
|
in.Fname = "../transcoder/test.ts"
|
|
_, err = tc.Transcode(in, out)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
// fail # 2
|
|
in.Fname = "none"
|
|
_, err = tc.Transcode(in, out)
|
|
if err == nil || err.Error() != "No such file or directory" {
|
|
t.Error("Expected 'No such file or directory', got ", err)
|
|
}
|
|
|
|
// success # 2
|
|
in.Fname = "../transcoder/test.ts"
|
|
_, err = tc.Transcode(in, out)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
// Now check invalid output filename
|
|
out[0].Muxer = ComponentOptions{Name: "md5"}
|
|
out[0].Oname = "/not/really/anywhere"
|
|
_, err = tc.Transcode(in, out)
|
|
if err == nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
}
|
|
|
|
func TestTranscoderAPI_Stopped(t *testing.T) {
|
|
|
|
// Test stopped transcoder
|
|
tc := NewTranscoder()
|
|
tc.StopTranscoder()
|
|
in := &TranscodeOptionsIn{}
|
|
_, err := tc.Transcode(in, nil)
|
|
if err != ErrTranscoderStp {
|
|
t.Errorf("Unexpected error; wanted %v but got %v", ErrTranscoderStp, err)
|
|
}
|
|
|
|
// test somehow munged transcoder handle
|
|
tc2 := NewTranscoder()
|
|
tc2.handle = nil // technically this leaks memory ... OK for test
|
|
_, err = tc2.Transcode(in, nil)
|
|
if err != ErrTranscoderStp {
|
|
t.Errorf("Unexpected error; wanted %v but got %v", ErrTranscoderStp, err)
|
|
}
|
|
}
|
|
|
|
func TestTranscoderAPI_TooManyOutputs(t *testing.T) {
|
|
|
|
out := make([]TranscodeOptions, 11)
|
|
for i := range out {
|
|
out[i].VideoEncoder = ComponentOptions{Name: "drop"}
|
|
}
|
|
in := &TranscodeOptionsIn{}
|
|
tc := NewTranscoder()
|
|
_, err := tc.Transcode(in, out)
|
|
if err == nil || err.Error() != "Too many outputs" {
|
|
t.Error("Expected 'Too many outputs', got ", err)
|
|
}
|
|
}
|