Include Lua tests
authorColin Clark <colin.clark@cclark.uk>
Wed, 2 Aug 2023 12:41:50 +0000 (13:41 +0100)
committerColin Clark <colin.clark@cclark.uk>
Wed, 2 Aug 2023 12:41:50 +0000 (13:41 +0100)
meson.build
scripts/lua-test.sh [new file with mode: 0644]
scripts/meson.build

index 96ce460..8dc761f 100644 (file)
@@ -755,3 +755,22 @@ if running_from_git
 else
     summary({'Code Correctness' : ['Test runs:', false]}, section : 'Testing', bool_yn : true)
 endif
+
+# Lua test
+option = get_option('lua')
+if not option.disabled()
+    if lua_dep.found()
+        if xvfb.found()
+            lua_test_sh = find_program('lua-test.sh', dirs : scriptsdir, required : true)
+            test('Lua test', lua_test_sh, args: [geeqie_exe], is_parallel : false, timeout: 100)
+
+            summary({'lua' : ['Test runs:', true]}, section : 'Testing', bool_yn : true)
+        else
+            summary({'lua' : ['Test runs:', false]}, section : 'Testing', bool_yn : true)
+        endif
+    else
+        summary({'lua' : ['Test runs:', false]}, section : 'Testing', bool_yn : true)
+    endif
+else
+    summary({'lua' : ['Test runs:', false]}, section : 'Testing', bool_yn : true)
+endif
diff --git a/scripts/lua-test.sh b/scripts/lua-test.sh
new file mode 100644 (file)
index 0000000..c50a98d
--- /dev/null
@@ -0,0 +1,82 @@
+#!/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.
+
+lua_test_image=$(mktemp --suffix=".jpeg" "${TMPDIR:-/tmp}/geeqie.XXXXXXXXXX")
+mkdir -p "$HOME/.config/geeqie/lua/"
+lua_test_file=$(mktemp --suffix=".lua" --tmpdir="$HOME/.config/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 "$1" &
+
+# Wait for remote to initialize
+while [ ! -e "$HOME/.config/geeqie/.command" ] ;
+do
+       sleep 1
+done
+
+sleep 2
+
+base_lua=$(basename "$lua_test_file")
+result=$(xvfb-run --auto-servernum "$1" --remote --lua:"$lua_test_image","$base_lua")
+xvfb-run --auto-servernum "$1" --remote --quit
+
+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" "$expected"| pr -2  --omit-header
+
+rm "$lua_test_image"
+rm "$lua_test_file"
+
+if [ "$result" = "$expected" ]
+then
+       exit 0
+else
+       exit 1
+fi
+
index 79e8f70..acac18e 100644 (file)
@@ -23,6 +23,7 @@ script_sources += files('authors.sh',
 'gq-marshal-pragma.sh',
 'image-test.sh',
 'keyword_merge.sh',
+'lua-test.sh',
 'new-release.sh',
 'template-desktop.sh',
 'translators.sh',