Skip to content

Commit

Permalink
exif: Added test for ParseExifHeader.
Browse files Browse the repository at this point in the history
- Tweaked the test names for correctness.
  • Loading branch information
dsoprea committed Jun 6, 2018
1 parent 32664e6 commit 7fa077b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
Binary file added assets/NDM_8901.jpg.exif
Binary file not shown.
30 changes: 27 additions & 3 deletions exif_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"reflect"

"io/ioutil"
"encoding/binary"

"github.com/dsoprea/go-logging"
)
Expand All @@ -29,7 +30,7 @@ func TestIsExif_False(t *testing.T) {
}
}

func TestVisit(t *testing.T) {
func TestExif_Visit(t *testing.T) {
defer func() {
if state := recover(); state != nil {
err := log.Wrap(state.(error))
Expand Down Expand Up @@ -199,7 +200,7 @@ func TestVisit(t *testing.T) {
}
}

func TestCollect(t *testing.T) {
func TestExif_Collect(t *testing.T) {
defer func() {
if state := recover(); state != nil {
err := log.Wrap(state.(error))
Expand Down Expand Up @@ -335,7 +336,30 @@ func TestCollect(t *testing.T) {
}
}

func TestBuildAndParseExifHeader(t *testing.T) {
func TestExif_ParseExifHeader(t *testing.T) {
filepath := path.Join(assetsPath, "NDM_8901.jpg.exif")

exifData, err := ioutil.ReadFile(filepath)
log.PanicIf(err)

// TODO(dustin): !! We're currently built to expect the JPEG EXIF header-prefix, but our test-data doesn't have that.So, artificially prefix it, for now.
data := make([]byte, len(exifData) + len(ExifHeaderPrefixBytes))
copy(data[0:], ExifHeaderPrefixBytes)
copy(data[len(ExifHeaderPrefixBytes):], exifData)

e := NewExif()

eh, err := e.ParseExifHeader(data)
log.PanicIf(err)

if eh.ByteOrder != binary.LittleEndian {
t.Fatalf("Byte-order of EXIF header not correct.")
} else if eh.FirstIfdOffset != 0x8 {
t.Fatalf("First IFD offset not correct.")
}
}

func TestExif_BuildAndParseExifHeader(t *testing.T) {
headerBytes, err := BuildExifHeader(TestDefaultByteOrder, 0x11223344)
log.PanicIf(err)

Expand Down

0 comments on commit 7fa077b

Please sign in to comment.