-
Notifications
You must be signed in to change notification settings - Fork 0
/
exif_test.go
90 lines (68 loc) · 1.85 KB
/
exif_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package exif
import (
"fmt"
"io"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestOpen(t *testing.T) {
exif := New()
// http://www.exif.org/samples/fujifilm-mx1700.jpg
err := exif.Open("_examples/resources/test.jpg")
assert.NoError(t, err)
assert.True(t, len(exif.Tags) > 0)
for key, val := range exif.Tags {
fmt.Printf("%s: %s\n", key, val)
}
}
func TestRead(t *testing.T) {
// http://www.exif.org/samples/fujifilm-mx1700.jpg
exif, err := Read("_examples/resources/test.jpg")
assert.NoError(t, err)
assert.True(t, len(exif.Tags) > 0)
for key, val := range exif.Tags {
fmt.Printf("%s: %s\n", key, val)
}
}
func TestWriteAndParse(t *testing.T) {
exif := New()
// http://www.exif.org/samples/fujifilm-mx1700.jpg
file, err := os.Open("_examples/resources/test.jpg")
assert.NoError(t, err)
defer file.Close()
_, err = io.Copy(exif, file)
assert.Error(t, err)
assert.Equal(t, ErrFoundExifInData, err)
err = exif.Parse()
assert.NoError(t, err)
for key, val := range exif.Tags {
fmt.Printf("%s: %s\n", key, val)
}
}
func TestGetLongitude(t *testing.T) {
exif := New()
err := exif.Open("_examples/resources/testlocation.jpg")
assert.NoError(t, err)
longitude, ok := exif.Tags["Longitude"]
assert.True(t, ok)
assert.Equal(t, "131, 0, 55.2063", longitude)
}
func TestGetLatitude(t *testing.T) {
exif := New()
err := exif.Open("_examples/resources/testlocation.jpg")
assert.NoError(t, err)
latitude, ok := exif.Tags["Latitude"]
assert.True(t, ok)
assert.Equal(t, "25, 21, 32.6101", latitude)
}
func TestBrokenExif(t *testing.T) {
exif := New()
exif.EnableLogging(&LoggingOption{ShowDebugMessage: true, DetailError: true})
file, err := os.Open("_examples/resources/broken_exif.jpg")
assert.NoError(t, err)
defer file.Close()
_, err = io.Copy(exif, file)
assert.Error(t, err)
assert.Equal(t, ErrCorruptData, err)
}