Add tested for undefined-tag types

for/master
Dustin Oprea 2020-01-11 04:34:25 -05:00
parent f72daedddc
commit 7d26e69f8d
5 changed files with 236 additions and 4 deletions

View File

@ -95,7 +95,7 @@ func (Codec8828Oecf) Decode(valueContext *exifcommon.ValueContext) (value Encode
startAt := 4
// offset is our current position.
offset := 4
offset := startAt
currentColumnNumber := uint16(0)

View 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)
}
}

View 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)
}
}

View File

@ -78,8 +78,6 @@ func (CodecExif9101ComponentsConfiguration) Encode(value interface{}, byteOrder
log.Panicf("can only encode a TagExif9101ComponentsConfiguration")
}
// TODO(dustin): Confirm this size against the specification.
return cc.ConfigurationBytes, uint32(len(cc.ConfigurationBytes)), nil
}
@ -96,7 +94,7 @@ func (CodecExif9101ComponentsConfiguration) Decode(valueContext *exifcommon.Valu
log.PanicIf(err)
for configurationId, configurationBytes := range TagUndefinedType_9101_ComponentsConfiguration_Configurations {
if bytes.Compare(valueBytes, configurationBytes) == 0 {
if bytes.Equal(configurationBytes, valueBytes) == true {
cc := TagExif9101ComponentsConfiguration{
ConfigurationId: configurationId,
ConfigurationBytes: valueBytes,

View 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)
}
}