summaryrefslogtreecommitdiff
path: root/tests/test_opener.c
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-07-14 09:08:10 +0300
committerPaul Buetow <paul@buetow.org>2026-07-14 09:08:10 +0300
commit95858bc4a819c118cf76dd38d6da0365ead997a9 (patch)
tree739544e2314c3e0bab65fb9c75e2c17e89069017 /tests/test_opener.c
parent12be1b9ae52829292d13cc2fcc6ff7571d050d62 (diff)
operate: mover, opener, runner, clipboard modules + tests (ut0)
M8 (partial): plain-C operate modules + unit tests. - src/mover.{c,h}: move files to configured dests (g_file_move + stem collision suffix -1/-2), one-level undo (move back), acts on marks-or-current. - src/opener.{c,h}: %f expand + detached GSubprocess launch (non-blocking). - src/runner.{c,h}: /bin/sh -c with single-quoted %f/%d (injection guard), async wait_check, rescan on completion. - src/clipboard.{c,h}: image/png via GdkContentProvider + uri-list. - meson: new sources added to libggae. - tests: unit test_mover (move/undo/collision), test_opener (true/false/weird filenames), test_runner (true/false/injection guard). 19/19 green, ASan clean. - Fixed: g_str_replace (not in GLib 2.88) → manual _str_replace; GdkContentProvider API (new_typed/new_for_value); mover collision stem-suffix; runner /bin/sh -c argv (single arg, not shell-parsed); test GFile leaks.
Diffstat (limited to 'tests/test_opener.c')
-rw-r--r--tests/test_opener.c85
1 files changed, 85 insertions, 0 deletions
diff --git a/tests/test_opener.c b/tests/test_opener.c
new file mode 100644
index 0000000..a364bdb
--- /dev/null
+++ b/tests/test_opener.c
@@ -0,0 +1,85 @@
+/* test_opener.c — %f expansion + launch with true/false. */
+#include "opener.h"
+#include <gio/gio.h>
+#include <glib.h>
+
+static GFile *
+make_tmp_file(void) {
+ GError *e = NULL;
+ char *d = g_dir_make_tmp("ggaze-opener-XXXXXX", &e);
+ g_assert_no_error(e);
+ char *p = g_build_filename(d, "test.txt", NULL);
+ GFile *f = g_file_new_for_path(p);
+ g_file_replace_contents(f, "x", 1, NULL, FALSE,
+ G_FILE_CREATE_REPLACE_DESTINATION, NULL, NULL, NULL);
+ g_free(p);
+ g_free(d);
+ return f;
+}
+
+static void
+test_launch_true(void) {
+ GFile *f = make_tmp_file();
+ Opener *o = opener_new();
+ OpenerProg prog = {"true", "true %f"};
+ GError *e = NULL;
+ g_assert_true(opener_launch(o, f, &prog, &e));
+ g_assert_no_error(e);
+ opener_delete(o);
+ g_object_unref(f);
+}
+
+static void
+test_launch_false(void) {
+ GFile *f = make_tmp_file();
+ Opener *o = opener_new();
+ OpenerProg prog = {"false", "false %f"};
+ GError *e = NULL;
+ g_assert_true(opener_launch(o, f, &prog, &e));
+ g_assert_no_error(e);
+ opener_delete(o);
+ g_object_unref(f);
+}
+
+static void
+test_weird_filename(void) {
+ GError *e = NULL;
+ char *d = g_dir_make_tmp("ggaze-opener-XXXXXX", &e);
+ g_assert_no_error(e);
+ char *p = g_build_filename(d, "file with spaces $HOME `whoami`.jpg", NULL);
+ GFile *f = g_file_new_for_path(p);
+ g_file_replace_contents(f, "x", 1, NULL, FALSE,
+ G_FILE_CREATE_REPLACE_DESTINATION, NULL, NULL, NULL);
+ Opener *o = opener_new();
+ OpenerProg prog = {"true", "true %f"};
+ g_assert_true(opener_launch(o, f, &prog, &e));
+ g_assert_no_error(e);
+ opener_delete(o);
+ g_object_unref(f);
+ g_free(p);
+ GFile *dd = g_file_new_for_path(d);
+ GFileEnumerator *en = g_file_enumerate_children(
+ dd, "standard::name", G_FILE_QUERY_INFO_NONE, NULL, NULL);
+ if (en) {
+ GFileInfo *i;
+ while ((i = g_file_enumerator_next_file(en, NULL, NULL))) {
+ GFile *c = g_file_get_child(dd, g_file_info_get_name(i));
+ g_file_delete(c, NULL, NULL);
+ g_object_unref(c);
+ g_object_unref(i);
+ }
+ g_object_unref(en);
+ }
+ g_file_delete(dd, NULL, NULL);
+ g_object_unref(dd);
+ g_free(d);
+}
+
+int
+main(int argc, char **argv) {
+ g_test_init(&argc, &argv, NULL);
+ g_test_add_func("/opener/true", test_launch_true);
+ g_test_add_func("/opener/false", test_launch_false);
+ g_test_add_func("/opener/weird_filename", test_weird_filename);
+ return g_test_run();
+} \ No newline at end of file