tests/plover/test-import-yum.c
author J. Ali Harlow <ali@juiblex.co.uk>
Fri Jun 08 20:13:00 2018 +0100 (2018-06-08)
changeset 79 c2dbb86da017
permissions -rw-r--r--
Release 0.5.4
ali@38
     1
/*
ali@38
     2
 * Copyright (C) 2016  J. Ali Harlow <ali@juiblex.co.uk>
ali@38
     3
 *
ali@38
     4
 * This program is free software; you can redistribute it and/or modify
ali@38
     5
 * it under the terms of the GNU General Public License as published by
ali@38
     6
 * the Free Software Foundation; either version 2 of the License, or
ali@38
     7
 * (at your option) any later version.
ali@38
     8
 *
ali@38
     9
 * This program is distributed in the hope that it will be useful,
ali@38
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ali@38
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
ali@38
    12
 * GNU General Public License for more details.
ali@38
    13
 *
ali@38
    14
 * You should have received a copy of the GNU General Public License along
ali@38
    15
 * with this program; if not, write to the Free Software Foundation, Inc.,
ali@38
    16
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
ali@38
    17
 */
ali@38
    18
ali@38
    19
#include <stdlib.h>
ali@38
    20
#include <glib.h>
ali@38
    21
#include <razor.h>
ali@38
    22
#include <plover/plover.h>
ali@38
    23
ali@38
    24
const char *yum_packages[]={
ali@38
    25
    "zsh","zsh2","zip","zap","filesystem","zappy","zappy-tools","zappy2",
ali@38
    26
    "unsatisfiable","uninstallable","badpostun"
ali@38
    27
};
ali@38
    28
ali@38
    29
static void test_basic_import(void)
ali@38
    30
{
ali@38
    31
    int i;
ali@38
    32
    struct razor_set *set;
ali@38
    33
    struct razor_package_iterator *iter;
ali@38
    34
    struct razor_package *package;
ali@38
    35
    const char *name;
ali@38
    36
    GList *expected=NULL,*lnk;
ali@38
    37
    GError *err=NULL;
ali@38
    38
    set=plover_razor_set_create_from_yum("../yum-repo-test-dir",&err);
ali@38
    39
    if (!set && err)
ali@38
    40
	g_error("../yum-repo-test-dir: %s",err->message);
ali@38
    41
    g_assert(set != NULL);
ali@38
    42
    g_assert(err == NULL);
ali@38
    43
    for(i=0;i<G_N_ELEMENTS(yum_packages);i++)
ali@38
    44
	expected=g_list_prepend(expected,
ali@38
    45
	  (gpointer)g_intern_string(yum_packages[i]));
ali@38
    46
    iter=razor_package_iterator_create(set);
ali@38
    47
    while(razor_package_iterator_next(iter,&package,RAZOR_DETAIL_NAME,&name,
ali@38
    48
      RAZOR_DETAIL_LAST))
ali@38
    49
    {
ali@38
    50
	lnk=g_list_find(expected,g_intern_string(name));
ali@38
    51
	if (!lnk)
ali@38
    52
	    g_warning("Unexpected package in set: %s",name);
ali@38
    53
	else
ali@38
    54
	    expected=g_list_remove_link(expected,lnk);
ali@38
    55
    }
ali@38
    56
    razor_package_iterator_destroy(iter);
ali@38
    57
    if (expected)
ali@38
    58
	g_warning("%d missing package%s in set, including %s",
ali@38
    59
	  g_list_length(expected),g_list_length(expected)==1?"":"s",
ali@38
    60
	  expected->data);
ali@38
    61
    razor_set_unref(set);
ali@38
    62
}
ali@38
    63
ali@38
    64
int main(int argc,char **argv)
ali@38
    65
{
ali@38
    66
    g_test_init(&argc,&argv,NULL);
ali@38
    67
    g_test_bug_base("mailto:ali@juiblex.co.uk");
ali@38
    68
    g_test_add_func("/import-yum/basic",test_basic_import);
ali@38
    69
    return g_test_run();
ali@38
    70
}