aboutsummaryrefslogtreecommitdiffhomepage
path: root/resources/images/exif/exif_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'resources/images/exif/exif_test.go')
-rw-r--r--resources/images/exif/exif_test.go65
1 files changed, 28 insertions, 37 deletions
diff --git a/resources/images/exif/exif_test.go b/resources/images/exif/exif_test.go
index 64c5a39e3..278bc761a 100644
--- a/resources/images/exif/exif_test.go
+++ b/resources/images/exif/exif_test.go
@@ -15,13 +15,12 @@ package exif
import (
"encoding/json"
- "math/big"
"os"
"path/filepath"
"testing"
"time"
- "github.com/gohugoio/hugo/htesting/hqt"
+ "github.com/bep/imagemeta"
"github.com/google/go-cmp/cmp"
qt "github.com/frankban/quicktest"
@@ -35,11 +34,12 @@ func TestExif(t *testing.T) {
d, err := NewDecoder(IncludeFields("Lens|Date"))
c.Assert(err, qt.IsNil)
- x, err := d.Decode(f)
+ x, err := d.Decode("", imagemeta.JPEG, f)
c.Assert(err, qt.IsNil)
c.Assert(x.Date.Format("2006-01-02"), qt.Equals, "2017-10-27")
// Malaga: https://goo.gl/taazZy
+
c.Assert(x.Lat, qt.Equals, float64(36.59744166666667))
c.Assert(x.Long, qt.Equals, float64(-4.50846))
@@ -49,9 +49,9 @@ func TestExif(t *testing.T) {
c.Assert(ok, qt.Equals, true)
c.Assert(lensModel, qt.Equals, "smc PENTAX-DA* 16-50mm F2.8 ED AL [IF] SDM")
- v, found = x.Tags["DateTime"]
+ v, found = x.Tags["ModifyDate"]
c.Assert(found, qt.Equals, true)
- c.Assert(v, hqt.IsSameType, time.Time{})
+ c.Assert(v, qt.Equals, "2017:11:23 09:56:54")
// Verify that it survives a round-trip to JSON and back.
data, err := json.Marshal(x)
@@ -72,8 +72,8 @@ func TestExifPNG(t *testing.T) {
d, err := NewDecoder()
c.Assert(err, qt.IsNil)
- _, err = d.Decode(f)
- c.Assert(err, qt.Not(qt.IsNil))
+ _, err = d.Decode("", imagemeta.PNG, f)
+ c.Assert(err, qt.IsNil)
}
func TestIssue8079(t *testing.T) {
@@ -85,28 +85,11 @@ func TestIssue8079(t *testing.T) {
d, err := NewDecoder()
c.Assert(err, qt.IsNil)
- x, err := d.Decode(f)
+ x, err := d.Decode("", imagemeta.JPEG, f)
c.Assert(err, qt.IsNil)
c.Assert(x.Tags["ImageDescription"], qt.Equals, "Città del Vaticano #nanoblock #vatican #vaticancity")
}
-func TestNullString(t *testing.T) {
- c := qt.New(t)
-
- for _, test := range []struct {
- in string
- expect string
- }{
- {"foo", "foo"},
- {"\x20", "\x20"},
- {"\xc4\x81", "\xc4\x81"}, // \u0101
- {"\u0160", "\u0160"}, // non-breaking space
- } {
- res := nullString([]byte(test.in))
- c.Assert(res, qt.Equals, test.expect)
- }
-}
-
func BenchmarkDecodeExif(b *testing.B) {
c := qt.New(b)
f, err := os.Open(filepath.FromSlash("../../testdata/sunset.jpg"))
@@ -118,7 +101,7 @@ func BenchmarkDecodeExif(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
- _, err = d.Decode(f)
+ _, err = d.Decode("", imagemeta.JPEG, f)
c.Assert(err, qt.IsNil)
f.Seek(0, 0)
}
@@ -126,8 +109,13 @@ func BenchmarkDecodeExif(b *testing.B) {
var eq = qt.CmpEquals(
cmp.Comparer(
- func(v1, v2 *big.Rat) bool {
- return v1.RatString() == v2.RatString()
+ func(v1, v2 imagemeta.Rat[uint32]) bool {
+ return v1.String() == v2.String()
+ },
+ ),
+ cmp.Comparer(
+ func(v1, v2 imagemeta.Rat[int32]) bool {
+ return v1.String() == v2.String()
},
),
cmp.Comparer(func(v1, v2 time.Time) bool {
@@ -138,14 +126,15 @@ var eq = qt.CmpEquals(
func TestIssue10738(t *testing.T) {
c := qt.New(t)
- testFunc := func(path, include string) any {
+ testFunc := func(c *qt.C, path, include string) any {
+ c.Helper()
f, err := os.Open(filepath.FromSlash(path))
c.Assert(err, qt.IsNil)
defer f.Close()
d, err := NewDecoder(IncludeFields(include))
c.Assert(err, qt.IsNil)
- x, err := d.Decode(f)
+ x, err := d.Decode("", imagemeta.JPEG, f)
c.Assert(err, qt.IsNil)
// Verify that it survives a round-trip to JSON and back.
@@ -194,7 +183,7 @@ func TestIssue10738(t *testing.T) {
include: "Lens|Date|ExposureTime",
}, want{
10,
- 0,
+ 1,
},
},
{
@@ -221,7 +210,7 @@ func TestIssue10738(t *testing.T) {
include: "Lens|Date|ExposureTime",
}, want{
1,
- 0,
+ 1,
},
},
{
@@ -266,7 +255,7 @@ func TestIssue10738(t *testing.T) {
include: "Lens|Date|ExposureTime",
}, want{
30,
- 0,
+ 1,
},
},
{
@@ -293,19 +282,21 @@ func TestIssue10738(t *testing.T) {
include: "Lens|Date|ExposureTime",
}, want{
4,
- 0,
+ 1,
},
},
}
for _, tt := range tests {
c.Run(tt.name, func(c *qt.C) {
- got := testFunc(tt.args.path, tt.args.include)
+ got := testFunc(c, tt.args.path, tt.args.include)
switch v := got.(type) {
case float64:
c.Assert(v, qt.Equals, float64(tt.want.vN))
- case *big.Rat:
- c.Assert(v, eq, big.NewRat(tt.want.vN, tt.want.vD))
+ case imagemeta.Rat[uint32]:
+ r, err := imagemeta.NewRat[uint32](uint32(tt.want.vN), uint32(tt.want.vD))
+ c.Assert(err, qt.IsNil)
+ c.Assert(v, eq, r)
default:
c.Fatalf("unexpected type: %T", got)
}