tests/plover-gtk/test-packagestore.c
author J. Ali Harlow <ali@juiblex.co.uk>
Sat Jul 16 11:07:18 2016 +0100 (2016-07-16)
changeset 61 31fb35727621
permissions -rw-r--r--
Support parallel installations. The idea is that for CAD screener, we want
to be able to install this on the same machine as a standard AVOT setup
(most notably for John's laptop). To allow for the possibility of a second
application that might have the same requirements, we add the concept of
vendor-specific distributions. Thus we can have one distribution for CAD
screener and one for The Next Big Thing. It doesn't seem trivial to have
both CAD screener and AVOT under the same vendor tag so we'll have to have
AVOT under "City Occupational" and CAD screener under "City Occupational Ltd"
or some such kludge.

Most of this is done although we are very short of test cases (in particular
we don't test that it's actually possible to install CAD screener in parallel
with AVOT or to update either of them once installed, which is fundamental).

We also have a lot of baggage left over, including an intercept of razor_set.
The problem that this was introduced to debug has been fixed but it looks
like there are a number of memory leaks which it might be useful to help
track down so it has been left in place for now.

There is still a lot of confusion in plover between path-based and URI-based
API. We should review the API, decide what we want and have a general clear up.

There is also confusion as to the purpose of RAZOR_ROOT (and meaning; path or
URI). This is not used at all in librazor (although it is used in razor.exe).
Ideally we shouldn't use it in plover or plover-gtk either although again, we
might want to support it or an equivalent in (some of) the various executables.

Work that would still to nice to do for CAD screener:

- uninstall (ideally as an installed program that hooks into Add/Remove programs
but even re-running the installer would be acceptable).
- xz support (smaller packages).
- repomd.xml and xml:base (would be needed for an Internet installer).
- graphical installer.
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 <string.h>
ali@38
    21
#include <glib.h>
ali@38
    22
#include <gdk/gdk.h>
ali@38
    23
#include <gtk/gtk.h>
ali@38
    24
#include <razor/razor.h>
ali@38
    25
#include <plover/package.h>
ali@38
    26
#include <plover/packageset.h>
ali@38
    27
#include <plover-gtk/packagestore.h>
ali@38
    28
#include "treemodel.h"
ali@38
    29
ali@38
    30
static void verify_package_store(PloverPackageStore *store,
ali@38
    31
  GSList *expected_packages)
ali@38
    32
{
ali@38
    33
    int i;
ali@38
    34
    const char *s;
ali@38
    35
    gchar *nosummary;
ali@38
    36
    PloverPackage *package;
ali@38
    37
    PloverPackageSet *package_set;
ali@38
    38
    GtkTreeModel *model;
ali@38
    39
    GtkTreeIter iter;
ali@38
    40
    GValue value={0,};
ali@38
    41
    GSList *expected,*lnk;
ali@38
    42
    GdkPixbuf *icon;
ali@38
    43
    model=GTK_TREE_MODEL(store);
ali@38
    44
    test_tree_model(model);
ali@38
    45
    expected=g_slist_copy(expected_packages);
ali@38
    46
    g_assert_cmpint(gtk_tree_model_get_n_columns(model),==,PLOVER_PACKAGE_STORE_NO_COLUMNS);
ali@38
    47
    g_assert_cmpint(gtk_tree_model_get_column_type(model,PLOVER_PACKAGE_STORE_OBJ_COLUMN),==,PLOVER_TYPE_PACKAGE);
ali@38
    48
    g_assert_cmpint(gtk_tree_model_get_column_type(model,PLOVER_PACKAGE_STORE_INSTALLED_COLUMN),==,G_TYPE_BOOLEAN);
ali@38
    49
    g_assert_cmpint(gtk_tree_model_get_column_type(model,PLOVER_PACKAGE_STORE_ICON_COLUMN),==,GDK_TYPE_PIXBUF);
ali@38
    50
    g_assert_cmpint(gtk_tree_model_get_column_type(model,PLOVER_PACKAGE_STORE_NAME_COLUMN),==,G_TYPE_STRING);
ali@38
    51
    g_assert_cmpint(gtk_tree_model_get_column_type(model,PLOVER_PACKAGE_STORE_VERSION_COLUMN),==,G_TYPE_STRING);
ali@38
    52
    g_assert_cmpint(gtk_tree_model_get_column_type(model,PLOVER_PACKAGE_STORE_SUMMARY_COLUMN),==,G_TYPE_STRING);
ali@38
    53
    for(i=0;;i++)
ali@38
    54
    {
ali@38
    55
	if (!gtk_tree_model_iter_nth_child(model,&iter,NULL,i))
ali@38
    56
	    break;
ali@38
    57
	gtk_tree_model_get_value(model,&iter,PLOVER_PACKAGE_STORE_OBJ_COLUMN,
ali@38
    58
	  &value);
ali@38
    59
	package=g_value_dup_object(&value);
ali@38
    60
	lnk=g_slist_find(expected,package);
ali@38
    61
	if (!lnk)
ali@38
    62
	    g_warning("Unexpected package in store: %s",
ali@38
    63
	      plover_package_get_name(package));
ali@38
    64
	else
ali@38
    65
	{
ali@38
    66
	    g_object_unref(lnk->data);
ali@38
    67
	    expected=g_slist_delete_link(expected,lnk);
ali@38
    68
	}
ali@38
    69
	g_value_unset(&value);
ali@38
    70
	gtk_tree_model_get_value(model,&iter,
ali@38
    71
	  PLOVER_PACKAGE_STORE_INSTALLED_COLUMN,&value);
ali@38
    72
	g_assert_cmpint(G_VALUE_TYPE(&value),==,G_TYPE_BOOLEAN);
ali@38
    73
	/* Can't check value of installed yet, it
ali@38
    74
	 * isn't set (or even properly defined).
ali@38
    75
	 */
ali@38
    76
	g_value_unset(&value);
ali@38
    77
	gtk_tree_model_get_value(model,&iter,
ali@38
    78
	  PLOVER_PACKAGE_STORE_ICON_COLUMN,&value);
ali@38
    79
	icon=g_value_get_object(&value);
ali@38
    80
	if (icon)
ali@38
    81
	    g_assert(GDK_IS_PIXBUF(icon));
ali@38
    82
	g_value_unset(&value);
ali@38
    83
	gtk_tree_model_get_value(model,&iter,PLOVER_PACKAGE_STORE_NAME_COLUMN,
ali@38
    84
	  &value);
ali@38
    85
	s=g_value_get_string(&value);
ali@38
    86
	g_assert_cmpstr(plover_package_get_name(package),==,s);
ali@38
    87
	g_value_unset(&value);
ali@38
    88
	gtk_tree_model_get_value(model,&iter,
ali@38
    89
	  PLOVER_PACKAGE_STORE_VERSION_COLUMN,&value);
ali@38
    90
	s=g_value_get_string(&value);
ali@38
    91
	g_assert_cmpstr(plover_package_get_version(package),==,s);
ali@38
    92
	g_value_unset(&value);
ali@38
    93
	gtk_tree_model_get_value(model,&iter,
ali@38
    94
	  PLOVER_PACKAGE_STORE_SUMMARY_COLUMN,&value);
ali@38
    95
	s=g_value_get_string(&value);
ali@38
    96
	if (*plover_package_get_summary(package))
ali@38
    97
	    g_assert_cmpstr(plover_package_get_summary(package),==,s);
ali@38
    98
	else
ali@38
    99
	{
ali@38
   100
	    nosummary=g_strconcat("The ",plover_package_get_name(package),
ali@38
   101
	      " package",NULL);
ali@38
   102
	    g_assert_cmpstr(nosummary,==,s);
ali@38
   103
	    g_free(nosummary);
ali@38
   104
	}
ali@38
   105
	g_value_unset(&value);
ali@38
   106
    }
ali@38
   107
    if (expected)
ali@38
   108
    {
ali@38
   109
	package=PLOVER_PACKAGE(expected->data);
ali@38
   110
	g_warning("%d missing package%s in store, including %s",
ali@38
   111
	  g_slist_length(expected),g_slist_length(expected)==1?"":"s",
ali@38
   112
	  plover_package_get_name(package));
ali@38
   113
    }
ali@38
   114
}
ali@38
   115
ali@38
   116
static void test_empty(void)
ali@38
   117
{
ali@38
   118
    PloverPackageStore *store;
ali@38
   119
    store=plover_package_store_new();
ali@38
   120
    g_assert(!plover_package_store_get_sets(store));
ali@38
   121
    verify_package_store(store,NULL);
ali@38
   122
    g_object_unref(store);
ali@38
   123
}
ali@38
   124
ali@38
   125
static void test_basic(void)
ali@38
   126
{
ali@38
   127
    PloverPackageSet *package_set;
ali@38
   128
    PloverPackageStore *store;
ali@38
   129
    GError *err=NULL;
ali@38
   130
    GSList *expected;
ali@38
   131
    package_set=plover_package_set_new_from_yum("../yum-repo-test-dir",NULL,
ali@38
   132
      &err);
ali@38
   133
    if (!package_set)
ali@38
   134
	g_error("../yum-repo-test-dir: %s",err->message);
ali@38
   135
    store=plover_package_store_new();
ali@38
   136
    plover_package_store_add_set(store,package_set);
ali@38
   137
    expected=g_slist_copy(plover_package_set_get_packages(package_set));
ali@38
   138
    g_slist_foreach(expected,(GFunc)g_object_ref,NULL);
ali@38
   139
    g_object_unref(package_set);
ali@38
   140
    verify_package_store(store,expected);
ali@38
   141
    g_slist_foreach(expected,(GFunc)g_object_unref,NULL);
ali@38
   142
    g_slist_free(expected);
ali@38
   143
    g_object_unref(store);
ali@38
   144
}
ali@38
   145
ali@38
   146
static PloverPackageSet *no_details_new(void)
ali@38
   147
{
ali@38
   148
    struct razor_set *set;
ali@38
   149
    struct razor_importer *importer;
ali@38
   150
    PloverPackageSet *package_set;
ali@38
   151
    importer=razor_importer_create();
ali@38
   152
    razor_importer_begin_package(importer,"no-details","1-1","noarch");
ali@38
   153
    razor_importer_add_details(importer,"","","","");
ali@38
   154
    razor_importer_add_property(importer,"no-details",
ali@38
   155
      RAZOR_PROPERTY_PROVIDES|RAZOR_PROPERTY_EQUAL,"1-1");
ali@38
   156
    razor_importer_finish_package(importer);
ali@38
   157
    set=razor_importer_finish(importer);
ali@38
   158
    package_set=plover_package_set_new_from_razor(set);
ali@38
   159
    razor_set_unref(set);
ali@38
   160
    return package_set;
ali@38
   161
}
ali@38
   162
ali@38
   163
static void test_no_details(void)
ali@38
   164
{
ali@38
   165
    PloverPackageSet *package_set;
ali@38
   166
    PloverPackageStore *store;
ali@38
   167
    GSList *expected;
ali@38
   168
    package_set=no_details_new();
ali@38
   169
    store=plover_package_store_new();
ali@38
   170
    plover_package_store_add_set(store,package_set);
ali@38
   171
    expected=g_slist_copy(plover_package_set_get_packages(package_set));
ali@38
   172
    g_slist_foreach(expected,(GFunc)g_object_ref,NULL);
ali@38
   173
    g_object_unref(package_set);
ali@38
   174
    verify_package_store(store,expected);
ali@38
   175
    g_slist_foreach(expected,(GFunc)g_object_unref,NULL);
ali@38
   176
    g_slist_free(expected);
ali@38
   177
    g_object_unref(store);
ali@38
   178
}
ali@38
   179
ali@38
   180
static void test_remove(void)
ali@38
   181
{
ali@38
   182
    PloverPackageSet *yum_set,*nodetails_set;
ali@38
   183
    PloverPackageStore *store;
ali@38
   184
    GSList *expected;
ali@38
   185
    GError *err=NULL;
ali@38
   186
    store=plover_package_store_new();
ali@38
   187
    yum_set=plover_package_set_new_from_yum("../yum-repo-test-dir",NULL,&err);
ali@38
   188
    if (!yum_set)
ali@38
   189
	g_error("../yum-repo-test-dir: %s",err->message);
ali@38
   190
    plover_package_store_add_set(store,yum_set);
ali@38
   191
    nodetails_set=no_details_new();
ali@38
   192
    expected=g_slist_copy(plover_package_set_get_packages(nodetails_set));
ali@38
   193
    g_slist_foreach(expected,(GFunc)g_object_ref,NULL);
ali@38
   194
    plover_package_store_add_set(store,nodetails_set);
ali@38
   195
    plover_package_store_remove_set(store,yum_set);
ali@38
   196
    g_object_unref(nodetails_set);
ali@38
   197
    g_object_unref(yum_set);
ali@38
   198
    verify_package_store(store,expected);
ali@38
   199
    g_slist_foreach(expected,(GFunc)g_object_unref,NULL);
ali@38
   200
    g_slist_free(expected);
ali@38
   201
    g_object_unref(store);
ali@38
   202
}
ali@38
   203
ali@38
   204
int main(int argc,char **argv)
ali@38
   205
{
ali@38
   206
    int retval;
ali@38
   207
    gtk_test_init(&argc,&argv,NULL);
ali@38
   208
    g_test_bug_base("mailto:ali@juiblex.co.uk");
ali@38
   209
    g_test_add_func("/packagestore/empty",test_empty);
ali@38
   210
    g_test_add_func("/packagestore/basic",test_basic);
ali@38
   211
    g_test_add_func("/packagestore/no-details",test_no_details);
ali@38
   212
    g_test_add_func("/packagestore/remove",test_remove);
ali@38
   213
    retval=g_test_run();
ali@38
   214
    return retval;
ali@38
   215
}