File: lua-test.sh

package info (click to toggle)
geeqie 1%3A2.5-8
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 16,780 kB
  • sloc: cpp: 110,189; xml: 11,497; sh: 3,681; awk: 124; perl: 88; python: 80; makefile: 23
file content (94 lines) | stat: -rwxr-xr-x 3,510 bytes parent folder | download
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
91
92
93
94
#!/bin/sh
#**********************************************************************
# Copyright (C) 2023 - The Geeqie Team
#
# Author: Colin Clark
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#**********************************************************************

## @file
## @brief Run Lua tests
##
## $1 Geeqie executable
##
## Create a basic image and run all lua built-in functions on it.
## The image file and the Lua test file are created within this script.

geeqie_exe="$1"

if [ -z "$XDG_CONFIG_HOME" ]
then
	config_home="$HOME/.config"
else
	config_home="$XDG_CONFIG_HOME"
fi

lua_test_image=$(mktemp --suffix=".jpeg" "${TMPDIR:-/tmp}/geeqie.XXXXXXXXXX")
mkdir -p "$config_home/geeqie/lua/"
lua_test_file=$(mktemp --suffix=".lua" --tmpdir="$config_home/geeqie/lua/" lua-test-XXXXXX)

# Test image generated by:
# convert -size 32x32 xc:white empty.jpg
# exiftool -ISO=200 --printConv empty.jpg
# base64 --wrap=0 empty.jpg > <temp file>
lua_test_image_base64="/9j/4AAQSkZJRgABAQAAAQABAAD/4QCkRXhpZgAATU0AKgAAAAgABQEaAAUAAAABAAAASgEbAAUAAAABAAAAUgEoAAMAAAABAAEAAAITAAMAAAABAAEAAIdpAAQAAAABAAAAWgAAAAAAAAABAAAAAQAAAAEAAAABAAWIJwADAAAAAQDIAACQAAAHAAAABDAyMzKRAQAHAAAABAECAwCgAAAHAAAABDAxMDCgAQADAAAAAf//AAAAAAAA/9sAQwADAgICAgIDAgICAwMDAwQGBAQEBAQIBgYFBgkICgoJCAkJCgwPDAoLDgsJCQ0RDQ4PEBAREAoMEhMSEBMPEBAQ/8AACwgAIAAgAQERAP/EABUAAQEAAAAAAAAAAAAAAAAAAAAJ/8QAFBABAAAAAAAAAAAAAAAAAAAAAP/aAAgBAQAAPwCqYAAAAD//2Q=="
printf "%s" "$lua_test_image_base64" | base64 --decode > "$lua_test_image"

lua_test="path = Image:get_path()
name = Image:get_name()
extension = Image:get_extension()
date = math.floor(Image:get_date())
size = math.floor(Image:get_size())
marks = math.floor(Image:get_marks())
exif_structure = Image:get_exif()
iso = exif_structure:get_datum(\"Exif.Photo.ISOSpeedRatings\")
ret = name..\"\n\"..extension..\"\n\"..path..\"\n\"..date..\"\n\"..size..\"\n\"..marks..\"\n\"..iso
return ret
"
printf  "%s" "$lua_test" > "$lua_test_file"

xvfb-run --auto-servernum "$geeqie_exe" &

# Wait for remote to initialize
while [ ! -e "$config_home/geeqie/.command" ] ;
do
	sleep 1
done

sleep 2

base_lua=$(basename "$lua_test_file")
result=$(xvfb-run --auto-servernum "$geeqie_exe" --remote --lua="$lua_test_image","$base_lua")
xvfb-run --auto-servernum "$geeqie_exe" --remote --quit

## @FIXME Running on GitHub gives additional dbind-WARNINGs. The data required is the last n lines.
result_tail=$(printf "%s" "$result" | tail --lines=7)

expected=$(printf "%s\n.%s\n%s\n%s\n%s\n%s\n%s" "$(basename "$lua_test_image")" jpeg "$lua_test_image" "$(stat -c %Y "$lua_test_image")" "$(stat -c %s "$lua_test_image")" 0 200)

printf "Result                              Expected\n"
printf '%s\n' "$result_tail" "$expected"| pr -2  --omit-header

rm "$lua_test_image"
rm "$lua_test_file"

if [ "$result_tail" = "$expected" ]
then
	exit 0
else
	exit 1
fi