tests/plover/test-transaction.c
author J. Ali Harlow <ali@juiblex.co.uk>
Wed Jun 22 17:32:44 2016 +0100 (2016-06-22)
changeset 45 a166277bc796
parent 38 a29623b68ca2
child 61 31fb35727621
permissions -rw-r--r--
Remove obsolete file URI support
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 <lua.h>
ali@38
    22
#include <razor.h>
ali@38
    23
#include <plover/plover.h>
ali@38
    24
#include <plover/packageset.h>
ali@38
    25
#include <plover/transaction.h>
ali@38
    26
ali@38
    27
LUALIB_API int luaopen_posix(lua_State *L);
ali@38
    28
ali@38
    29
const char *zappy_packages[]={
ali@38
    30
    "zap","zappy","zappy-tools","zappy2"
ali@38
    31
};
ali@38
    32
ali@38
    33
static void test_installed_system_set(void)
ali@38
    34
{
ali@38
    35
    PloverTransaction *transaction;
ali@38
    36
    PloverPackageSet *package_set;
ali@38
    37
    struct razor_set *set;
ali@38
    38
    GError *err=NULL;
ali@38
    39
    transaction=plover_transaction_new();
ali@38
    40
    g_assert(PLOVER_IS_TRANSACTION(transaction));
ali@38
    41
    package_set=plover_package_set_new_from_yum("../yum-repo-test-dir",NULL,
ali@38
    42
      &err);
ali@38
    43
    if (!package_set)
ali@38
    44
	g_error("../yum-repo-test-dir: %s",err->message);
ali@38
    45
    plover_transaction_set_installed(transaction,package_set);
ali@38
    46
    set=plover_transaction_get_system_set(transaction);
ali@38
    47
    g_assert(set == plover_package_set_get_razor(package_set));
ali@38
    48
    g_object_unref(package_set);
ali@38
    49
    g_object_unref(transaction);
ali@38
    50
}
ali@38
    51
ali@38
    52
static PloverTransaction *update_noop(void)
ali@38
    53
{
ali@38
    54
    PloverTransaction *transaction;
ali@38
    55
    struct razor_install_iterator *iter;
ali@38
    56
    struct razor_package *pkg;
ali@38
    57
    enum razor_install_action action;
ali@38
    58
    int count;
ali@42
    59
    gchar *root_uri;
ali@38
    60
    GError *err=NULL;
ali@42
    61
    GFile *file;
ali@42
    62
    file=g_file_new_for_path("../razor-test-dir");
ali@42
    63
    root_uri=g_file_get_uri(file);
ali@42
    64
    g_object_unref(file);
ali@42
    65
    g_setenv("RAZOR_ROOT",root_uri,TRUE);
ali@42
    66
    g_free(root_uri);
ali@38
    67
    transaction=plover_transaction_new_update("../yum-repo-test-dir","/test",
ali@38
    68
      NULL,&err);
ali@38
    69
    if (!transaction && err)
ali@38
    70
	g_error("../yum-repo-test-dir: %s",err->message);
ali@38
    71
    g_assert(PLOVER_IS_TRANSACTION(transaction));
ali@38
    72
    g_assert(!err);
ali@38
    73
    g_assert(!plover_transaction_get_unsatisfied(transaction));
ali@38
    74
    iter=plover_transaction_get_install_iterator(transaction,&err);
ali@38
    75
    if (!iter && err)
ali@38
    76
	g_error("plover_transaction_get_install_iterator: %s",err->message);
ali@38
    77
    g_assert(iter);
ali@38
    78
    g_assert(!err);
ali@38
    79
    g_assert(!razor_install_iterator_next(iter,&pkg,&action,&count));
ali@38
    80
    return transaction;
ali@38
    81
}
ali@38
    82
ali@38
    83
static void test_update_noop(void)
ali@38
    84
{
ali@38
    85
    PloverTransaction *transaction;
ali@38
    86
    transaction=update_noop();
ali@38
    87
    g_object_unref(transaction);
ali@38
    88
}
ali@38
    89
ali@38
    90
static void test_update_nonexistant(void)
ali@38
    91
{
ali@38
    92
    PloverTransaction *transaction;
ali@38
    93
    char *pkgs[]={"nonexistant",NULL};
ali@42
    94
    gchar *root_uri;
ali@38
    95
    GError *err=NULL;
ali@42
    96
    GFile *file;
ali@42
    97
    file=g_file_new_for_path("../razor-test-dir");
ali@42
    98
    root_uri=g_file_get_uri(file);
ali@42
    99
    g_object_unref(file);
ali@42
   100
    g_setenv("RAZOR_ROOT",root_uri,TRUE);
ali@42
   101
    g_free(root_uri);
ali@38
   102
    transaction=plover_transaction_new_update("../yum-repo-test-dir","/test",
ali@38
   103
      pkgs,&err);
ali@38
   104
    g_assert(!transaction);
ali@38
   105
    g_assert(g_error_matches(err,PLOVER_GENERAL_ERROR,
ali@38
   106
      PLOVER_GENERAL_ERROR_NO_SUCH_PACKAGE));
ali@38
   107
    g_clear_error(&err);
ali@38
   108
}
ali@38
   109
ali@38
   110
static void test_install(void)
ali@38
   111
{
ali@38
   112
    PloverTransaction *transaction;
ali@38
   113
    struct razor_set *next;
ali@38
   114
    struct razor_install_iterator *iter;
ali@38
   115
    struct razor_package *pkg;
ali@38
   116
    enum razor_install_action action;
ali@38
   117
    int count;
ali@38
   118
    char *name;
ali@38
   119
    char *pkgs[]={"zip",NULL};
ali@42
   120
    gchar *root_uri;
ali@38
   121
    GError *err=NULL;
ali@42
   122
    GFile *file;
ali@42
   123
    file=g_file_new_for_path("../razor-test-dir");
ali@42
   124
    root_uri=g_file_get_uri(file);
ali@42
   125
    g_object_unref(file);
ali@42
   126
    g_setenv("RAZOR_ROOT",root_uri,TRUE);
ali@42
   127
    g_free(root_uri);
ali@38
   128
    transaction=plover_transaction_new_install("../yum-repo-test-dir","/test",
ali@38
   129
      pkgs,&err);
ali@38
   130
    if (!transaction && err)
ali@38
   131
	g_error("../yum-repo-test-dir: %s",err->message);
ali@38
   132
    g_assert(PLOVER_IS_TRANSACTION(transaction));
ali@38
   133
    g_assert(!err);
ali@38
   134
    g_assert(!plover_transaction_get_unsatisfied(transaction));
ali@38
   135
    next=plover_transaction_get_next_set(transaction,&err);
ali@38
   136
    if (!next && err)
ali@38
   137
	g_error("plover_transaction_get_next_set: %s",err->message);
ali@38
   138
    g_assert(next);
ali@38
   139
    g_assert(!err);
ali@38
   140
    iter=plover_transaction_get_install_iterator(transaction,&err);
ali@38
   141
    if (!iter && err)
ali@38
   142
	g_error("plover_transaction_get_install_iterator: %s",err->message);
ali@38
   143
    g_assert(iter);
ali@38
   144
    g_assert(!err);
ali@38
   145
    g_assert(razor_install_iterator_next(iter,&pkg,&action,&count));
ali@38
   146
    g_assert_cmpint(action,==,RAZOR_INSTALL_ACTION_ADD);
ali@38
   147
    g_assert_cmpint(count,==,1);
ali@38
   148
    razor_package_get_details(next,pkg,RAZOR_DETAIL_NAME,&name,
ali@38
   149
      RAZOR_DETAIL_LAST);
ali@38
   150
    g_assert_cmpstr(name,==,"zip");
ali@38
   151
    g_assert(!razor_install_iterator_next(iter,&pkg,&action,&count));
ali@38
   152
    g_object_unref(transaction);
ali@38
   153
}
ali@38
   154
ali@38
   155
static void test_install_nonexistant(void)
ali@38
   156
{
ali@38
   157
    PloverTransaction *transaction;
ali@38
   158
    char *pkgs[]={"nonexistant",NULL};
ali@42
   159
    gchar *root_uri;
ali@38
   160
    GError *err=NULL;
ali@42
   161
    GFile *file;
ali@42
   162
    file=g_file_new_for_path("../razor-test-dir");
ali@42
   163
    root_uri=g_file_get_uri(file);
ali@42
   164
    g_object_unref(file);
ali@42
   165
    g_setenv("RAZOR_ROOT",root_uri,TRUE);
ali@42
   166
    g_free(root_uri);
ali@38
   167
    transaction=plover_transaction_new_install("../yum-repo-test-dir","/test",
ali@38
   168
      pkgs,&err);
ali@38
   169
    g_assert(!transaction);
ali@38
   170
    g_assert(g_error_matches(err,PLOVER_GENERAL_ERROR,
ali@38
   171
      PLOVER_GENERAL_ERROR_NO_SUCH_PACKAGE));
ali@38
   172
    g_clear_error(&err);
ali@38
   173
}
ali@38
   174
ali@38
   175
static void test_install_uninstallable(void)
ali@38
   176
{
ali@38
   177
    PloverTransaction *transaction;
ali@38
   178
    struct razor_set *next;
ali@38
   179
    struct razor_install_iterator *iter;
ali@38
   180
    struct razor_package *pkg;
ali@38
   181
    enum razor_install_action action;
ali@38
   182
    int count;
ali@38
   183
    char *name;
ali@38
   184
    char *pkgs[]={"uninstallable",NULL};
ali@42
   185
    gchar *root_uri;
ali@38
   186
    GError *err=NULL;
ali@42
   187
    GFile *file;
ali@42
   188
    file=g_file_new_for_path("../razor-test-dir");
ali@42
   189
    root_uri=g_file_get_uri(file);
ali@42
   190
    g_object_unref(file);
ali@42
   191
    g_setenv("RAZOR_ROOT",root_uri,TRUE);
ali@42
   192
    g_free(root_uri);
ali@38
   193
    transaction=plover_transaction_new_install("../yum-repo-test-dir","/test",
ali@38
   194
      pkgs,&err);
ali@38
   195
    if (!transaction && err)
ali@38
   196
	g_error("../yum-repo-test-dir: %s",err->message);
ali@38
   197
    g_assert(PLOVER_IS_TRANSACTION(transaction));
ali@38
   198
    g_assert(!err);
ali@38
   199
    g_assert_cmpstr(plover_transaction_get_unsatisfied(transaction),==,NULL);
ali@38
   200
    next=plover_transaction_get_next_set(transaction,&err);
ali@38
   201
    if (!next && err)
ali@38
   202
	g_error("plover_transaction_get_next_set: %s",err->message);
ali@38
   203
    g_assert(next);
ali@38
   204
    g_assert(!err);
ali@38
   205
    iter=plover_transaction_get_install_iterator(transaction,&err);
ali@38
   206
    if (!iter && err)
ali@38
   207
	g_error("plover_transaction_get_install_iterator: %s",err->message);
ali@38
   208
    g_assert(iter);
ali@38
   209
    g_assert(!err);
ali@38
   210
    g_assert(razor_install_iterator_next(iter,&pkg,&action,&count));
ali@38
   211
    g_assert_cmpint(action,==,RAZOR_INSTALL_ACTION_ADD);
ali@38
   212
    g_assert_cmpint(count,==,1);
ali@38
   213
    razor_package_get_details(next,pkg,RAZOR_DETAIL_NAME,&name,
ali@38
   214
      RAZOR_DETAIL_LAST);
ali@38
   215
    g_assert_cmpstr(name,==,"uninstallable");
ali@38
   216
    g_assert(!razor_install_iterator_next(iter,&pkg,&action,&count));
ali@38
   217
    g_assert(!plover_transaction_commit(transaction,NULL,&err));
ali@42
   218
    g_message("plover_transaction_commit: %s",err->message);
ali@38
   219
    g_assert_cmpint(err->domain,==,PLOVER_RAZOR_ERROR);
ali@38
   220
    g_assert_cmpint(err->code,==,RAZOR_GENERAL_ERROR_FAILED);
ali@38
   221
    g_clear_error(&err);
ali@38
   222
    g_object_unref(transaction);
ali@38
   223
}
ali@38
   224
ali@38
   225
static void test_unsatisfied(void)
ali@38
   226
{
ali@38
   227
    PloverTransaction *transaction;
ali@38
   228
    struct razor_install_iterator *iter;
ali@38
   229
    char *pkgs[]={"unsatisfiable",NULL};
ali@38
   230
    const char *s;
ali@42
   231
    gchar *root_uri;
ali@38
   232
    GError *err=NULL;
ali@42
   233
    GFile *file;
ali@42
   234
    file=g_file_new_for_path("../razor-test-dir");
ali@42
   235
    root_uri=g_file_get_uri(file);
ali@42
   236
    g_object_unref(file);
ali@42
   237
    g_setenv("RAZOR_ROOT",root_uri,TRUE);
ali@42
   238
    g_free(root_uri);
ali@38
   239
    transaction=plover_transaction_new_install("../yum-repo-test-dir","/test",
ali@38
   240
      pkgs,&err);
ali@38
   241
    if (!transaction && err)
ali@38
   242
	g_error("../yum-repo-test-dir: %s",err->message);
ali@38
   243
    g_assert(PLOVER_IS_TRANSACTION(transaction));
ali@38
   244
    g_assert(!err);
ali@38
   245
    iter=plover_transaction_get_install_iterator(transaction,&err);
ali@38
   246
    g_assert(!iter);
ali@38
   247
    g_assert(g_error_matches(err,PLOVER_GENERAL_ERROR,
ali@38
   248
      PLOVER_GENERAL_ERROR_REQUIREMENTS_NOT_MET));
ali@38
   249
    g_clear_error(&err);
ali@38
   250
    s=plover_transaction_get_unsatisfied(transaction);
ali@38
   251
    g_assert_cmpstr(s,!=,NULL);
ali@38
   252
    g_assert_cmpstr(s,!=,"");
ali@38
   253
    g_object_unref(transaction);
ali@38
   254
}
ali@38
   255
ali@38
   256
static void test_remove(void)
ali@38
   257
{
ali@38
   258
    PloverTransaction *transaction;
ali@38
   259
    struct razor_set *system;
ali@38
   260
    struct razor_install_iterator *iter;
ali@38
   261
    struct razor_package *pkg;
ali@38
   262
    enum razor_install_action action;
ali@38
   263
    int count;
ali@38
   264
    char *name;
ali@38
   265
    char *pkgs[]={"zappy-tools",NULL};
ali@42
   266
    gchar *root_uri;
ali@38
   267
    GError *err=NULL;
ali@42
   268
    GFile *file;
ali@42
   269
    file=g_file_new_for_path("../razor-test-dir");
ali@42
   270
    root_uri=g_file_get_uri(file);
ali@42
   271
    g_object_unref(file);
ali@42
   272
    g_setenv("RAZOR_ROOT",root_uri,TRUE);
ali@42
   273
    g_free(root_uri);
ali@38
   274
    transaction=plover_transaction_new_remove(pkgs,&err);
ali@38
   275
    if (!transaction && err)
ali@38
   276
	g_error("zappy-tools: %s",err->message);
ali@38
   277
    g_assert(PLOVER_IS_TRANSACTION(transaction));
ali@38
   278
    g_assert(!err);
ali@38
   279
    system=plover_transaction_get_system_set(transaction);
ali@38
   280
    g_assert(system);
ali@38
   281
    iter=plover_transaction_get_install_iterator(transaction,&err);
ali@38
   282
    if (!iter && err)
ali@38
   283
	g_error("plover_transaction_get_install_iterator: %s",err->message);
ali@38
   284
    g_assert(iter);
ali@38
   285
    g_assert(!err);
ali@38
   286
    g_assert(razor_install_iterator_next(iter,&pkg,&action,&count));
ali@38
   287
    g_assert_cmpint(action,==,RAZOR_INSTALL_ACTION_REMOVE);
ali@38
   288
    g_assert_cmpint(count,==,0);
ali@38
   289
    razor_package_get_details(system,pkg,RAZOR_DETAIL_NAME,&name,
ali@38
   290
      RAZOR_DETAIL_LAST);
ali@38
   291
    g_assert_cmpstr(name,==,"zappy-tools");
ali@38
   292
    g_assert(!razor_install_iterator_next(iter,&pkg,&action,&count));
ali@38
   293
    g_object_unref(transaction);
ali@38
   294
}
ali@38
   295
ali@38
   296
static void test_remove_nonexistant(void)
ali@38
   297
{
ali@38
   298
    PloverTransaction *transaction;
ali@38
   299
    char *pkgs[]={"nonexistant",NULL};
ali@42
   300
    gchar *root_uri;
ali@38
   301
    GError *err=NULL;
ali@42
   302
    GFile *file;
ali@42
   303
    file=g_file_new_for_path("../razor-test-dir");
ali@42
   304
    root_uri=g_file_get_uri(file);
ali@42
   305
    g_object_unref(file);
ali@42
   306
    g_setenv("RAZOR_ROOT",root_uri,TRUE);
ali@42
   307
    g_free(root_uri);
ali@38
   308
    transaction=plover_transaction_new_remove(pkgs,&err);
ali@38
   309
    g_assert(!transaction);
ali@38
   310
    g_assert(g_error_matches(err,PLOVER_GENERAL_ERROR,
ali@38
   311
      PLOVER_GENERAL_ERROR_NO_SUCH_PACKAGE));
ali@38
   312
    g_clear_error(&err);
ali@38
   313
}
ali@38
   314
ali@38
   315
GMainLoop *test_commit_mainloop;
ali@38
   316
ali@38
   317
static void test_commit_callback(GObject *source,GAsyncResult *result,
ali@38
   318
  gpointer user_data)
ali@38
   319
{
ali@38
   320
    PloverTransaction *transaction=user_data;
ali@38
   321
    GError *err=NULL;
ali@38
   322
    if (!plover_transaction_commit_finish(transaction,result,&err))
ali@38
   323
    {
ali@38
   324
	g_assert(err && err->message);
ali@38
   325
	g_error("test-commit: %s",err->message);
ali@38
   326
    }
ali@38
   327
    g_assert(!err);
ali@38
   328
    g_main_loop_quit(test_commit_mainloop);
ali@38
   329
}
ali@38
   330
ali@38
   331
static void test_commit(void)
ali@38
   332
{
ali@38
   333
    PloverTransaction *transaction;
ali@38
   334
    test_commit_mainloop=g_main_loop_new(NULL,FALSE);
ali@38
   335
    transaction=update_noop();
ali@38
   336
    plover_transaction_commit_async(transaction,NULL,test_commit_callback,
ali@38
   337
      transaction);
ali@38
   338
    g_main_loop_run(test_commit_mainloop);
ali@38
   339
    g_main_loop_unref(test_commit_mainloop);
ali@38
   340
    g_object_unref(transaction);
ali@38
   341
}
ali@38
   342
ali@38
   343
static void test_remove_with_leaves(void)
ali@38
   344
{
ali@38
   345
    PloverTransaction *transaction;
ali@38
   346
    struct razor_set *system;
ali@38
   347
    struct razor_install_iterator *iter;
ali@38
   348
    struct razor_package *pkg;
ali@38
   349
    enum razor_install_action action;
ali@38
   350
    int count;
ali@38
   351
    char *name;
ali@38
   352
    char *pkgs[]={"zappy-tools",NULL};
ali@42
   353
    gchar *root_uri;
ali@38
   354
    GError *err=NULL;
ali@42
   355
    GFile *file;
ali@42
   356
    file=g_file_new_for_path("../razor-test-dir");
ali@42
   357
    root_uri=g_file_get_uri(file);
ali@42
   358
    g_object_unref(file);
ali@42
   359
    g_setenv("RAZOR_ROOT",root_uri,TRUE);
ali@42
   360
    g_free(root_uri);
ali@38
   361
    transaction=plover_transaction_new_remove_with_leaves(pkgs,&err);
ali@38
   362
    if (!transaction && err)
ali@38
   363
	g_error("zappy-tools: %s",err->message);
ali@38
   364
    g_assert(PLOVER_IS_TRANSACTION(transaction));
ali@38
   365
    g_assert(!err);
ali@38
   366
    system=plover_transaction_get_system_set(transaction);
ali@38
   367
    g_assert(system);
ali@38
   368
    iter=plover_transaction_get_install_iterator(transaction,&err);
ali@38
   369
    if (!iter && err)
ali@38
   370
	g_error("plover_transaction_get_install_iterator: %s",err->message);
ali@38
   371
    g_assert(iter);
ali@38
   372
    g_assert(!err);
ali@38
   373
    g_assert(razor_install_iterator_next(iter,&pkg,&action,&count));
ali@38
   374
    g_assert_cmpint(action,==,RAZOR_INSTALL_ACTION_REMOVE);
ali@38
   375
    g_assert_cmpint(count,==,0);
ali@38
   376
    razor_package_get_details(system,pkg,RAZOR_DETAIL_NAME,&name,
ali@38
   377
      RAZOR_DETAIL_LAST);
ali@38
   378
    g_assert(!strcmp(name,"zappy-tools") || !strcmp(name,"zappy"));
ali@38
   379
    g_assert(razor_install_iterator_next(iter,&pkg,&action,&count));
ali@38
   380
    g_assert_cmpint(action,==,RAZOR_INSTALL_ACTION_REMOVE);
ali@38
   381
    g_assert_cmpint(count,==,0);
ali@38
   382
    razor_package_get_details(system,pkg,RAZOR_DETAIL_NAME,&name,
ali@38
   383
      RAZOR_DETAIL_LAST);
ali@38
   384
    g_assert(!strcmp(name,"zappy-tools") || !strcmp(name,"zappy"));
ali@38
   385
    g_assert(!razor_install_iterator_next(iter,&pkg,&action,&count));
ali@38
   386
    g_object_unref(transaction);
ali@38
   387
}
ali@38
   388
ali@38
   389
static void test_remove_nonexistant_with_leaves(void)
ali@38
   390
{
ali@38
   391
    PloverTransaction *transaction;
ali@38
   392
    char *pkgs[]={"nonexistant",NULL};
ali@42
   393
    gchar *root_uri;
ali@38
   394
    GError *err=NULL;
ali@42
   395
    GFile *file;
ali@42
   396
    file=g_file_new_for_path("../razor-test-dir");
ali@42
   397
    root_uri=g_file_get_uri(file);
ali@42
   398
    g_object_unref(file);
ali@42
   399
    g_setenv("RAZOR_ROOT",root_uri,TRUE);
ali@42
   400
    g_free(root_uri);
ali@38
   401
    transaction=plover_transaction_new_remove_with_leaves(pkgs,&err);
ali@38
   402
    g_assert(!transaction);
ali@38
   403
    g_assert(g_error_matches(err,PLOVER_GENERAL_ERROR,
ali@38
   404
      PLOVER_GENERAL_ERROR_NO_SUCH_PACKAGE));
ali@38
   405
    g_clear_error(&err);
ali@38
   406
}
ali@38
   407
ali@38
   408
static void test_remove_all(void)
ali@38
   409
{
ali@38
   410
    int i;
ali@38
   411
    PloverTransaction *transaction;
ali@38
   412
    struct razor_set *system;
ali@38
   413
    struct razor_install_iterator *iter;
ali@38
   414
    struct razor_package *pkg;
ali@38
   415
    enum razor_install_action action;
ali@38
   416
    int count;
ali@38
   417
    char *name;
ali@42
   418
    gchar *root_uri;
ali@38
   419
    GError *err=NULL;
ali@42
   420
    GFile *file;
ali@38
   421
    GList *expected=NULL,*lnk;
ali@42
   422
    file=g_file_new_for_path("../razor-test-dir");
ali@42
   423
    root_uri=g_file_get_uri(file);
ali@42
   424
    g_object_unref(file);
ali@42
   425
    g_setenv("RAZOR_ROOT",root_uri,TRUE);
ali@42
   426
    g_free(root_uri);
ali@38
   427
    transaction=plover_transaction_new_remove_with_leaves(NULL,&err);
ali@38
   428
    if (!transaction && err)
ali@38
   429
	g_error("remove-all: %s",err->message);
ali@38
   430
    g_assert(PLOVER_IS_TRANSACTION(transaction));
ali@38
   431
    g_assert(!err);
ali@38
   432
    system=plover_transaction_get_system_set(transaction);
ali@38
   433
    g_assert(system);
ali@38
   434
    for(i=0;i<G_N_ELEMENTS(zappy_packages);i++)
ali@38
   435
	expected=g_list_prepend(expected,
ali@38
   436
	  (gpointer)g_intern_string(zappy_packages[i]));
ali@38
   437
    iter=plover_transaction_get_install_iterator(transaction,&err);
ali@38
   438
    if (!iter && err)
ali@38
   439
	g_error("plover_transaction_get_install_iterator: %s",err->message);
ali@38
   440
    g_assert(iter);
ali@38
   441
    g_assert(!err);
ali@38
   442
    while(razor_install_iterator_next(iter,&pkg,&action,&count))
ali@38
   443
    {
ali@38
   444
	g_assert_cmpint(action,==,RAZOR_INSTALL_ACTION_REMOVE);
ali@38
   445
	g_assert_cmpint(count,==,0);
ali@38
   446
	razor_package_get_details(system,pkg,RAZOR_DETAIL_NAME,&name,
ali@38
   447
	  RAZOR_DETAIL_LAST);
ali@38
   448
	lnk=g_list_find(expected,g_intern_string(name));
ali@38
   449
	if (!lnk)
ali@38
   450
	    g_warning("Unexpected package to be removed: %s",name);
ali@38
   451
	else
ali@38
   452
	    expected=g_list_delete_link(expected,lnk);
ali@38
   453
    }
ali@38
   454
    if (expected)
ali@38
   455
	g_warning("%d package%s not removed, including %s",
ali@38
   456
	  g_list_length(expected),g_list_length(expected)==1?"":"s",
ali@38
   457
	  expected->data);
ali@38
   458
    g_object_unref(transaction);
ali@38
   459
}
ali@38
   460
ali@38
   461
static void test_change_installed(void)
ali@38
   462
{
ali@38
   463
    PloverTransaction *transaction;
ali@38
   464
    PloverPackageSet *package_set;
ali@38
   465
    GError *err=NULL;
ali@38
   466
    transaction=plover_transaction_new();
ali@38
   467
    g_assert(PLOVER_IS_TRANSACTION(transaction));
ali@38
   468
    if (!plover_transaction_root_open(transaction,"../razor-test-dir",&err))
ali@38
   469
    {
ali@38
   470
	g_assert(err && err->message);
ali@38
   471
	g_error("../razor-test-dir: %s",err->message);
ali@38
   472
    }
ali@38
   473
    g_assert(!err);
ali@38
   474
    g_assert(plover_transaction_get_system_set(transaction));
ali@38
   475
    package_set=plover_package_set_new_from_yum("../yum-repo-test-dir",NULL,
ali@38
   476
      &err);
ali@38
   477
    if (!package_set)
ali@38
   478
	g_error("../yum-repo-test-dir: %s",err->message);
ali@38
   479
    plover_transaction_set_installed(transaction,package_set);
ali@38
   480
    g_object_unref(package_set);
ali@38
   481
    g_object_unref(transaction);
ali@38
   482
}
ali@38
   483
ali@38
   484
int main(int argc,char **argv)
ali@38
   485
{
ali@38
   486
    g_test_init(&argc,&argv,NULL);
ali@38
   487
    razor_set_lua_loader("posix",(void (*)())luaopen_posix);
ali@38
   488
    g_test_bug_base("mailto:ali@juiblex.co.uk");
ali@38
   489
    g_test_add_func("/transaction/installed-system-set",
ali@38
   490
      test_installed_system_set);
ali@38
   491
    g_test_add_func("/transaction/update-noop",test_update_noop);
ali@38
   492
    g_test_add_func("/transaction/update-nonexistant",test_update_nonexistant);
ali@38
   493
    g_test_add_func("/transaction/install",test_install);
ali@38
   494
    g_test_add_func("/transaction/install-nonexistant",
ali@38
   495
      test_install_nonexistant);
ali@38
   496
    g_test_add_func("/transaction/install-uninstallable",
ali@38
   497
      test_install_uninstallable);
ali@38
   498
    g_test_add_func("/transaction/unsatisfied",test_unsatisfied);
ali@38
   499
    g_test_add_func("/transaction/remove",test_remove);
ali@38
   500
    g_test_add_func("/transaction/remove-nonexistant",test_remove_nonexistant);
ali@38
   501
    g_test_add_func("/transaction/commit",test_commit);
ali@38
   502
    g_test_add_func("/transaction/remove-with-leaves",test_remove_with_leaves);
ali@38
   503
    g_test_add_func("/transaction/remove-nonexistant-with-leaves",
ali@38
   504
      test_remove_nonexistant_with_leaves);
ali@38
   505
    g_test_add_func("/transaction/remove-all",test_remove_all);
ali@38
   506
    g_test_add_func("/transaction/change-installed",test_change_installed);
ali@38
   507
    return g_test_run();
ali@38
   508
}