diff --git a/v2/undefined/exif_927C_maker_note_test.go b/v2/undefined/exif_927C_maker_note_test.go new file mode 100644 index 0000000..539f60d --- /dev/null +++ b/v2/undefined/exif_927C_maker_note_test.go @@ -0,0 +1,72 @@ +package exifundefined + +import ( + "bytes" + "reflect" + "testing" + + "github.com/dsoprea/go-logging" + + "github.com/dsoprea/go-exif/v2/common" +) + +func TestTag927CMakerNote_String(t *testing.T) { + ut := Tag927CMakerNote{ + MakerNoteType: []byte{0, 1, 2, 3, 4}, + MakerNoteBytes: []byte{5, 6, 7, 8, 9}, + } + + s := ut.String() + if s != "MakerNote" { + t.Fatalf("String not correct: [%s]", s) + } +} + +func TestCodec927CMakerNote_Encode(t *testing.T) { + codec := Codec927CMakerNote{} + + prefix := []byte{0, 1, 2, 3, 4} + b := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9} + + ut := Tag927CMakerNote{ + MakerNoteType: prefix, + MakerNoteBytes: b, + } + + encoded, unitCount, err := codec.Encode(ut, exifcommon.TestDefaultByteOrder) + log.PanicIf(err) + + if bytes.Equal(encoded, b) != true { + t.Fatalf("Encoding not correct: %v", encoded) + } else if unitCount != uint32(len(b)) { + t.Fatalf("Unit-count not correct: (%d)", len(b)) + } +} + +func TestCodec927CMakerNote_Decode(t *testing.T) { + b := []byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9} + + ut := Tag927CMakerNote{ + MakerNoteType: b, + MakerNoteBytes: b, + } + + valueContext := exifcommon.NewValueContext( + "", + 0, + uint32(len(b)), + 0, + nil, + b, + exifcommon.TypeUndefined, + exifcommon.TestDefaultByteOrder) + + codec := Codec927CMakerNote{} + + value, err := codec.Decode(valueContext) + log.PanicIf(err) + + if reflect.DeepEqual(value, ut) != true { + t.Fatalf("Decoded value not correct: %s != %s", value, ut) + } +} diff --git a/v2/undefined/exif_9286_user_comment_test.go b/v2/undefined/exif_9286_user_comment_test.go new file mode 100644 index 0000000..6a88bd4 --- /dev/null +++ b/v2/undefined/exif_9286_user_comment_test.go @@ -0,0 +1,94 @@ +package exifundefined + +import ( + "bytes" + "reflect" + "testing" + + "github.com/dsoprea/go-logging" + + "github.com/dsoprea/go-exif/v2/common" +) + +func TestTag9286UserComment_String(t *testing.T) { + comment := "some comment" + + ut := Tag9286UserComment{ + EncodingType: TagUndefinedType_9286_UserComment_Encoding_ASCII, + EncodingBytes: []byte(comment), + } + + s := ut.String() + if s != "[ASCII] some comment" { + t.Fatalf("String not correct: [%s]", s) + } +} + +func TestCodec9286UserComment_Encode(t *testing.T) { + comment := "some comment" + + ut := Tag9286UserComment{ + EncodingType: TagUndefinedType_9286_UserComment_Encoding_ASCII, + EncodingBytes: []byte(comment), + } + + codec := Codec9286UserComment{} + + encoded, unitCount, err := codec.Encode(ut, exifcommon.TestDefaultByteOrder) + log.PanicIf(err) + + typeBytes := TagUndefinedType_9286_UserComment_Encodings[TagUndefinedType_9286_UserComment_Encoding_ASCII] + if bytes.Equal(encoded[:8], typeBytes) != true { + exifcommon.DumpBytesClause(encoded[:8]) + + t.Fatalf("Encoding type not correct.") + } + + if bytes.Equal(encoded[8:], []byte(comment)) != true { + exifcommon.DumpBytesClause(encoded[8:]) + + t.Fatalf("Encoded comment not correct.") + } + + if unitCount != uint32(len(encoded)) { + t.Fatalf("Unit-couunt not correct: (%d)", unitCount) + } + + exifcommon.DumpBytesClause(encoded) + +} + +func TestCodec9286UserComment_Decode(t *testing.T) { + encoded := []byte{ + 0x41, 0x53, 0x43, 0x49, 0x49, 0x00, 0x00, 0x00, + 0x73, 0x6f, 0x6d, 0x65, 0x20, 0x63, 0x6f, 0x6d, 0x6d, 0x65, 0x6e, 0x74, + } + + addressableBytes := encoded + + valueContext := exifcommon.NewValueContext( + "", + 0, + uint32(len(encoded)), + 0, + nil, + addressableBytes, + exifcommon.TypeUndefined, + exifcommon.TestDefaultByteOrder) + + codec := Codec9286UserComment{} + + decoded, err := codec.Decode(valueContext) + log.PanicIf(err) + + comment := "some comment" + + expectedUt := Tag9286UserComment{ + EncodingType: TagUndefinedType_9286_UserComment_Encoding_ASCII, + EncodingBytes: []byte(comment), + } + + if reflect.DeepEqual(decoded, expectedUt) != true { + t.Fatalf("Decoded struct not correct.") + } +} diff --git a/v2/undefined/exif_A000_flashpix_version_test.go b/v2/undefined/exif_A000_flashpix_version_test.go new file mode 100644 index 0000000..093500e --- /dev/null +++ b/v2/undefined/exif_A000_flashpix_version_test.go @@ -0,0 +1,70 @@ +package exifundefined + +import ( + "bytes" + "reflect" + "testing" + + "github.com/dsoprea/go-logging" + + "github.com/dsoprea/go-exif/v2/common" +) + +func TestTagA000FlashpixVersion_String(t *testing.T) { + versionPhrase := "some version" + + ut := TagA000FlashpixVersion{versionPhrase} + + s := ut.String() + if s != versionPhrase { + t.Fatalf("String not correct: [%s]", s) + } +} + +func TestCodecA000FlashpixVersion_Encode(t *testing.T) { + versionPhrase := "some version" + + ut := TagA000FlashpixVersion{versionPhrase} + + codec := CodecA000FlashpixVersion{} + + encoded, unitCount, err := codec.Encode(ut, exifcommon.TestDefaultByteOrder) + log.PanicIf(err) + + if bytes.Equal(encoded, []byte(versionPhrase)) != true { + exifcommon.DumpBytesClause(encoded) + + t.Fatalf("Encoding not correct.") + } else if unitCount != uint32(len(encoded)) { + t.Fatalf("Unit-couunt not correct: (%d)", unitCount) + } +} + +func TestCodecA000FlashpixVersion_Decode(t *testing.T) { + versionPhrase := "some version" + + expectedUt := TagA000FlashpixVersion{versionPhrase} + + encoded := []byte(versionPhrase) + + addressableBytes := encoded + + valueContext := exifcommon.NewValueContext( + "", + 0, + uint32(len(encoded)), + 0, + nil, + addressableBytes, + exifcommon.TypeUndefined, + exifcommon.TestDefaultByteOrder) + + codec := CodecA000FlashpixVersion{} + + decoded, err := codec.Decode(valueContext) + log.PanicIf(err) + + if reflect.DeepEqual(decoded, expectedUt) != true { + t.Fatalf("Decoded struct not correct.") + } +} diff --git a/v2/undefined/exif_A20C_spatial_frequency_response_test.go b/v2/undefined/exif_A20C_spatial_frequency_response_test.go new file mode 100644 index 0000000..1a92857 --- /dev/null +++ b/v2/undefined/exif_A20C_spatial_frequency_response_test.go @@ -0,0 +1,104 @@ +package exifundefined + +import ( + "bytes" + "reflect" + "testing" + + "github.com/dsoprea/go-logging" + + "github.com/dsoprea/go-exif/v2/common" +) + +func TestTagA20CSpatialFrequencyResponse_String(t *testing.T) { + ut := TagA20CSpatialFrequencyResponse{ + Columns: 2, + Rows: 9, + ColumnNames: []string{"column1", "column2"}, + Values: []exifcommon.Rational{ + exifcommon.Rational{1, 2}, + exifcommon.Rational{3, 4}, + }, + } + + s := ut.String() + if s != "CodecA20CSpatialFrequencyResponse" { + t.Fatalf("String not correct: [%s]", s) + } +} + +func TestCodecA20CSpatialFrequencyResponse_Encode(t *testing.T) { + ut := TagA20CSpatialFrequencyResponse{ + Columns: 2, + Rows: 9, + ColumnNames: []string{"column1", "column2"}, + Values: []exifcommon.Rational{ + exifcommon.Rational{1, 2}, + exifcommon.Rational{3, 4}, + }, + } + + codec := CodecA20CSpatialFrequencyResponse{} + + encoded, unitCount, err := codec.Encode(ut, exifcommon.TestDefaultByteOrder) + log.PanicIf(err) + + expectedEncoded := []byte{ + 0x00, 0x02, + 0x00, 0x09, + 0x63, 0x6f, 0x6c, 0x75, 0x6d, 0x6e, 0x31, 0x00, + 0x63, 0x6f, 0x6c, 0x75, 0x6d, 0x6e, 0x32, 0x00, + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, + 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, + } + + if bytes.Equal(encoded, expectedEncoded) != true { + exifcommon.DumpBytesClause(encoded) + + t.Fatalf("Encoding not correct.") + } else if unitCount != uint32(len(encoded)) { + t.Fatalf("Unit-couunt not correct: (%d)", unitCount) + } +} + +func TestCodecA20CSpatialFrequencyResponse_Decode(t *testing.T) { + expectedUt := TagA20CSpatialFrequencyResponse{ + Columns: 2, + Rows: 9, + ColumnNames: []string{"column1", "column2"}, + Values: []exifcommon.Rational{ + exifcommon.Rational{1, 2}, + exifcommon.Rational{3, 4}, + }, + } + + encoded := []byte{ + 0x00, 0x02, + 0x00, 0x09, + 0x63, 0x6f, 0x6c, 0x75, 0x6d, 0x6e, 0x31, 0x00, + 0x63, 0x6f, 0x6c, 0x75, 0x6d, 0x6e, 0x32, 0x00, + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, + 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, + } + + addressableBytes := encoded + + valueContext := exifcommon.NewValueContext( + "", + 0, + uint32(len(encoded)), + 0, + nil, + addressableBytes, + exifcommon.TypeUndefined, + exifcommon.TestDefaultByteOrder) + + codec := CodecA20CSpatialFrequencyResponse{} + + decoded, err := codec.Decode(valueContext) + log.PanicIf(err) + + if reflect.DeepEqual(decoded, expectedUt) != true { + t.Fatalf("Decoded struct not correct.") + } +} diff --git a/v2/undefined/exif_A300_file_source.go b/v2/undefined/exif_A300_file_source.go index 2f5914d..3f8e6ea 100644 --- a/v2/undefined/exif_A300_file_source.go +++ b/v2/undefined/exif_A300_file_source.go @@ -17,7 +17,7 @@ func (TagExifA300FileSource) EncoderName() string { } func (af TagExifA300FileSource) String() string { - return fmt.Sprintf("%d", af) + return fmt.Sprintf("0x%08x", uint32(af)) } const ( diff --git a/v2/undefined/exif_A300_file_source_test.go b/v2/undefined/exif_A300_file_source_test.go new file mode 100644 index 0000000..6ed3a73 --- /dev/null +++ b/v2/undefined/exif_A300_file_source_test.go @@ -0,0 +1,66 @@ +package exifundefined + +import ( + "bytes" + "reflect" + "testing" + + "github.com/dsoprea/go-logging" + + "github.com/dsoprea/go-exif/v2/common" +) + +func TestTagExifA300FileSource_String(t *testing.T) { + ut := TagExifA300FileSource(0x1234) + + s := ut.String() + if s != "0x00001234" { + t.Fatalf("String not correct: [%s]", s) + } +} + +func TestCodecExifA300FileSource_Encode(t *testing.T) { + ut := TagExifA300FileSource(0x1234) + + codec := CodecExifA300FileSource{} + + encoded, unitCount, err := codec.Encode(ut, exifcommon.TestDefaultByteOrder) + log.PanicIf(err) + + expectedEncoded := []byte{0, 0, 0x12, 0x34} + + if bytes.Equal(encoded, expectedEncoded) != true { + exifcommon.DumpBytesClause(encoded) + + t.Fatalf("Encoding not correct.") + } else if unitCount != 1 { + t.Fatalf("Unit-couunt not correct: (%d)", unitCount) + } +} + +func TestCodecExifA300FileSource_Decode(t *testing.T) { + expectedUt := TagExifA300FileSource(0x1234) + + encoded := []byte{0, 0, 0x12, 0x34} + + rawValueOffset := encoded + + valueContext := exifcommon.NewValueContext( + "", + 0, + 1, + 0, + rawValueOffset, + nil, + exifcommon.TypeUndefined, + exifcommon.TestDefaultByteOrder) + + codec := CodecExifA300FileSource{} + + decoded, err := codec.Decode(valueContext) + log.PanicIf(err) + + if reflect.DeepEqual(decoded, expectedUt) != true { + t.Fatalf("Decoded struct not correct.") + } +}