addressing PR reviews

This commit is contained in:
Kim Mishra
2023-04-11 16:48:05 -04:00
committed by Eric Daniels
parent 0507093a59
commit bccff100e5
3 changed files with 80 additions and 3 deletions

View File

@@ -0,0 +1,44 @@
package frame
import (
"bytes"
"image/jpeg"
"testing"
)
func TestAddMotionDht(t *testing.T) {
uninitializedHuffmanTableFrame, err := jpeg.Decode(bytes.NewReader(UninitializedHuffmanTable))
// Decode fails with an uninitialized Huffman table error for sample input
expectedErrorMessage := "invalid JPEG format: uninitialized Huffman table"
if err.Error() != expectedErrorMessage {
t.Errorf("Wrong decode error result,\nexpected:\n%+v\ngot:\n%+v", expectedErrorMessage, err)
}
// Decode passes after adding default Huffman table to
defaultHuffmanTableFrame, err := jpeg.Decode(bytes.NewReader(addMotionDht(UninitializedHuffmanTable)))
if err != nil {
t.Errorf("Expected decode function to pass after adding default Huffman table. Failed with %v\n", err)
}
// Adding default Huffman table to a valid frame without a Huffman table changes the table
if uninitializedHuffmanTableFrame == defaultHuffmanTableFrame {
t.Errorf("Expected addMotionDht to update frame. Instead returned original frame")
}
// Check that an improperly constructed frame does not get updated by addMotionDht
randomBytes := []byte{1, 2, 3, 4}
frame1, err := jpeg.Decode(bytes.NewReader(randomBytes))
if err == nil {
t.Errorf("Expected decode function to fail with random bytes but passed.")
}
frame2, err := jpeg.Decode(bytes.NewReader(addMotionDht(randomBytes)))
if err == nil {
t.Errorf("Expected decode function to fail with random bytes but passed.")
}
if frame1 != frame2 {
t.Errorf("addMotionDht updated the frame despite being improperly constructed")
}
}