2 #**********************************************************************
3 # Copyright (C) 2023 - The Geeqie Team
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along
18 # with this program; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #**********************************************************************
23 ## @brief Run Lua tests
25 ## $1 Geeqie executable
27 ## Create a basic image and run all lua built-in functions on it.
28 ## The image file and the Lua test file are created within this script.
30 if [ -z "$XDG_CONFIG_HOME" ]
32 config_home="$HOME/.config"
34 config_home="$XDG_CONFIG_HOME"
37 lua_test_image=$(mktemp --suffix=".jpeg" "${TMPDIR:-/tmp}/geeqie.XXXXXXXXXX")
38 mkdir -p "$config_home/geeqie/lua/"
39 lua_test_file=$(mktemp --suffix=".lua" --tmpdir="$config_home/geeqie/lua/" lua-test-XXXXXX)
41 # Test image generated by:
42 # convert -size 32x32 xc:white empty.jpg
43 # exiftool -ISO=200 --printConv empty.jpg
44 # base64 --wrap=0 empty.jpg > <temp file>
45 lua_test_image_base64="/9j/4AAQSkZJRgABAQAAAQABAAD/4QCkRXhpZgAATU0AKgAAAAgABQEaAAUAAAABAAAASgEbAAUAAAABAAAAUgEoAAMAAAABAAEAAAITAAMAAAABAAEAAIdpAAQAAAABAAAAWgAAAAAAAAABAAAAAQAAAAEAAAABAAWIJwADAAAAAQDIAACQAAAHAAAABDAyMzKRAQAHAAAABAECAwCgAAAHAAAABDAxMDCgAQADAAAAAf//AAAAAAAA/9sAQwADAgICAgIDAgICAwMDAwQGBAQEBAQIBgYFBgkICgoJCAkJCgwPDAoLDgsJCQ0RDQ4PEBAREAoMEhMSEBMPEBAQ/8AACwgAIAAgAQERAP/EABUAAQEAAAAAAAAAAAAAAAAAAAAJ/8QAFBABAAAAAAAAAAAAAAAAAAAAAP/aAAgBAQAAPwCqYAAAAD//2Q=="
46 printf "%s" "$lua_test_image_base64" | base64 --decode > "$lua_test_image"
48 lua_test="path = Image:get_path()
49 name = Image:get_name()
50 extension = Image:get_extension()
51 date = math.floor(Image:get_date())
52 size = math.floor(Image:get_size())
53 marks = math.floor(Image:get_marks())
54 exif_structure = Image:get_exif()
55 iso = exif_structure:get_datum(\"Exif.Photo.ISOSpeedRatings\")
56 ret = name..\"\n\"..extension..\"\n\"..path..\"\n\"..date..\"\n\"..size..\"\n\"..marks..\"\n\"..iso
59 printf "%s" "$lua_test" > "$lua_test_file"
61 xvfb-run --auto-servernum "$1" &
63 # Wait for remote to initialize
64 while [ ! -e "$config_home/geeqie/.command" ] ;
71 base_lua=$(basename "$lua_test_file")
72 result=$(xvfb-run --auto-servernum "$1" --remote --lua:"$lua_test_image","$base_lua")
73 xvfb-run --auto-servernum "$1" --remote --quit
75 ## @FIXME Running on GitHub gives additional dbind-WARNINGs. The data required is the last n lines.
76 result_tail=$(printf "%s" "$result" | tail --lines=7)
78 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)
80 printf "Result Expected\n"
81 printf '%s\n' "$result_tail" "$expected"| pr -2 --omit-header
86 if [ "$result_tail" = "$expected" ]