...

Source file src/github.com/dsoprea/go-exif/v3/undefined/exif_A302_cfa_pattern_test.go

Documentation: github.com/dsoprea/go-exif/v3/undefined

     1  package exifundefined
     2  
     3  import (
     4  	"bytes"
     5  	"reflect"
     6  	"testing"
     7  
     8  	"github.com/dsoprea/go-logging"
     9  	"github.com/dsoprea/go-utility/v2/filesystem"
    10  
    11  	"github.com/dsoprea/go-exif/v3/common"
    12  )
    13  
    14  func TestTagA302CfaPattern_String(t *testing.T) {
    15  	ut := TagA302CfaPattern{
    16  		HorizontalRepeat: 2,
    17  		VerticalRepeat:   3,
    18  		CfaValue: []byte{
    19  			0, 1, 2, 3, 4, 5,
    20  		},
    21  	}
    22  
    23  	s := ut.String()
    24  
    25  	if s != "TagA302CfaPattern<HORZ-REPEAT=(2) VERT-REPEAT=(3) CFA-VALUE=(6)>" {
    26  		t.Fatalf("String not correct: [%s]", s)
    27  	}
    28  }
    29  
    30  func TestCodecA302CfaPattern_Encode(t *testing.T) {
    31  	ut := TagA302CfaPattern{
    32  		HorizontalRepeat: 2,
    33  		VerticalRepeat:   3,
    34  		CfaValue: []byte{
    35  			0, 1, 2, 3, 4,
    36  			5, 6, 7, 8, 9,
    37  			10, 11, 12, 13, 14,
    38  		},
    39  	}
    40  
    41  	codec := CodecA302CfaPattern{}
    42  
    43  	encoded, unitCount, err := codec.Encode(ut, exifcommon.TestDefaultByteOrder)
    44  	log.PanicIf(err)
    45  
    46  	expectedBytes := []byte{
    47  		0x00, 0x02,
    48  		0x00, 0x03,
    49  		0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
    50  	}
    51  
    52  	if bytes.Equal(encoded, expectedBytes) != true {
    53  		exifcommon.DumpBytesClause(encoded)
    54  
    55  		t.Fatalf("Encoded bytes not correct.")
    56  	} else if unitCount != 19 {
    57  		t.Fatalf("Unit-count not correct: (%d)", unitCount)
    58  	}
    59  }
    60  
    61  func TestCodecA302CfaPattern_Decode(t *testing.T) {
    62  	encoded := []byte{
    63  		0x00, 0x02,
    64  		0x00, 0x03,
    65  		0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
    66  	}
    67  
    68  	addressableBytes := encoded
    69  	sb := rifs.NewSeekableBufferWithBytes(addressableBytes)
    70  
    71  	valueContext := exifcommon.NewValueContext(
    72  		"",
    73  		0,
    74  		uint32(len(encoded)),
    75  		0,
    76  		nil,
    77  		sb,
    78  		exifcommon.TypeUndefined,
    79  		exifcommon.TestDefaultByteOrder)
    80  
    81  	codec := CodecA302CfaPattern{}
    82  
    83  	value, err := codec.Decode(valueContext)
    84  	log.PanicIf(err)
    85  
    86  	expectedValue := TagA302CfaPattern{
    87  		HorizontalRepeat: 2,
    88  		VerticalRepeat:   3,
    89  		CfaValue: []byte{
    90  			0, 1, 2, 3, 4, 5,
    91  		},
    92  	}
    93  
    94  	if reflect.DeepEqual(value, expectedValue) != true {
    95  		t.Fatalf("Decoded value not correct: %s", value)
    96  	}
    97  }
    98  

View as plain text