GetVideoFrame test for valid input, invalid path and out-of-range frame index
This commit is contained in:
parent
fd5137064c
commit
1813715282
2 changed files with 66 additions and 0 deletions
66
frame_test.go
Normal file
66
frame_test.go
Normal file
|
@ -0,0 +1,66 @@
|
|||
package vidio
|
||||
|
||||
import (
|
||||
"image/png"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGetFrameShouldReturnErrorOnInvalidFilePath(t *testing.T) {
|
||||
path := "test/koala-video-not-present.mp4"
|
||||
|
||||
frame, err := GetVideoFrame(path, 2)
|
||||
|
||||
if frame != nil {
|
||||
t.Errorf("Frame was expected to be nil")
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
t.Error("Error was expected to not be nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetFrameShouldReturnErrorOnOutOfRangeFrame(t *testing.T) {
|
||||
path := "test/koala.mp4"
|
||||
framesCount := 101
|
||||
|
||||
frame, err := GetVideoFrame(path, framesCount+1)
|
||||
|
||||
if frame != nil {
|
||||
t.Error("Frames was expected to be nil")
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
t.Error("Error was expected to not be nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetFrameShouldReturnCorrectFrame(t *testing.T) {
|
||||
path := "test/koala.mp4"
|
||||
|
||||
expectedFrameFile, _ := os.Open("test/koala-frame5.png")
|
||||
defer expectedFrameFile.Close()
|
||||
|
||||
expectedFrame, _ := png.Decode(expectedFrameFile)
|
||||
|
||||
actualFrame, err := GetVideoFrame(path, 5)
|
||||
|
||||
if actualFrame == nil {
|
||||
t.Error("Frame was expected to not be nil")
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
t.Error("Error was expected to be nil")
|
||||
}
|
||||
|
||||
for xIndex := 0; xIndex < expectedFrame.Bounds().Dx(); xIndex += 1 {
|
||||
for yIndex := 0; yIndex < expectedFrame.Bounds().Dy(); yIndex += 1 {
|
||||
eR, eG, eB, eA := expectedFrame.At(xIndex, yIndex).RGBA()
|
||||
aR, aG, aB, aA := actualFrame.At(xIndex, yIndex).RGBA()
|
||||
|
||||
if eR != aR || eG != aG || eB != aB || eA != aA {
|
||||
t.Error("The expected and actual frames were expected to be equal")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
BIN
test/koala-frame5.png
Normal file
BIN
test/koala-frame5.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 250 KiB |
Loading…
Add table
Add a link
Reference in a new issue