-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ifd_enumerate_test.go: Moved and refactored some ITEVR tests to be fo…
…r ValueContext instead Per our recent change to deimplement ITEVRs. - ifd_enumerate_test.go: Fixed some test naming. - ifd_builder_test.go: Dropped some now-unnecessary implementations of ITEVRs.
- Loading branch information
Showing
5 changed files
with
136 additions
and
121 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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package exif | ||
|
||
import ( | ||
"bytes" | ||
"path" | ||
"testing" | ||
|
||
"github.com/dsoprea/go-logging" | ||
) | ||
|
||
func TestValueContext_ReadAscii(t *testing.T) { | ||
defer func() { | ||
if state := recover(); state != nil { | ||
err := log.Wrap(state.(error)) | ||
log.PrintErrorf(err, "Test failure.") | ||
} | ||
}() | ||
|
||
filepath := path.Join(assetsPath, "NDM_8901.jpg") | ||
|
||
rawExif, err := SearchFileAndExtractExif(filepath) | ||
log.PanicIf(err) | ||
|
||
im := NewIfdMapping() | ||
|
||
err = LoadStandardIfds(im) | ||
log.PanicIf(err) | ||
|
||
ti := NewTagIndex() | ||
|
||
_, index, err := Collect(im, ti, rawExif) | ||
log.PanicIf(err) | ||
|
||
ifd := index.RootIfd | ||
|
||
var ite *IfdTagEntry | ||
for _, thisIte := range ifd.Entries { | ||
if thisIte.TagId == 0x0110 { | ||
ite = thisIte | ||
break | ||
} | ||
} | ||
|
||
if ite == nil { | ||
t.Fatalf("Tag not found.") | ||
} | ||
|
||
valueContext := ifd.GetValueContext(ite) | ||
|
||
decodedString, err := valueContext.ReadAscii() | ||
log.PanicIf(err) | ||
|
||
decodedBytes := []byte(decodedString) | ||
|
||
expected := []byte("Canon EOS 5D Mark III") | ||
|
||
if bytes.Compare(decodedBytes, expected) != 0 { | ||
t.Fatalf("Decoded bytes not correct.") | ||
} | ||
} | ||
|
||
func TestValueContext_Undefined(t *testing.T) { | ||
defer func() { | ||
if state := recover(); state != nil { | ||
err := log.Wrap(state.(error)) | ||
log.PrintErrorf(err, "Test failure.") | ||
} | ||
}() | ||
|
||
filepath := path.Join(assetsPath, "NDM_8901.jpg") | ||
|
||
rawExif, err := SearchFileAndExtractExif(filepath) | ||
log.PanicIf(err) | ||
|
||
im := NewIfdMapping() | ||
|
||
err = LoadStandardIfds(im) | ||
log.PanicIf(err) | ||
|
||
ti := NewTagIndex() | ||
|
||
_, index, err := Collect(im, ti, rawExif) | ||
log.PanicIf(err) | ||
|
||
ifdExif := index.Lookup[IfdPathStandardExif][0] | ||
|
||
var ite *IfdTagEntry | ||
for _, thisIte := range ifdExif.Entries { | ||
if thisIte.TagId == 0x9000 { | ||
ite = thisIte | ||
break | ||
} | ||
} | ||
|
||
if ite == nil { | ||
t.Fatalf("Tag not found.") | ||
} | ||
|
||
valueContext := ifdExif.GetValueContext(ite) | ||
|
||
value, err := valueContext.Undefined() | ||
log.PanicIf(err) | ||
|
||
gs, ok := value.(TagUnknownType_GeneralString) | ||
if ok != true { | ||
t.Fatalf("Undefined value not processed correctly.") | ||
} | ||
|
||
decodedBytes, err := gs.ValueBytes() | ||
log.PanicIf(err) | ||
|
||
expected := []byte("0230") | ||
|
||
if bytes.Compare(decodedBytes, expected) != 0 { | ||
t.Fatalf("Decoded bytes not correct.") | ||
} | ||
} |