...

Source file src/github.com/dsoprea/go-exif/v3/common/utility_test.go

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

     1  package exifcommon
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  	"time"
     7  
     8  	"github.com/dsoprea/go-logging"
     9  )
    10  
    11  func TestDumpBytes(t *testing.T) {
    12  	DumpBytes([]byte{1, 2, 3, 4})
    13  }
    14  
    15  func TestDumpBytesClause(t *testing.T) {
    16  	DumpBytesClause([]byte{1, 2, 3, 4})
    17  }
    18  
    19  func TestDumpBytesToString(t *testing.T) {
    20  	s := DumpBytesToString([]byte{1, 2, 3, 4})
    21  	if s != "01 02 03 04" {
    22  		t.Fatalf("String not correct: [%s]", s)
    23  	}
    24  }
    25  
    26  func TestDumpBytesClauseToString(t *testing.T) {
    27  	s := DumpBytesClauseToString([]byte{1, 2, 3, 4})
    28  	if s != "0x01, 0x02, 0x03, 0x04" {
    29  		t.Fatalf("Stringified clause is not correct: [%s]", s)
    30  	}
    31  }
    32  
    33  func TestExifFullTimestampString(t *testing.T) {
    34  	originalPhrase := "2018:11:30 13:01:49"
    35  
    36  	timestamp, err := ParseExifFullTimestamp(originalPhrase)
    37  	log.PanicIf(err)
    38  
    39  	restoredPhrase := ExifFullTimestampString(timestamp)
    40  	if restoredPhrase != originalPhrase {
    41  		t.Fatalf("Final phrase [%s] does not equal original phrase [%s]", restoredPhrase, originalPhrase)
    42  	}
    43  }
    44  
    45  func ExampleExifFullTimestampString() {
    46  	originalPhrase := "2018:11:30 13:01:49"
    47  
    48  	timestamp, err := ParseExifFullTimestamp(originalPhrase)
    49  	log.PanicIf(err)
    50  
    51  	restoredPhrase := ExifFullTimestampString(timestamp)
    52  	fmt.Printf("To EXIF timestamp: [%s]\n", restoredPhrase)
    53  
    54  	// Output:
    55  	// To EXIF timestamp: [2018:11:30 13:01:49]
    56  }
    57  
    58  func TestParseExifFullTimestamp(t *testing.T) {
    59  	timestamp, err := ParseExifFullTimestamp("2018:11:30 13:01:49")
    60  	log.PanicIf(err)
    61  
    62  	actual := timestamp.Format(time.RFC3339)
    63  	expected := "2018-11-30T13:01:49Z"
    64  
    65  	if actual != expected {
    66  		t.Fatalf("time not formatted correctly: [%s] != [%s]", actual, expected)
    67  	}
    68  }
    69  
    70  func ExampleParseExifFullTimestamp() {
    71  	originalPhrase := "2018:11:30 13:01:49"
    72  
    73  	timestamp, err := ParseExifFullTimestamp(originalPhrase)
    74  	log.PanicIf(err)
    75  
    76  	fmt.Printf("To Go timestamp: [%s]\n", timestamp.Format(time.RFC3339))
    77  
    78  	// Output:
    79  	// To Go timestamp: [2018-11-30T13:01:49Z]
    80  }
    81  

View as plain text