diff options
| author | Paul Buetow <paul@buetow.org> | 2026-07-14 08:49:12 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-07-14 08:49:12 +0300 |
| commit | 12be1b9ae52829292d13cc2fcc6ff7571d050d62 (patch) | |
| tree | 674aafaeb3485bb38dd1e2ecc3d62f77e3584366 /tests/test_progressive_jpeg.c | |
| parent | 484fbca06312dbe0f381109763f701671f22e602 (diff) | |
progressive: libjpeg-turbo two-phase JPEG backend (st0)
M6: progressive low-res preview via libjpeg-turbo.
- jpeg.c: two-phase decode (1/8 low-res via progress_cb, full via GdkPixbuf
with EXIF orientation). Feature-gated.
- loader.h/c: LoaderProgressCb + load_progressive on backend struct;
loader_load_async accepts progress params; JPEG special-cased in task thread.
- window.c: _load_progress_cb marshals partial to main thread.
- tests: test_loader_jpeg (progress + dims), test_progressive_jpeg (sample).
16/16 green, ASan clean.
Diffstat (limited to 'tests/test_progressive_jpeg.c')
| -rw-r--r-- | tests/test_progressive_jpeg.c | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/tests/test_progressive_jpeg.c b/tests/test_progressive_jpeg.c new file mode 100644 index 0000000..8fc8f19 --- /dev/null +++ b/tests/test_progressive_jpeg.c @@ -0,0 +1,94 @@ +/*:* + * ggaze — progressive JPEG integration test + * + * Opens a large sample JPEG via the window (async + progressive path) and + * asserts the viewer shows a texture. The progressive low-res partial fires + * first (via the loader's progress callback), then the full result replaces + * it. Skip-if-absent (./sample-images not in CI). Needs a display. + * + * Copyright (c) 2026 ggaze contributors + * SPDX-License-Identifier: GPL-3.0-or-later + *:*/ + +#include "viewer.h" +#include "window.h" + +#include <gdk/gdk.h> +#include <gio/gio.h> +#include <glib.h> +#include <gtk/gtk.h> + +static GgazeWindow * +new_window(void) { + return (GGAZE_WINDOW(g_object_new(GGAZE_TYPE_WINDOW, NULL))); +} + +static GdkTexture * +viewer_texture(GgazeWindow *p_win) { + GtkStack *p_stack = ggaze_window_get_stack(p_win); + GtkWidget *p_large = gtk_stack_get_child_by_name(p_stack, "large"); + return (ggaze_viewer_get_texture(GGAZE_VIEWER(p_large))); +} + +static void +drain_main(guint u_ms) { + for (guint u = 0; u < u_ms; u++) { + g_main_context_iteration(g_main_context_default(), FALSE); + g_usleep(1000); + } +} + +static void +test_progressive_sample(void) { + const gchar *c_dir = g_getenv("GGAZE_SAMPLE_DIR"); + if (c_dir == NULL || *c_dir == '\0' || + !g_file_test(c_dir, G_FILE_TEST_IS_DIR)) { + g_test_skip("GGAZE_SAMPLE_DIR unset/absent (./sample-images)"); + return; + } + GDir *p_d = g_dir_open(c_dir, 0, NULL); + g_assert_nonnull(p_d); + const gchar *c_name; + while ((c_name = g_dir_read_name(p_d)) != NULL) { + if (g_str_has_suffix(c_name, ".jpg") || + g_str_has_suffix(c_name, ".JPG")) { + break; + } + } + char *c_path = + (c_name != NULL) ? g_build_filename(c_dir, c_name, NULL) : NULL; + g_dir_close(p_d); + if (c_path == NULL) { + g_test_skip("no JPEG sample found"); + return; + } + + GgazeWindow *p_win = new_window(); + GFile *p_file = g_file_new_for_path(c_path); + ggaze_window_open(p_win, p_file); + g_object_unref(p_file); + g_free(c_path); + + /* Pump until the viewer shows a texture (the progressive partial or the + * full result). */ + for (guint u = 0; u < 3000 && viewer_texture(p_win) == NULL; u++) { + g_main_context_iteration(g_main_context_default(), FALSE); + g_usleep(1000); + } + g_assert_nonnull(viewer_texture(p_win)); + + g_object_unref(p_win); + drain_main(500); +} + +int +main(int i_argc, char **c_argv) { + g_test_init(&i_argc, &c_argv, NULL); + g_log_set_always_fatal(G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL); + if (!gtk_init_check()) { + g_test_skip("no display available (run under xvfb)"); + return (g_test_run()); + } + g_test_add_func("/progressive/sample", test_progressive_sample); + return (g_test_run()); +}
\ No newline at end of file |
