Blame unit-tests/test-util.c

Packit 116408
/*
Packit 116408
 * Copyright (C) 2017 Sébastien Wilmet <swilmet@gnome.org>
Packit 116408
 *
Packit 116408
 * This program is free software; you can redistribute it and/or
Packit 116408
 * modify it under the terms of the GNU General Public License as
Packit 116408
 * published by the Free Software Foundation; either version 2 of the
Packit 116408
 * License, or (at your option) any later version.
Packit 116408
 *
Packit 116408
 * This program is distributed in the hope that it will be useful,
Packit 116408
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 116408
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 116408
 * General Public License for more details.
Packit 116408
 *
Packit 116408
 * You should have received a copy of the GNU General Public License
Packit 116408
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
Packit 116408
 */
Packit 116408
Packit 116408
#include "dh-util.h"
Packit 116408
Packit 116408
static void
Packit 116408
check_get_possible_index_files (const gchar *book_directory_path,
Packit 116408
                                const gchar *book_basename)
Packit 116408
{
Packit 116408
        GFile *book_directory;
Packit 116408
        GSList *list;
Packit 116408
        GSList *l;
Packit 116408
        gint i;
Packit 116408
Packit 116408
        book_directory = g_file_new_for_path (book_directory_path);
Packit 116408
        list = _dh_util_get_possible_index_files (book_directory);
Packit 116408
Packit 116408
        g_assert_cmpint (g_slist_length (list), ==, 4);
Packit 116408
Packit 116408
        for (l = list, i = 0; l != NULL; l = l->next, i++) {
Packit 116408
                GFile *index_file = G_FILE (l->data);
Packit 116408
                gchar *expected_basename;
Packit 116408
                gchar *basename;
Packit 116408
                gchar *expected_path;
Packit 116408
                gchar *path;
Packit 116408
Packit 116408
                switch (i) {
Packit 116408
                        case 0:
Packit 116408
                                expected_basename = g_strconcat (book_basename, ".devhelp2", NULL);
Packit 116408
                                break;
Packit 116408
Packit 116408
                        case 1:
Packit 116408
                                expected_basename = g_strconcat (book_basename, ".devhelp2.gz", NULL);
Packit 116408
                                break;
Packit 116408
Packit 116408
                        case 2:
Packit 116408
                                expected_basename = g_strconcat (book_basename, ".devhelp", NULL);
Packit 116408
                                break;
Packit 116408
Packit 116408
                        case 3:
Packit 116408
                                expected_basename = g_strconcat (book_basename, ".devhelp.gz", NULL);
Packit 116408
                                break;
Packit 116408
Packit 116408
                        default:
Packit 116408
                                g_assert_not_reached ();
Packit 116408
                }
Packit 116408
Packit 116408
                basename = g_file_get_basename (index_file);
Packit 116408
                g_assert_cmpstr (basename, ==, expected_basename);
Packit 116408
Packit 116408
                expected_path = g_build_filename (book_directory_path, expected_basename, NULL);
Packit 116408
                path = g_file_get_path (index_file);
Packit 116408
                g_assert_cmpstr (path, ==, expected_path);
Packit 116408
Packit 116408
                g_free (expected_basename);
Packit 116408
                g_free (basename);
Packit 116408
                g_free (expected_path);
Packit 116408
                g_free (path);
Packit 116408
        }
Packit 116408
Packit 116408
        g_object_unref (book_directory);
Packit 116408
        g_slist_free_full (list, g_object_unref);
Packit 116408
}
Packit 116408
Packit 116408
static void
Packit 116408
test_get_possible_index_files (void)
Packit 116408
{
Packit 116408
        check_get_possible_index_files ("/usr/share/gtk-doc/html/glib", "glib");
Packit 116408
        check_get_possible_index_files ("/usr/share/gtk-doc/html/glib/", "glib");
Packit 116408
        check_get_possible_index_files ("/usr/share/gtk-doc/html/gtk3", "gtk3");
Packit 116408
        check_get_possible_index_files ("/usr/share/gtk-doc/html/gtk3/", "gtk3");
Packit 116408
}
Packit 116408
Packit 116408
int
Packit 116408
main (int    argc,
Packit 116408
      char **argv)
Packit 116408
{
Packit 116408
        g_test_init (&argc, &argv, NULL);
Packit 116408
Packit 116408
        g_test_add_func ("/util/get_possible_index_files", test_get_possible_index_files);
Packit 116408
Packit 116408
        return g_test_run ();
Packit 116408
}