diff options
| author | Colomban Wendling <[email protected]> | 2025-11-05 18:20:58 +0100 |
|---|---|---|
| committer | Colomban Wendling <[email protected]> | 2025-11-06 14:40:21 +0100 |
| commit | 216ac0dcf24cd20a35e81ac24031ccbe87f43ed2 (patch) | |
| tree | c103fbfa5c49e38e90e518ef07f1929efa3667fb | |
| parent | 15f762ebe18598b23bd87911ec6f89bc9e0f3c76 (diff) | |
| download | atril-216ac0dcf24cd20a35e81ac24031ccbe87f43ed2.tar.bz2 atril-216ac0dcf24cd20a35e81ac24031ccbe87f43ed2.tar.xz | |
Import test-ev-archive.c from XReader
Import test source from XReader[1]. This is not as useful as it might
seem as it's not a unit test, but it's still nice to have an easy way
to manually test this code, and reduces differences with XReader,
especially in the Meson build system.
[1] https://github.com/linuxmint/xreader/blob/master/backend/comics/test-ev-archive.c
| -rw-r--r-- | backend/comics/meson.build | 28 | ||||
| -rw-r--r-- | backend/comics/test-ev-archive.c | 116 |
2 files changed, 130 insertions, 14 deletions
diff --git a/backend/comics/meson.build b/backend/comics/meson.build index 36ecbaf3..a9903884 100644 --- a/backend/comics/meson.build +++ b/backend/comics/meson.build @@ -33,17 +33,17 @@ shared_module( ) -# Test is missing its source file -#test_name = 'test-ev-archive' -# -#test_sources = files( -# 'ev-archive.c', -# 'test-ev-archive.c', -#) -# -#executable( -# test_name, -# test_sources, -# include_directories: include_dirs, -# dependencies: comics_deps, -#) + +test_name = 'test-ev-archive' + +test_sources = files( + 'ev-archive.c', + 'test-ev-archive.c', +) + +executable( + test_name, + test_sources, + include_directories: include_dirs, + dependencies: comics_deps, +) diff --git a/backend/comics/test-ev-archive.c b/backend/comics/test-ev-archive.c new file mode 100644 index 00000000..772495a9 --- /dev/null +++ b/backend/comics/test-ev-archive.c @@ -0,0 +1,116 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */ +/* + * Copyright (C) 2017, Bastien Nocera <[email protected]> + * + * 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, 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. + */ + +#include "config.h" + +#include "ev-archive.h" + +static void +usage (const char *prog) +{ + g_print ("- Lists file in a supported archive format\n"); + g_print ("Usage: %s archive-type filename\n", prog); + g_print ("Where archive-type is one of rar, zip, 7z or tar\n"); +} + +static EvArchiveType +str_to_archive_type (const char *str) +{ + g_return_val_if_fail (str != NULL, EV_ARCHIVE_TYPE_NONE); + + if (g_strcmp0 (str, "rar") == 0) + return EV_ARCHIVE_TYPE_RAR; + if (g_strcmp0 (str, "zip") == 0) + return EV_ARCHIVE_TYPE_ZIP; + if (g_strcmp0 (str, "7z") == 0) + return EV_ARCHIVE_TYPE_7Z; + if (g_strcmp0 (str, "tar") == 0) + return EV_ARCHIVE_TYPE_TAR; + + g_warning ("Archive type '%s' not supported", str); + return EV_ARCHIVE_TYPE_NONE; +} + +int +main (int argc, char **argv) +{ + EvArchive *ar; + EvArchiveType ar_type; + GError *error = NULL; + gboolean printed_header = FALSE; + + if (argc != 3) { + usage (argv[0]); + return 1; + } + + ar_type = str_to_archive_type (argv[1]); + if (ar_type == EV_ARCHIVE_TYPE_NONE) + return 1; + + ar = ev_archive_new (); + if (!ev_archive_set_archive_type (ar, ar_type)) { + g_warning ("Failed to set archive type"); + goto out; + } + + if (!ev_archive_open_filename (ar, argv[2], &error)) { + g_warning ("Failed to open '%s': %s", + argv[2], error->message); + g_error_free (error); + goto out; + } + + while (1) { + const char *name; + gboolean is_encrypted; + gint64 size; + + if (!ev_archive_read_next_header (ar, &error)) { + if (error != NULL) { + g_warning ("Fatal error handling archive: %s", error->message); + g_clear_error (&error); + goto out; + } + break; + } + + name = ev_archive_get_entry_pathname (ar); + is_encrypted = ev_archive_get_entry_is_encrypted (ar); + size = ev_archive_get_entry_size (ar); + + if (!printed_header) { + g_print ("P\tSIZE\tNAME\n"); + printed_header = TRUE; + } + + g_print ("%c\t%"G_GINT64_FORMAT"\t%s\n", + is_encrypted ? 'P' : ' ', + size, name); + } + + ev_archive_reset (ar); + g_clear_object (&ar); + + return 0; + +out: + g_clear_object (&ar); + return 1; +} |
