mirror of
https://git.vectorsigma.ru/public/photoview.git
synced 2026-08-03 20:59:03 +00:00
Add orientation tests. (#1249)
This commit is contained in:
@@ -2,6 +2,7 @@ package periodic_scanner
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -23,7 +24,7 @@ func (m *MockScannerQueue) AddAllToQueue() error {
|
||||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
test_utils.UnitTestRun(m)
|
||||
os.Exit(test_utils.UnitTestRun(m))
|
||||
}
|
||||
|
||||
func resetPeriodicScanner() {
|
||||
|
||||
@@ -54,6 +54,9 @@ func TestFullScan(t *testing.T) {
|
||||
"girl_blond3.jpg",
|
||||
"lilac_lilac_bush_lilac.jpg",
|
||||
"mount_merapi_volcano_indonesia.jpg",
|
||||
|
||||
"left_arrow_normal_web.jpg",
|
||||
"up_arrow_90cw_web.jpg",
|
||||
}
|
||||
wantNonWebPhotos := []string{
|
||||
"heif.heif",
|
||||
@@ -62,6 +65,9 @@ func TestFullScan(t *testing.T) {
|
||||
"raw_with_jpg.tiff",
|
||||
"standalone_raw.tiff",
|
||||
"tiff.tiff",
|
||||
|
||||
"left_arrow_normal_nonweb.tiff",
|
||||
"up_arrow_90cw_nonweb.tiff",
|
||||
}
|
||||
wantWebVideos := []string{
|
||||
"mp4.mp4",
|
||||
@@ -204,6 +210,37 @@ func TestFullScan(t *testing.T) {
|
||||
t.Errorf("all media diff (-got, +want):\n%s", diff)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("CheckPhotosOrientation", func(t *testing.T) {
|
||||
photoFiles := []string{
|
||||
"left_arrow_normal_web.jpg",
|
||||
"up_arrow_90cw_web.jpg",
|
||||
"left_arrow_normal_nonweb.tiff",
|
||||
"up_arrow_90cw_nonweb.tiff",
|
||||
}
|
||||
for _, filename := range photoFiles {
|
||||
var media models.Media
|
||||
if err := db.Preload("MediaURL").Where("title = ?", filename).Find(&media).Error; err != nil {
|
||||
t.Fatalf("can't find media with name %q: %v", filename, err)
|
||||
}
|
||||
|
||||
thumbnail, err := media.GetThumbnail()
|
||||
if err != nil {
|
||||
t.Fatalf("can't get thumbnail of media %q: %v", filename, err)
|
||||
}
|
||||
|
||||
switch {
|
||||
case strings.HasPrefix(filename, "up"):
|
||||
if thumbnail.Width >= thumbnail.Height {
|
||||
t.Errorf("media %q dimension: %dx%d, which should be a vertial photo", filename, thumbnail.Width, thumbnail.Height)
|
||||
}
|
||||
case strings.HasPrefix(filename, "left"):
|
||||
if thumbnail.Width <= thumbnail.Height {
|
||||
t.Errorf("media %q dimension: %dx%d, which should be a horizontal photo", filename, thumbnail.Width, thumbnail.Height)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func equalNameWithoutSuffix(a, b string) bool {
|
||||
|
||||
61
api/scanner/test_media/orient/ensure_test.go
Normal file
61
api/scanner/test_media/orient/ensure_test.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package orient
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/barasher/go-exiftool"
|
||||
"github.com/photoview/photoview/api/test_utils"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
os.Exit(test_utils.UnitTestRun(m))
|
||||
}
|
||||
|
||||
func TestEnsureExifOrient(t *testing.T) {
|
||||
buf := make([]byte, 64*1024)
|
||||
|
||||
et, err := exiftool.NewExiftool(exiftool.NoPrintConversion(), exiftool.Buffer(buf, 64*1024))
|
||||
if err != nil {
|
||||
t.Fatalf("create exiftool error: %v", err)
|
||||
}
|
||||
defer et.Close()
|
||||
|
||||
t.Log("Orientation explaination:")
|
||||
t.Log("1 = Horizontal (normal)")
|
||||
t.Log("2 = Mirror horizontal")
|
||||
t.Log("3 = Rotate 180")
|
||||
t.Log("4 = Mirror vertical")
|
||||
t.Log("5 = Mirror horizontal and rotate 270 CW")
|
||||
t.Log("6 = Rotate 90 CW")
|
||||
t.Log("7 = Mirror horizontal and rotate 90 CW")
|
||||
t.Log("8 = Rotate 270 CW")
|
||||
|
||||
// Test files should be present in the same directory as this test
|
||||
for _, file := range []string{
|
||||
"left_arrow_normal_web.jpg",
|
||||
"up_arrow_90cw_web.jpg",
|
||||
"left_arrow_normal_nonweb.tiff",
|
||||
"up_arrow_90cw_nonweb.tiff",
|
||||
} {
|
||||
meta := et.ExtractMetadata(file)
|
||||
if got, want := len(meta), 1; got != want {
|
||||
t.Fatalf("len(file(%s) meta) = %d, want: %d", file, got, want)
|
||||
}
|
||||
|
||||
got, err := meta[0].GetInt("Orientation")
|
||||
if err != nil {
|
||||
t.Fatalf("get orientation with file %s error: %v", file, err)
|
||||
}
|
||||
|
||||
want := int64(1)
|
||||
if strings.Contains(file, "_90cw_") {
|
||||
want = 6
|
||||
}
|
||||
|
||||
if got != want {
|
||||
t.Errorf("file %q orientation is %d, want: %d", file, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
api/scanner/test_media/orient/left_arrow_normal_nonweb.tiff
Normal file
BIN
api/scanner/test_media/orient/left_arrow_normal_nonweb.tiff
Normal file
Binary file not shown.
BIN
api/scanner/test_media/orient/left_arrow_normal_web.jpg
Normal file
BIN
api/scanner/test_media/orient/left_arrow_normal_web.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
BIN
api/scanner/test_media/orient/up_arrow_90cw_nonweb.tiff
Normal file
BIN
api/scanner/test_media/orient/up_arrow_90cw_nonweb.tiff
Normal file
Binary file not shown.
BIN
api/scanner/test_media/orient/up_arrow_90cw_web.jpg
Normal file
BIN
api/scanner/test_media/orient/up_arrow_90cw_web.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
Reference in New Issue
Block a user