mirror of
https://github.com/dsoprea/go-exif.git
synced 2025-05-31 11:41:57 +00:00
Add tested for undefined-tag types
This commit is contained in:
parent
f72daedddc
commit
7d26e69f8d
@ -95,7 +95,7 @@ func (Codec8828Oecf) Decode(valueContext *exifcommon.ValueContext) (value Encode
|
|||||||
startAt := 4
|
startAt := 4
|
||||||
|
|
||||||
// offset is our current position.
|
// offset is our current position.
|
||||||
offset := 4
|
offset := startAt
|
||||||
|
|
||||||
currentColumnNumber := uint16(0)
|
currentColumnNumber := uint16(0)
|
||||||
|
|
||||||
|
88
v2/undefined/exif_8828_oecf_test.go
Normal file
88
v2/undefined/exif_8828_oecf_test.go
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
package exifundefined
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/dsoprea/go-logging"
|
||||||
|
|
||||||
|
"github.com/dsoprea/go-exif/v2/common"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestTag8828Oecf_String(t *testing.T) {
|
||||||
|
ut := Tag8828Oecf{
|
||||||
|
Columns: 11,
|
||||||
|
Rows: 22,
|
||||||
|
}
|
||||||
|
|
||||||
|
s := ut.String()
|
||||||
|
|
||||||
|
if s != "Tag8828Oecf<COLUMNS=(11) ROWS=(22)>" {
|
||||||
|
t.Fatalf("String not correct: [%s]", s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCodec8828Oecf_Encode(t *testing.T) {
|
||||||
|
ut := Tag8828Oecf{
|
||||||
|
Columns: 2,
|
||||||
|
Rows: 22,
|
||||||
|
ColumnNames: []string{"aa", "bb"},
|
||||||
|
Values: []exifcommon.SignedRational{exifcommon.SignedRational{11, 22}},
|
||||||
|
}
|
||||||
|
|
||||||
|
codec := Codec8828Oecf{}
|
||||||
|
|
||||||
|
encoded, unitCount, err := codec.Encode(ut, exifcommon.TestDefaultByteOrder)
|
||||||
|
log.PanicIf(err)
|
||||||
|
|
||||||
|
expectedBytes := []byte{
|
||||||
|
0x00, 0x02,
|
||||||
|
0x00, 0x16,
|
||||||
|
0x61, 0x61, 0x00, 0x62, 0x62, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x16}
|
||||||
|
|
||||||
|
if bytes.Equal(encoded, expectedBytes) != true {
|
||||||
|
exifcommon.DumpBytesClause(encoded)
|
||||||
|
|
||||||
|
t.Fatalf("Encoded bytes not correct.")
|
||||||
|
} else if unitCount != 18 {
|
||||||
|
t.Fatalf("Unit-count not correct: (%d)", unitCount)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCodec8828Oecf_Decode(t *testing.T) {
|
||||||
|
encoded := []byte{
|
||||||
|
0x00, 0x02,
|
||||||
|
0x00, 0x16,
|
||||||
|
0x61, 0x61, 0x00, 0x62, 0x62, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x16}
|
||||||
|
|
||||||
|
addressableData := encoded
|
||||||
|
|
||||||
|
valueContext := exifcommon.NewValueContext(
|
||||||
|
"",
|
||||||
|
0,
|
||||||
|
uint32(len(encoded)),
|
||||||
|
0,
|
||||||
|
nil,
|
||||||
|
addressableData,
|
||||||
|
exifcommon.TypeUndefined,
|
||||||
|
exifcommon.TestDefaultByteOrder)
|
||||||
|
|
||||||
|
codec := Codec8828Oecf{}
|
||||||
|
|
||||||
|
value, err := codec.Decode(valueContext)
|
||||||
|
log.PanicIf(err)
|
||||||
|
|
||||||
|
expectedValue := Tag8828Oecf{
|
||||||
|
Columns: 2,
|
||||||
|
Rows: 22,
|
||||||
|
ColumnNames: []string{"aa", "bb"},
|
||||||
|
Values: []exifcommon.SignedRational{exifcommon.SignedRational{11, 22}},
|
||||||
|
}
|
||||||
|
|
||||||
|
if reflect.DeepEqual(value, expectedValue) != true {
|
||||||
|
t.Fatalf("Decoded value not correct: %s", value)
|
||||||
|
}
|
||||||
|
}
|
64
v2/undefined/exif_9000_exif_version_test.go
Normal file
64
v2/undefined/exif_9000_exif_version_test.go
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
package exifundefined
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/dsoprea/go-logging"
|
||||||
|
|
||||||
|
"github.com/dsoprea/go-exif/v2/common"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestTag9000ExifVersion_String(t *testing.T) {
|
||||||
|
ut := Tag9000ExifVersion{"abc"}
|
||||||
|
s := ut.String()
|
||||||
|
|
||||||
|
if s != "abc" {
|
||||||
|
t.Fatalf("String not correct: [%s]", s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCodec9000ExifVersion_Encode(t *testing.T) {
|
||||||
|
s := "abc"
|
||||||
|
ut := Tag9000ExifVersion{s}
|
||||||
|
|
||||||
|
codec := Codec9000ExifVersion{}
|
||||||
|
|
||||||
|
encoded, unitCount, err := codec.Encode(ut, exifcommon.TestDefaultByteOrder)
|
||||||
|
log.PanicIf(err)
|
||||||
|
|
||||||
|
if bytes.Equal(encoded, []byte(s)) != true {
|
||||||
|
t.Fatalf("Encoded bytes not correct: %v", encoded)
|
||||||
|
} else if unitCount != uint32(len(s)) {
|
||||||
|
t.Fatalf("Unit-count not correct: (%d)", unitCount)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCodec9000ExifVersion_Decode(t *testing.T) {
|
||||||
|
s := "abc"
|
||||||
|
ut := Tag9000ExifVersion{s}
|
||||||
|
|
||||||
|
encoded := []byte(s)
|
||||||
|
|
||||||
|
rawValueOffset := encoded
|
||||||
|
|
||||||
|
valueContext := exifcommon.NewValueContext(
|
||||||
|
"",
|
||||||
|
0,
|
||||||
|
uint32(len(encoded)),
|
||||||
|
0,
|
||||||
|
rawValueOffset,
|
||||||
|
nil,
|
||||||
|
exifcommon.TypeUndefined,
|
||||||
|
exifcommon.TestDefaultByteOrder)
|
||||||
|
|
||||||
|
codec := Codec9000ExifVersion{}
|
||||||
|
|
||||||
|
value, err := codec.Decode(valueContext)
|
||||||
|
log.PanicIf(err)
|
||||||
|
|
||||||
|
if reflect.DeepEqual(value, ut) != true {
|
||||||
|
t.Fatalf("Decoded value not correct: %s\n", value)
|
||||||
|
}
|
||||||
|
}
|
@ -78,8 +78,6 @@ func (CodecExif9101ComponentsConfiguration) Encode(value interface{}, byteOrder
|
|||||||
log.Panicf("can only encode a TagExif9101ComponentsConfiguration")
|
log.Panicf("can only encode a TagExif9101ComponentsConfiguration")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(dustin): Confirm this size against the specification.
|
|
||||||
|
|
||||||
return cc.ConfigurationBytes, uint32(len(cc.ConfigurationBytes)), nil
|
return cc.ConfigurationBytes, uint32(len(cc.ConfigurationBytes)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,7 +94,7 @@ func (CodecExif9101ComponentsConfiguration) Decode(valueContext *exifcommon.Valu
|
|||||||
log.PanicIf(err)
|
log.PanicIf(err)
|
||||||
|
|
||||||
for configurationId, configurationBytes := range TagUndefinedType_9101_ComponentsConfiguration_Configurations {
|
for configurationId, configurationBytes := range TagUndefinedType_9101_ComponentsConfiguration_Configurations {
|
||||||
if bytes.Compare(valueBytes, configurationBytes) == 0 {
|
if bytes.Equal(configurationBytes, valueBytes) == true {
|
||||||
cc := TagExif9101ComponentsConfiguration{
|
cc := TagExif9101ComponentsConfiguration{
|
||||||
ConfigurationId: configurationId,
|
ConfigurationId: configurationId,
|
||||||
ConfigurationBytes: valueBytes,
|
ConfigurationBytes: valueBytes,
|
||||||
|
82
v2/undefined/exif_9101_components_configuration_test.go
Normal file
82
v2/undefined/exif_9101_components_configuration_test.go
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
package exifundefined
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/dsoprea/go-logging"
|
||||||
|
|
||||||
|
"github.com/dsoprea/go-exif/v2/common"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestTagExif9101ComponentsConfiguration_String(t *testing.T) {
|
||||||
|
ut := TagExif9101ComponentsConfiguration{
|
||||||
|
ConfigurationId: TagUndefinedType_9101_ComponentsConfiguration_RGB,
|
||||||
|
ConfigurationBytes: []byte{0x11, 0x22, 0x33, 0x44},
|
||||||
|
}
|
||||||
|
|
||||||
|
s := ut.String()
|
||||||
|
|
||||||
|
if s != "Exif9101ComponentsConfiguration<ID=[RGB] BYTES=[17 34 51 68]>" {
|
||||||
|
t.Fatalf("String not correct: [%s]", s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCodecExif9101ComponentsConfiguration_Encode(t *testing.T) {
|
||||||
|
configurationBytes := []byte(TagUndefinedType_9101_ComponentsConfiguration_Names[TagUndefinedType_9101_ComponentsConfiguration_RGB])
|
||||||
|
|
||||||
|
ut := TagExif9101ComponentsConfiguration{
|
||||||
|
ConfigurationId: TagUndefinedType_9101_ComponentsConfiguration_RGB,
|
||||||
|
ConfigurationBytes: configurationBytes,
|
||||||
|
}
|
||||||
|
|
||||||
|
codec := CodecExif9101ComponentsConfiguration{}
|
||||||
|
|
||||||
|
encoded, unitCount, err := codec.Encode(ut, exifcommon.TestDefaultByteOrder)
|
||||||
|
log.PanicIf(err)
|
||||||
|
|
||||||
|
if bytes.Equal(encoded, configurationBytes) != true {
|
||||||
|
exifcommon.DumpBytesClause(encoded)
|
||||||
|
|
||||||
|
t.Fatalf("Encoded bytes not correct: %v", encoded)
|
||||||
|
} else if unitCount != uint32(len(configurationBytes)) {
|
||||||
|
t.Fatalf("Unit-count not correct: (%d)", unitCount)
|
||||||
|
}
|
||||||
|
|
||||||
|
s := string(configurationBytes)
|
||||||
|
|
||||||
|
if s != TagUndefinedType_9101_ComponentsConfiguration_Names[TagUndefinedType_9101_ComponentsConfiguration_RGB] {
|
||||||
|
t.Fatalf("Recovered configuration name not correct: [%s]", s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCodecExif9101ComponentsConfiguration_Decode(t *testing.T) {
|
||||||
|
configurationBytes := TagUndefinedType_9101_ComponentsConfiguration_Configurations[TagUndefinedType_9101_ComponentsConfiguration_RGB]
|
||||||
|
|
||||||
|
ut := TagExif9101ComponentsConfiguration{
|
||||||
|
ConfigurationId: TagUndefinedType_9101_ComponentsConfiguration_RGB,
|
||||||
|
ConfigurationBytes: configurationBytes,
|
||||||
|
}
|
||||||
|
|
||||||
|
rawValueOffset := configurationBytes
|
||||||
|
|
||||||
|
valueContext := exifcommon.NewValueContext(
|
||||||
|
"",
|
||||||
|
0,
|
||||||
|
uint32(len(configurationBytes)),
|
||||||
|
0,
|
||||||
|
rawValueOffset,
|
||||||
|
nil,
|
||||||
|
exifcommon.TypeUndefined,
|
||||||
|
exifcommon.TestDefaultByteOrder)
|
||||||
|
|
||||||
|
codec := CodecExif9101ComponentsConfiguration{}
|
||||||
|
|
||||||
|
value, err := codec.Decode(valueContext)
|
||||||
|
log.PanicIf(err)
|
||||||
|
|
||||||
|
if reflect.DeepEqual(value, ut) != true {
|
||||||
|
t.Fatalf("Decoded value not correct: %s != %s\n", value, ut)
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user