939a024ad2717566f6f3e3a44e309f2a5eb89e76
[geeqie.git] / scripts / lua-test.sh
1 #!/bin/sh
2 #**********************************************************************
3 # Copyright (C) 2023 - The Geeqie Team
4 #
5 # Author: Colin Clark
6 #
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.
11 #
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.
16 #
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 #**********************************************************************
21
22 ## @file
23 ## @brief Run Lua tests
24 ##
25 ## $1 Geeqie executable
26 ##
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.
29
30 lua_test_image=$(mktemp --suffix=".jpeg" "${TMPDIR:-/tmp}/geeqie.XXXXXXXXXX")
31 mkdir -p "$HOME/.config/geeqie/lua/"
32 lua_test_file=$(mktemp --suffix=".lua" --tmpdir="$HOME/.config/geeqie/lua/" lua-test-XXXXXX)
33
34 # Test image generated by:
35 # convert -size 32x32 xc:white empty.jpg
36 # exiftool -ISO=200 --printConv empty.jpg
37 # base64 --wrap=0 empty.jpg > <temp file>
38 lua_test_image_base64="/9j/4AAQSkZJRgABAQAAAQABAAD/4QCkRXhpZgAATU0AKgAAAAgABQEaAAUAAAABAAAASgEbAAUAAAABAAAAUgEoAAMAAAABAAEAAAITAAMAAAABAAEAAIdpAAQAAAABAAAAWgAAAAAAAAABAAAAAQAAAAEAAAABAAWIJwADAAAAAQDIAACQAAAHAAAABDAyMzKRAQAHAAAABAECAwCgAAAHAAAABDAxMDCgAQADAAAAAf//AAAAAAAA/9sAQwADAgICAgIDAgICAwMDAwQGBAQEBAQIBgYFBgkICgoJCAkJCgwPDAoLDgsJCQ0RDQ4PEBAREAoMEhMSEBMPEBAQ/8AACwgAIAAgAQERAP/EABUAAQEAAAAAAAAAAAAAAAAAAAAJ/8QAFBABAAAAAAAAAAAAAAAAAAAAAP/aAAgBAQAAPwCqYAAAAD//2Q=="
39 printf "%s" "$lua_test_image_base64" | base64 --decode > "$lua_test_image"
40
41 lua_test="path = Image:get_path()
42 name = Image:get_name()
43 extension = Image:get_extension()
44 date = math.floor(Image:get_date())
45 size = math.floor(Image:get_size())
46 marks = math.floor(Image:get_marks())
47 exif_structure = Image:get_exif()
48 iso = exif_structure:get_datum(\"Exif.Photo.ISOSpeedRatings\")
49 ret = name..\"\n\"..extension..\"\n\"..path..\"\n\"..date..\"\n\"..size..\"\n\"..marks..\"\n\"..iso
50 return ret
51 "
52 printf  "%s" "$lua_test" > "$lua_test_file"
53
54 xvfb-run --auto-servernum "$1" &
55
56 # Wait for remote to initialize
57 while [ ! -e "$HOME/.config/geeqie/.command" ] ;
58 do
59         sleep 1
60 done
61
62 sleep 2
63
64 base_lua=$(basename "$lua_test_file")
65 result=$(xvfb-run --auto-servernum "$1" --remote --lua:"$lua_test_image","$base_lua")
66 xvfb-run --auto-servernum "$1" --remote --quit
67
68 ## @FIXME Running on GitHub gives additional dbind-WARNINGs. The data required is the last n lines.
69 result_tail=$(printf "%s" "$result" | tail --lines=7)
70
71 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)
72
73 printf "Result                              Expected\n"
74 printf '%s\n' "$result_tail" "$expected"| pr -2  --omit-header
75
76 rm "$lua_test_image"
77 rm "$lua_test_file"
78
79 if [ "$result_tail" = "$expected" ]
80 then
81         exit 0
82 else
83         exit 1
84 fi
85