1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
3
* Copyright (C) 2007-2010 Richard Hughes <richard@hughsie.com>
5
* Licensed under the GNU Lesser General Public License Version 2.1
7
* This library is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Lesser General Public
9
* License as published by the Free Software Foundation; either
10
* version 2.1 of the License, or (at your option) any later version.
12
* This library is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this library; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24
#include <glib-object.h>
25
#include <glib/gstdio.h>
26
#include <gio/gunixsocketaddress.h>
28
#include "pk-catalog.h"
29
#include "pk-client.h"
30
#include "pk-client-helper.h"
31
#include "pk-common.h"
32
#include "pk-control.h"
33
#include "pk-console-shared.h"
34
#include "pk-desktop.h"
36
#include "pk-package.h"
37
#include "pk-package-id.h"
38
#include "pk-package-ids.h"
39
#include "pk-package-sack.h"
40
#include "pk-results.h"
42
#include "pk-task-text.h"
43
#include "pk-task-wrapper.h"
44
#include "pk-transaction-list.h"
45
#include "pk-version.h"
46
#include "pk-control-sync.h"
47
#include "pk-client-sync.h"
48
#include "pk-progress-bar.h"
49
#include "pk-service-pack.h"
52
/** ver:1.0 ***********************************************************/
53
static GMainLoop *_test_loop = NULL;
54
static guint _test_loop_timeout_id = 0;
57
_g_test_hang_check_cb (gpointer user_data)
59
guint timeout_ms = *((guint*) user_data);
60
g_main_loop_quit (_test_loop);
61
g_warning ("loop not completed in %ims", timeout_ms);
62
g_assert_not_reached ();
67
* _g_test_loop_run_with_timeout:
70
_g_test_loop_run_with_timeout (guint timeout_ms)
72
g_assert (_test_loop_timeout_id == 0);
73
_test_loop = g_main_loop_new (NULL, FALSE);
74
_test_loop_timeout_id = g_timeout_add (timeout_ms, _g_test_hang_check_cb, &timeout_ms);
75
g_main_loop_run (_test_loop);
80
_g_test_hang_wait_cb (gpointer user_data)
82
g_main_loop_quit (_test_loop);
83
_test_loop_timeout_id = 0;
91
_g_test_loop_wait (guint timeout_ms)
93
g_assert (_test_loop_timeout_id == 0);
94
_test_loop = g_main_loop_new (NULL, FALSE);
95
_test_loop_timeout_id = g_timeout_add (timeout_ms, _g_test_hang_wait_cb, &timeout_ms);
96
g_main_loop_run (_test_loop);
104
_g_test_loop_quit (void)
106
if (_test_loop_timeout_id > 0) {
107
g_source_remove (_test_loop_timeout_id);
108
_test_loop_timeout_id = 0;
110
if (_test_loop != NULL) {
111
g_main_loop_quit (_test_loop);
112
g_main_loop_unref (_test_loop);
117
/**********************************************************************/
120
pk_test_bitfield_func (void)
127
/* check we can convert filter bitfield to text (none) */
128
text = pk_filter_bitfield_to_string (pk_bitfield_value (PK_FILTER_ENUM_NONE));
129
g_assert_cmpstr (text, ==, "none");
132
/* check we can invert a bit 1 -> 0 */
133
values = pk_bitfield_value (PK_FILTER_ENUM_NOT_DEVELOPMENT) | pk_bitfield_value (PK_FILTER_ENUM_NOT_NEWEST);
134
pk_bitfield_invert (values, PK_FILTER_ENUM_NOT_DEVELOPMENT);
135
g_assert_cmpint (values, ==, pk_bitfield_value (PK_FILTER_ENUM_NOT_NEWEST));
137
/* check we can invert a bit 0 -> 1 */
139
pk_bitfield_invert (values, PK_FILTER_ENUM_NOT_DEVELOPMENT);
140
g_assert_cmpint (values, ==, pk_bitfield_value (PK_FILTER_ENUM_NOT_DEVELOPMENT));
142
/* check we can convert filter bitfield to text (single) */
143
text = pk_filter_bitfield_to_string (pk_bitfield_value (PK_FILTER_ENUM_NOT_DEVELOPMENT));
144
g_assert_cmpstr (text, ==, "~devel");
147
/* check we can convert filter bitfield to text (plural) */
148
text = pk_filter_bitfield_to_string (pk_bitfield_value (PK_FILTER_ENUM_NOT_DEVELOPMENT) |
149
pk_bitfield_value (PK_FILTER_ENUM_GUI) |
150
pk_bitfield_value (PK_FILTER_ENUM_NEWEST));
151
g_assert_cmpstr (text, ==, "~devel;gui;newest");
154
/* check we can convert filter text to bitfield (none) */
155
filter = pk_filter_bitfield_from_string ("none");
156
g_assert_cmpint (filter, ==, pk_bitfield_value (PK_FILTER_ENUM_NONE));
158
/* check we can convert filter text to bitfield (single) */
159
filter = pk_filter_bitfield_from_string ("~devel");
160
g_assert_cmpint (filter, ==, pk_bitfield_value (PK_FILTER_ENUM_NOT_DEVELOPMENT));
162
/* check we can convert filter text to bitfield (plural) */
163
filter = pk_filter_bitfield_from_string ("~devel;gui;newest");
164
g_assert_cmpint (filter, ==, (pk_bitfield_value (PK_FILTER_ENUM_NOT_DEVELOPMENT) |
165
pk_bitfield_value (PK_FILTER_ENUM_GUI) |
166
pk_bitfield_value (PK_FILTER_ENUM_NEWEST)));
168
/* check we can add / remove bitfield */
169
filter = pk_bitfield_value (PK_FILTER_ENUM_NOT_DEVELOPMENT) |
170
pk_bitfield_value (PK_FILTER_ENUM_GUI) |
171
pk_bitfield_value (PK_FILTER_ENUM_NEWEST);
172
pk_bitfield_add (filter, PK_FILTER_ENUM_NOT_FREE);
173
pk_bitfield_remove (filter, PK_FILTER_ENUM_NOT_DEVELOPMENT);
174
text = pk_filter_bitfield_to_string (filter);
175
g_assert_cmpstr (text, ==, "gui;~free;newest");
178
/* check we can test enum presence */
179
filter = pk_bitfield_value (PK_FILTER_ENUM_NOT_DEVELOPMENT) |
180
pk_bitfield_value (PK_FILTER_ENUM_GUI) |
181
pk_bitfield_value (PK_FILTER_ENUM_NEWEST);
182
g_assert (pk_bitfield_contain (filter, PK_FILTER_ENUM_NOT_DEVELOPMENT));
184
/* check we can test enum false-presence */
185
g_assert (!pk_bitfield_contain (filter, PK_FILTER_ENUM_FREE));
187
/* check we can add / remove bitfield to nothing */
188
filter = pk_bitfield_value (PK_FILTER_ENUM_NOT_DEVELOPMENT);
189
pk_bitfield_remove (filter, PK_FILTER_ENUM_NOT_DEVELOPMENT);
190
text = pk_filter_bitfield_to_string (filter);
191
g_assert_cmpstr (text, ==, "none");
194
/* role bitfield from enums (unknown) */
195
values = pk_bitfield_from_enums (PK_ROLE_ENUM_UNKNOWN, -1);
196
g_assert_cmpint (values, ==, pk_bitfield_value (PK_ROLE_ENUM_UNKNOWN));
198
/* role bitfield from enums (random) */
199
values = pk_bitfield_from_enums (PK_ROLE_ENUM_SEARCH_GROUP, PK_ROLE_ENUM_SEARCH_DETAILS, -1);
200
g_assert_cmpint (values, ==, (pk_bitfield_value (PK_ROLE_ENUM_SEARCH_DETAILS) |
201
pk_bitfield_value (PK_ROLE_ENUM_SEARCH_GROUP)));
203
/* group bitfield from enums (unknown) */
204
values = pk_bitfield_from_enums (PK_GROUP_ENUM_UNKNOWN, -1);
205
g_assert_cmpint (values, ==, pk_bitfield_value (PK_GROUP_ENUM_UNKNOWN));
207
/* group bitfield from enums (random) */
208
values = pk_bitfield_from_enums (PK_GROUP_ENUM_ACCESSIBILITY, -1);
209
g_assert_cmpint (values, ==, (pk_bitfield_value (PK_GROUP_ENUM_ACCESSIBILITY)));
211
/* group bitfield to text (unknown) */
212
values = pk_bitfield_from_enums (PK_GROUP_ENUM_UNKNOWN, -1);
213
text = pk_group_bitfield_to_string (values);
214
g_assert_cmpstr (text, ==, "unknown");
217
/* group bitfield to text (first and last) */
218
values = pk_bitfield_from_enums (PK_GROUP_ENUM_ACCESSIBILITY, PK_GROUP_ENUM_UNKNOWN, -1);
219
text = pk_group_bitfield_to_string (values);
220
g_assert_cmpstr (text, ==, "unknown;accessibility");
223
/* group bitfield to text (random) */
224
values = pk_bitfield_from_enums (PK_GROUP_ENUM_UNKNOWN, PK_GROUP_ENUM_REPOS, -1);
225
text = pk_group_bitfield_to_string (values);
226
g_assert_cmpstr (text, ==, "unknown;repos");
229
/* priority check missing */
230
values = pk_bitfield_value (PK_ROLE_ENUM_SEARCH_DETAILS) |
231
pk_bitfield_value (PK_ROLE_ENUM_SEARCH_GROUP);
232
value = pk_bitfield_contain_priority (values, PK_ROLE_ENUM_SEARCH_FILE, -1);
233
g_assert_cmpint (value, ==, -1);
235
/* priority check first */
236
value = pk_bitfield_contain_priority (values, PK_ROLE_ENUM_SEARCH_GROUP, -1);
237
g_assert_cmpint (value, ==, PK_ROLE_ENUM_SEARCH_GROUP);
239
/* priority check second, correct */
240
value = pk_bitfield_contain_priority (values, PK_ROLE_ENUM_SEARCH_FILE, PK_ROLE_ENUM_SEARCH_GROUP, -1);
241
g_assert_cmpint (value, ==, PK_ROLE_ENUM_SEARCH_GROUP);
245
pk_test_catalog_lookup_cb (GObject *object, GAsyncResult *res, gpointer user_data)
247
PkCatalog *catalog = PK_CATALOG (object);
248
GError *error = NULL;
253
/* get the results */
254
array = pk_catalog_lookup_finish (catalog, res, &error);
255
g_assert_no_error (error);
256
g_assert (array != NULL);
257
g_assert_cmpint (array->len, ==, 3);
259
/* list for shits and giggles */
260
for (i=0; i<array->len; i++) {
261
package = g_ptr_array_index (array, i);
262
g_debug ("%i\t%s", i, pk_package_get_id (package));
264
g_ptr_array_unref (array);
265
_g_test_loop_quit ();
269
pk_test_catalog_progress_cb (PkProgress *progress, PkProgressType type, gpointer user_data)
272
if (type == PK_PROGRESS_TYPE_STATUS) {
273
g_object_get (progress,
276
g_debug ("now %s", pk_status_enum_to_string (status));
281
pk_test_catalog_func (void)
285
catalog = pk_catalog_new ();
286
g_assert (catalog != NULL);
289
pk_catalog_lookup_async (catalog, TESTDATADIR "/test.catalog", NULL,
290
(PkProgressCallback) pk_test_catalog_progress_cb, NULL,
291
(GAsyncReadyCallback) pk_test_catalog_lookup_cb, NULL);
292
_g_test_loop_run_with_timeout (150000);
293
g_debug ("resolvd, searched, etc. in %f", g_test_timer_elapsed ());
295
g_object_unref (catalog);
299
* pk_test_client_helper_output_cb:
302
pk_test_client_helper_output_cb (GSocket *socket, GIOCondition condition, gpointer user_data)
304
GError *error = NULL;
309
/* the helper process exited */
310
if ((condition & G_IO_HUP) > 0) {
311
g_warning ("socket was disconnected");
317
if ((condition & G_IO_IN) > 0) {
318
len = g_socket_receive (socket, buffer, 6, NULL, &error);
319
g_assert_no_error (error);
320
g_assert_cmpint (len, >, 0);
323
if (g_strcmp0 (buffer, "pong\n") == 0) {
324
_g_test_loop_quit ();
328
g_warning ("child returned unexpected data: %s", buffer);
335
pk_test_client_helper_func (void)
338
GError *error = NULL;
340
PkClientHelper *client_helper;
341
const gchar *argv[] = { TESTDATADIR "/pk-client-helper-test.py", NULL };
342
const gchar *envp[] = { "DAVE=1", NULL };
343
GSocket *socket = NULL;
344
GSocketAddress *address = NULL;
348
client_helper = pk_client_helper_new ();
349
g_assert (client_helper != NULL);
351
/* unref without using */
352
g_object_unref (client_helper);
355
client_helper = pk_client_helper_new ();
356
g_assert (client_helper != NULL);
358
/* create a socket filename */
359
filename = g_build_filename (g_get_tmp_dir (), "pk-self-test.socket", NULL);
361
/* ensure previous sockets are deleted */
364
/* start a demo program */
365
ret = pk_client_helper_start (client_helper, filename, (gchar**) argv, (gchar**) envp, &error);
366
g_assert_no_error (error);
368
g_assert (g_file_test (filename, G_FILE_TEST_EXISTS));
371
socket = g_socket_new (G_SOCKET_FAMILY_UNIX, G_SOCKET_TYPE_STREAM, G_SOCKET_PROTOCOL_DEFAULT, &error);
372
g_assert_no_error (error);
373
g_assert (socket != NULL);
374
g_socket_set_blocking (socket, FALSE);
375
g_socket_set_keepalive (socket, TRUE);
378
address = g_unix_socket_address_new_with_type (filename, -1, G_UNIX_SOCKET_ADDRESS_PATH);
379
ret = g_socket_connect (socket, address, NULL, &error);
380
g_assert_no_error (error);
383
/* socket has data */
384
source = g_socket_create_source (socket, G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL, NULL);
385
g_source_set_callback (source, (GSourceFunc) pk_test_client_helper_output_cb, NULL, NULL);
386
g_source_attach (source, NULL);
389
wrote = g_socket_send (socket, "ping\n", 5, NULL, &error);
390
g_assert_no_error (error);
391
g_assert_cmpint (wrote, ==, 5);
393
/* run for a few seconds */
394
_g_test_loop_run_with_timeout (1000);
396
/* stop the demo program */
397
ret = pk_client_helper_stop (client_helper, &error);
398
g_assert_no_error (error);
405
g_object_unref (socket);
406
g_object_unref (address);
407
g_object_unref (client_helper);
411
pk_test_client_resolve_cb (GObject *object, GAsyncResult *res, gpointer user_data)
413
PkClient *client = PK_CLIENT (object);
414
GError *error = NULL;
415
PkResults *results = NULL;
416
PkExitEnum exit_enum;
420
/* get the results */
421
results = pk_client_generic_finish (client, res, &error);
422
g_assert_no_error (error);
423
g_assert (results != NULL);
425
exit_enum = pk_results_get_exit_code (results);
426
g_assert_cmpint (exit_enum, ==, PK_EXIT_ENUM_SUCCESS);
428
packages = pk_results_get_package_array (results);
429
g_assert (packages != NULL);
432
g_object_get (client, "idle", &idle, NULL);
434
g_assert_cmpint (packages->len, ==, 2);
436
g_ptr_array_unref (packages);
438
g_debug ("results exit enum = %s", pk_exit_enum_to_string (exit_enum));
440
g_object_unref (results);
441
_g_test_loop_quit ();
445
pk_test_client_get_details_cb (GObject *object, GAsyncResult *res, gpointer user_data)
447
PkClient *client = PK_CLIENT (object);
448
GError *error = NULL;
449
PkResults *results = NULL;
450
PkExitEnum exit_enum;
453
/* get the results */
454
results = pk_client_generic_finish (client, res, &error);
455
g_assert_no_error (error);
456
g_assert (results != NULL);
458
exit_enum = pk_results_get_exit_code (results);
459
g_assert_cmpint (exit_enum, ==, PK_EXIT_ENUM_SUCCESS);
461
details = pk_results_get_details_array (results);
462
g_assert (details != NULL);
463
g_assert_cmpint (details->len, ==, 1);
465
g_ptr_array_unref (details);
467
g_debug ("results exit enum = %s", pk_exit_enum_to_string (exit_enum));
469
g_object_unref (results);
470
_g_test_loop_quit ();
474
pk_test_client_get_updates_cb (GObject *object, GAsyncResult *res, gpointer user_data)
476
PkClient *client = PK_CLIENT (object);
477
GError *error = NULL;
478
PkResults *results = NULL;
479
PkExitEnum exit_enum;
483
/* get the results */
484
results = pk_client_generic_finish (client, res, &error);
485
g_assert_no_error (error);
486
g_assert (results != NULL);
488
exit_enum = pk_results_get_exit_code (results);
489
g_assert_cmpint (exit_enum, ==, PK_EXIT_ENUM_SUCCESS);
491
sack = pk_results_get_package_sack (results);
492
g_assert (sack != NULL);
495
size = pk_package_sack_get_size (sack);
496
g_assert_cmpint (size, ==, 3);
498
g_object_unref (sack);
500
g_debug ("results exit enum = %s", pk_exit_enum_to_string (exit_enum));
502
g_object_unref (results);
503
_g_test_loop_quit ();
507
pk_test_client_search_name_cb (GObject *object, GAsyncResult *res, gpointer user_data)
509
PkClient *client = PK_CLIENT (object);
510
GError *error = NULL;
511
PkResults *results = NULL;
512
PkExitEnum exit_enum;
513
PkError *error_code = NULL;
515
/* get the results */
516
results = pk_client_generic_finish (client, res, &error);
517
g_assert_no_error (error);
518
g_assert (results != NULL);
520
exit_enum = pk_results_get_exit_code (results);
521
g_assert_cmpint (exit_enum, ==, PK_EXIT_ENUM_CANCELLED);
523
/* check error code */
524
error_code = pk_results_get_error_code (results);
525
g_assert_cmpint (pk_error_get_code (error_code), ==, PK_ERROR_ENUM_TRANSACTION_CANCELLED);
526
g_assert_cmpstr (pk_error_get_details (error_code), ==, "The task was stopped successfully");
527
// g_assert_cmpstr (pk_error_get_details (error_code), ==, "transaction was cancelled");
529
if (error_code != NULL)
530
g_object_unref (error_code);
532
g_object_unref (results);
533
_g_test_loop_quit ();
537
pk_test_client_search_name_cancellable_cancelled_cb (GObject *object, GAsyncResult *res, gpointer user_data)
539
PkClient *client = PK_CLIENT (object);
540
GError *error = NULL;
541
PkResults *results = NULL;
542
results = pk_client_generic_finish (client, res, &error);
543
g_assert_error (error, G_IO_ERROR, G_IO_ERROR_CANCELLED);
544
g_assert (results == NULL);
545
_g_test_loop_quit ();
548
static guint _progress_cb = 0;
549
static guint _status_cb = 0;
550
static guint _package_cb = 0;
551
static guint _allow_cancel_cb = 0;
555
pk_test_client_progress_cb (PkProgress *progress, PkProgressType type, gpointer user_data)
558
if (type == PK_PROGRESS_TYPE_PACKAGE_ID)
560
if (type == PK_PROGRESS_TYPE_PERCENTAGE)
562
if (type == PK_PROGRESS_TYPE_SUBPERCENTAGE)
564
if (type == PK_PROGRESS_TYPE_ALLOW_CANCEL)
566
if (type == PK_PROGRESS_TYPE_STATUS)
569
/* get the running transaction id if we've not set it before */
570
g_object_get (progress, "transaction-id", &tid, NULL);
571
if (tid != NULL && _tid == NULL)
572
_tid = g_strdup (tid);
577
pk_test_client_cancel_cb (GCancellable *cancellable)
579
g_debug ("cancelling method");
580
g_cancellable_cancel (cancellable);
585
pk_test_client_download_cb (GObject *object, GAsyncResult *res, gpointer user_data)
587
PkClient *client = PK_CLIENT (object);
588
GError *error = NULL;
589
PkResults *results = NULL;
590
PkExitEnum exit_enum;
592
GPtrArray *array = NULL;
593
gchar *package_id = NULL;
594
gchar **files = NULL;
596
/* get the results */
597
results = pk_client_generic_finish (client, res, &error);
598
g_assert_no_error (error);
599
g_assert (results != NULL);
601
exit_enum = pk_results_get_exit_code (results);
602
g_assert_cmpint (exit_enum, ==, PK_EXIT_ENUM_SUCCESS);
605
array = pk_results_get_files_array (results);
606
g_assert_cmpint (array->len, ==, 2);
609
item = g_ptr_array_index (array, 0);
611
"package-id", &package_id,
614
g_assert_cmpstr (package_id, ==, "powertop-common;1.8-1.fc8;i386;fedora");
615
g_assert_cmpint (g_strv_length (files), ==, 1);
616
g_assert_cmpstr (files[0], ==, "/tmp/powertop-common-1.8-1.fc8.rpm");
620
g_ptr_array_unref (array);
622
g_object_unref (results);
623
_g_test_loop_quit ();
628
pk_test_client_recursive_signal_cb (PkControl *control, gpointer user_data)
631
ret = pk_control_get_properties (control, NULL, NULL);
637
pk_test_client_notify_idle_cb (PkClient *client, GParamSpec *pspec, gpointer user_data)
640
g_object_get (client, "idle", &idle, NULL);
641
g_debug ("idle=%i", idle);
645
pk_test_client_update_system_socket_test_cb (GObject *object, GAsyncResult *res, gpointer user_data)
647
PkClient *client = PK_CLIENT (object);
648
GError *error = NULL;
649
PkResults *results = NULL;
652
/* get the results */
653
results = pk_client_generic_finish (client, res, &error);
654
g_assert_no_error (error);
655
g_assert (results != NULL);
657
/* make sure we handled the ping/pong frontend-socket thing, which is 5 + 1 */
658
messages = pk_results_get_message_array (results);
659
g_assert_cmpint (messages->len, ==, 6);
660
g_ptr_array_unref (messages);
662
g_object_unref (results);
663
_g_test_loop_quit ();
667
pk_test_client_func (void)
672
GCancellable *cancellable;
675
GError *error = NULL;
676
PkProgress *progress;
680
// PkResults *results;
684
file = pk_client_get_user_temp ("self-test", NULL);
685
g_assert (g_str_has_suffix (file, "/.PackageKit/self-test"));
686
g_assert (g_str_has_prefix (file, "/home/"));
689
/* test native TRUE */
690
ret = pk_client_is_file_native ("/tmp");
693
/* test native FALSE */
694
ret = pk_client_is_file_native ("/tmp/.gvfs/moo");
697
/* test resolve NULL */
698
file = pk_client_real_path (NULL);
699
g_assert (file == NULL);
701
/* test resolve /etc/hosts */
702
file = pk_client_real_path ("/etc/hosts");
703
g_assert_cmpstr (file, ==, "/etc/hosts");
706
/* test resolve /etc/../etc/hosts */
707
file = pk_client_real_path ("/etc/../etc/hosts");
708
g_assert_cmpstr (file, ==, "/etc/hosts");
713
client = pk_client_new ();
714
g_signal_connect (client, "notify::idle",
715
G_CALLBACK (pk_test_client_notify_idle_cb), NULL);
716
g_assert (client != NULL);
719
g_object_get (client, "idle", &ret, NULL);
722
/* resolve package */
723
package_ids = pk_package_ids_from_string ("glib2;2.14.0;i386;fedora&powertop");
724
pk_client_resolve_async (client, pk_bitfield_value (PK_FILTER_ENUM_INSTALLED), package_ids, NULL,
725
(PkProgressCallback) pk_test_client_progress_cb, NULL,
726
(GAsyncReadyCallback) pk_test_client_resolve_cb, NULL);
727
g_strfreev (package_ids);
728
_g_test_loop_run_with_timeout (15000);
729
g_debug ("resolved in %f", g_test_timer_elapsed ());
732
g_object_get (client, "idle", &ret, NULL);
735
/* get progress of past transaction */
736
progress = pk_client_get_progress (client, _tid, NULL, &error);
737
g_object_get (progress,
738
"transaction-id", &tid,
742
g_assert_cmpstr (tid, ==, _tid);
743
g_assert_cmpint (role, ==, PK_ROLE_ENUM_RESOLVE);
744
g_assert_cmpint (status, ==, PK_STATUS_ENUM_FINISHED);
745
g_debug ("got progress in %f", g_test_timer_elapsed ());
746
g_object_unref (progress);
751
g_assert_cmpint (_progress_cb, >, 0);
752
g_assert_cmpint (_status_cb, >, 0);
759
/* get details about package */
760
package_ids = pk_package_ids_from_id ("powertop;1.8-1.fc8;i386;fedora");
761
pk_client_get_details_async (client, package_ids, NULL,
762
(PkProgressCallback) pk_test_client_progress_cb, NULL,
763
(GAsyncReadyCallback) pk_test_client_get_details_cb, NULL);
764
g_strfreev (package_ids);
765
_g_test_loop_run_with_timeout (15000);
766
g_debug ("resolved in %f", g_test_timer_elapsed ());
769
g_assert_cmpint (_progress_cb, >, 0);
770
g_assert_cmpint (_status_cb, >, 0);
778
pk_client_get_updates_async (client, pk_bitfield_value (PK_FILTER_ENUM_NONE), NULL,
779
(PkProgressCallback) pk_test_client_progress_cb, NULL,
780
(GAsyncReadyCallback) pk_test_client_get_updates_cb, NULL);
781
_g_test_loop_run_with_timeout (15000);
782
g_debug ("got updates in %f", g_test_timer_elapsed ());
784
/* it takes more than 50ms to get the progress of the transaction, and if
785
* getting updates from internal cache, then it'll take a shed load less
786
* than this to complete */
787
if (g_test_timer_elapsed () > 100) {
788
/* got status updates */
789
g_assert_cmpint (_status_cb, >, 0);
793
cancellable = g_cancellable_new ();
794
values = g_strsplit ("power", "&", -1);
795
pk_client_search_names_async (client, pk_bitfield_value (PK_FILTER_ENUM_NONE), values, cancellable,
796
(PkProgressCallback) pk_test_client_progress_cb, NULL,
797
(GAsyncReadyCallback) pk_test_client_search_name_cb, NULL);
798
g_timeout_add (1000, (GSourceFunc) pk_test_client_cancel_cb, cancellable);
799
_g_test_loop_run_with_timeout (15000);
800
g_debug ("cancelled in %f", g_test_timer_elapsed ());
802
/* ensure we abort with error if we cancel */
803
pk_client_search_names_async (client, pk_bitfield_value (PK_FILTER_ENUM_NONE), values, cancellable,
804
(PkProgressCallback) pk_test_client_progress_cb, NULL,
805
(GAsyncReadyCallback) pk_test_client_search_name_cancellable_cancelled_cb, NULL);
806
_g_test_loop_run_with_timeout (15000);
811
g_cancellable_reset (cancellable);
813
/* do the update-system role to trigger the fake pipe stuff */
814
pk_client_update_system_async (client, TRUE, NULL,
815
(PkProgressCallback) pk_test_client_progress_cb, NULL,
816
(GAsyncReadyCallback) pk_test_client_update_system_socket_test_cb, NULL);
817
_g_test_loop_run_with_timeout (15000);
820
package_ids = pk_package_ids_from_id ("powertop;1.8-1.fc8;i386;fedora");
821
pk_client_download_packages_async (client, package_ids, "/tmp", cancellable,
822
(PkProgressCallback) pk_test_client_progress_cb, NULL,
823
(GAsyncReadyCallback) pk_test_client_download_cb, NULL);
824
g_strfreev (package_ids);
825
_g_test_loop_run_with_timeout (15000);
826
g_debug ("downloaded and copied in %f", g_test_timer_elapsed ());
828
/* test recursive signal handling */
830
g_signal_connect (client->priv->control, "repo-list-changed", G_CALLBACK (pk_test_client_recursive_signal_cb), NULL);
831
results = pk_client_repo_set_data (client, "dave", "moo", "data", NULL, NULL, NULL, NULL);
832
g_assert (results != NULL);
833
g_object_unref (results);
836
g_object_unref (cancellable);
837
g_object_unref (client);
841
pk_test_common_func (void)
846
/************************************************************
847
************** iso8601 ****************
848
************************************************************/
849
/* get present iso8601 */
850
present = pk_iso8601_present ();
851
g_assert (present != NULL);
854
/************************************************************
855
************** Date handling ****************
856
************************************************************/
857
/* zero length date */
858
date = pk_iso8601_to_date ("");
859
g_assert (date == NULL);
861
/* no day specified */
862
date = pk_iso8601_to_date ("2004-01");
863
g_assert (date == NULL);
865
/* date _and_ time specified */
866
date = pk_iso8601_to_date ("2009-05-08 13:11:12");
867
g_assert_cmpint (date->day, ==, 8);
868
g_assert_cmpint (date->month, ==, 5);
869
g_assert_cmpint (date->year, ==, 2009);
872
/* correct date format */
873
date = pk_iso8601_to_date ("2004-02-01");
874
g_assert_cmpint (date->day, ==, 1);
875
g_assert_cmpint (date->month, ==, 2);
876
g_assert_cmpint (date->year, ==, 2004);
881
pk_test_console_func (void)
886
ret = pk_console_get_prompt ("press enter", TRUE);
890
ret = pk_console_get_prompt ("press enter", TRUE);
894
ret = pk_console_get_prompt ("press Y", TRUE);
898
ret = pk_console_get_prompt ("press N", TRUE);
902
static guint _refcount = 0;
905
pk_test_control_get_tid_cb (GObject *object, GAsyncResult *res, gpointer user_data)
907
PkControl *control = PK_CONTROL (object);
908
GError *error = NULL;
912
tid = pk_control_get_tid_finish (control, res, &error);
913
g_assert_no_error (error);
914
g_assert (tid != NULL);
916
g_debug ("tid = %s", tid);
918
if (--_refcount == 0)
919
_g_test_loop_quit ();
923
pk_test_control_get_properties_cb (GObject *object, GAsyncResult *res, gpointer user_data)
925
PkControl *control = PK_CONTROL (object);
926
GError *error = NULL;
934
ret = pk_control_get_properties_finish (control, res, &error);
935
g_assert_no_error (error);
939
g_object_get (control,
946
/* check mime_types */
947
g_assert_cmpstr (text, ==, "application/x-rpm;application/x-deb");
951
text = pk_role_bitfield_to_string (roles);
952
g_assert_cmpstr (text, ==, "cancel;get-depends;get-details;get-files;get-packages;get-repo-list;"
953
"get-requires;get-update-detail;get-updates;install-files;install-packages;install-signature;"
954
"refresh-cache;remove-packages;repo-enable;repo-set-data;resolve;rollback;"
955
"search-details;search-file;search-group;search-name;update-packages;update-system;"
956
"what-provides;download-packages;get-distro-upgrades;simulate-install-packages;"
957
"simulate-remove-packages;simulate-update-packages");
961
text = pk_filter_bitfield_to_string (filters);
962
g_assert_cmpstr (text, ==, "installed;devel;gui");
966
text = pk_group_bitfield_to_string (groups);
967
g_assert_cmpstr (text, ==, "accessibility;games;system");
968
g_debug ("groups = %s", text);
972
if (--_refcount == 0)
973
_g_test_loop_quit ();
977
pk_test_control_get_time_since_action_cb (GObject *object, GAsyncResult *res, gpointer user_data)
979
PkControl *control = PK_CONTROL (object);
980
GError *error = NULL;
984
seconds = pk_control_get_time_since_action_finish (control, res, &error);
985
g_assert_no_error (error);
986
g_assert_cmpint (seconds, !=, 0);
988
_g_test_loop_quit ();
992
pk_test_control_can_authorize_cb (GObject *object, GAsyncResult *res, gpointer user_data)
994
PkControl *control = PK_CONTROL (object);
995
GError *error = NULL;
996
PkAuthorizeEnum auth;
999
auth = pk_control_can_authorize_finish (control, res, &error);
1000
g_assert_no_error (error);
1001
g_assert_cmpint (auth, !=, PK_AUTHORIZE_ENUM_UNKNOWN);
1003
_g_test_loop_quit ();
1007
pk_test_control_func (void)
1011
GError *error = NULL;
1016
const guint LOOP_SIZE = 5;
1019
control = pk_control_new ();
1020
g_assert (control != NULL);
1024
pk_control_get_tid_async (control, NULL, (GAsyncReadyCallback) pk_test_control_get_tid_cb, NULL);
1025
_g_test_loop_run_with_timeout (5000);
1026
g_debug ("got tid in %f", g_test_timer_elapsed ());
1028
/* get multiple TIDs async */
1029
_refcount = LOOP_SIZE;
1030
for (i=0; i<_refcount; i++) {
1031
g_debug ("getting #%i", i+1);
1032
pk_control_get_tid_async (control, NULL, (GAsyncReadyCallback) pk_test_control_get_tid_cb, NULL);
1034
_g_test_loop_run_with_timeout (5000);
1035
g_debug ("got %i tids in %f", LOOP_SIZE, g_test_timer_elapsed ());
1037
/* get properties async */
1039
pk_control_get_properties_async (control, NULL, (GAsyncReadyCallback) pk_test_control_get_properties_cb, NULL);
1040
_g_test_loop_run_with_timeout (5000);
1041
g_debug ("got properties types in %f", g_test_timer_elapsed ());
1043
/* get properties async (again, to test caching) */
1045
pk_control_get_properties_async (control, NULL, (GAsyncReadyCallback) pk_test_control_get_properties_cb, NULL);
1046
_g_test_loop_run_with_timeout (5000);
1047
g_debug ("got properties in %f", g_test_timer_elapsed ());
1049
/* do multiple requests async */
1050
_refcount = LOOP_SIZE * 4;
1051
for (i=0; i<_refcount; i++) {
1052
g_debug ("getting #%i", i+1);
1053
pk_control_get_tid_async (control, NULL, (GAsyncReadyCallback) pk_test_control_get_tid_cb, NULL);
1054
pk_control_get_properties_async (control, NULL, (GAsyncReadyCallback) pk_test_control_get_properties_cb, NULL);
1055
pk_control_get_tid_async (control, NULL, (GAsyncReadyCallback) pk_test_control_get_tid_cb, NULL);
1056
pk_control_get_properties_async (control, NULL, (GAsyncReadyCallback) pk_test_control_get_properties_cb, NULL);
1058
_g_test_loop_run_with_timeout (5000);
1059
g_debug ("got %i 2*properties and 2*tids in %f", LOOP_SIZE, g_test_timer_elapsed ());
1061
/* get time since async */
1062
pk_control_get_time_since_action_async (control, PK_ROLE_ENUM_GET_UPDATES, NULL, (GAsyncReadyCallback) pk_test_control_get_time_since_action_cb, NULL);
1063
_g_test_loop_run_with_timeout (5000);
1064
g_debug ("got get time since in %f", g_test_timer_elapsed ());
1066
/* get auth state async */
1067
pk_control_can_authorize_async (control, "org.freedesktop.packagekit.system-update", NULL,
1068
(GAsyncReadyCallback) pk_test_control_can_authorize_cb, NULL);
1069
_g_test_loop_run_with_timeout (5000);
1070
g_debug ("get auth state in %f", g_test_timer_elapsed ());
1073
g_object_get (control, "version-major", &version, NULL);
1074
g_assert_cmpint (version, ==, PK_MAJOR_VERSION);
1077
g_object_get (control, "version-minor", &version, NULL);
1078
g_assert_cmpint (version, ==, PK_MINOR_VERSION);
1081
g_object_get (control, "version-micro", &version, NULL);
1082
g_assert_cmpint (version, ==, PK_MICRO_VERSION);
1084
/* get properties sync */
1085
ret = pk_control_get_properties (control, NULL, &error);
1086
g_assert_no_error (error);
1090
g_object_get (control,
1095
text = pk_role_bitfield_to_string (roles);
1096
g_assert_cmpstr (text, ==, "cancel;get-depends;get-details;get-files;get-packages;get-repo-list;"
1097
"get-requires;get-update-detail;get-updates;install-files;install-packages;install-signature;"
1098
"refresh-cache;remove-packages;repo-enable;repo-set-data;resolve;rollback;"
1099
"search-details;search-file;search-group;search-name;update-packages;update-system;"
1100
"what-provides;download-packages;get-distro-upgrades;simulate-install-packages;"
1101
"simulate-remove-packages;simulate-update-packages");
1104
g_object_unref (control);
1108
pk_test_desktop_func (void)
1114
GError *error = NULL;
1116
desktop = pk_desktop_new ();
1117
g_assert (desktop != NULL);
1119
/* get package when not valid */
1120
package = pk_desktop_get_package_for_file (desktop, "/usr/share/applications/gpk-update-viewer.desktop", NULL);
1121
g_assert (package == NULL);
1123
/* file does not exist */
1124
ret = g_file_test (PK_DESKTOP_DEFAULT_DATABASE, G_FILE_TEST_EXISTS);
1126
g_warning ("skipping checks as database does not exist");
1131
ret = pk_desktop_open_database (desktop, &error);
1132
g_assert_no_error (error);
1136
package = pk_desktop_get_package_for_file (desktop, "/usr/share/applications/gpk-update-viewer.desktop", NULL);
1138
/* dummy, not yum */
1139
if (g_strcmp0 (package, "vips-doc") == 0); {
1140
g_debug ("created db with dummy, skipping remaining tests");
1143
g_assert_cmpstr (package, ==, "gnome-packagekit");
1147
array = pk_desktop_get_files_for_package (desktop, "gnome-packagekit", NULL);
1148
g_assert (array != NULL);
1149
g_assert_cmpint (array->len, >=, 5);
1150
g_ptr_array_unref (array);
1152
/* get shown files */
1153
array = pk_desktop_get_shown_for_package (desktop, "gnome-packagekit", NULL);
1154
g_assert (array != NULL);
1155
g_assert_cmpint (array->len, >=, 3);
1156
g_ptr_array_unref (array);
1158
g_object_unref (desktop);
1162
pk_test_enum_func (void)
1164
const gchar *string;
1165
PkRoleEnum role_value;
1169
role_value = pk_role_enum_from_string ("search-file");
1170
g_assert_cmpint (role_value, ==, PK_ROLE_ENUM_SEARCH_FILE);
1173
string = pk_role_enum_to_string (PK_ROLE_ENUM_SEARCH_FILE);
1174
g_assert_cmpstr (string, ==, "search-file");
1176
/* check we convert all the role bitfield */
1177
for (i=1; i<PK_ROLE_ENUM_LAST; i++) {
1178
string = pk_role_enum_to_string (i);
1179
if (string == NULL) {
1180
/* so we get the value of i in the assert text */
1181
g_assert_cmpint (0, ==, i);
1186
/* check we convert all the status bitfield */
1187
for (i=1; i<PK_STATUS_ENUM_LAST; i++) {
1188
string = pk_status_enum_to_string (i);
1189
if (string == NULL) {
1190
/* so we get the value of i in the assert text */
1191
g_assert_cmpint (0, ==, i);
1196
/* check we convert all the exit bitfield */
1197
for (i=0; i<PK_EXIT_ENUM_LAST; i++) {
1198
string = pk_exit_enum_to_string (i);
1199
if (string == NULL) {
1200
/* so we get the value of i in the assert text */
1201
g_assert_cmpint (0, ==, i);
1206
/* check we convert all the filter bitfield */
1207
for (i=0; i<PK_FILTER_ENUM_LAST; i++) {
1208
string = pk_filter_enum_to_string (i);
1209
if (string == NULL) {
1210
/* so we get the value of i in the assert text */
1211
g_assert_cmpint (0, ==, i);
1216
/* check we convert all the restart bitfield */
1217
for (i=0; i<PK_RESTART_ENUM_LAST; i++) {
1218
string = pk_restart_enum_to_string (i);
1219
if (string == NULL) {
1220
/* so we get the value of i in the assert text */
1221
g_assert_cmpint (0, ==, i);
1226
/* check we convert all the error_code bitfield */
1227
for (i=0; i<PK_ERROR_ENUM_LAST; i++) {
1228
string = pk_error_enum_to_string (i);
1229
if (string == NULL) {
1230
/* so we get the value of i in the assert text */
1231
g_assert_cmpint (0, ==, i);
1236
/* check we convert all the group bitfield */
1237
for (i=1; i<PK_GROUP_ENUM_LAST; i++) {
1238
string = pk_group_enum_to_string (i);
1239
if (string == NULL) {
1240
/* so we get the value of i in the assert text */
1241
g_assert_cmpint (0, ==, i);
1246
/* check we convert all the info bitfield */
1247
for (i=1; i<PK_INFO_ENUM_LAST; i++) {
1248
string = pk_info_enum_to_string (i);
1249
if (string == NULL) {
1250
/* so we get the value of i in the assert text */
1251
g_assert_cmpint (0, ==, i);
1256
/* check we convert all the sig_type bitfield */
1257
for (i=0; i<PK_SIGTYPE_ENUM_LAST; i++) {
1258
string = pk_sig_type_enum_to_string (i);
1259
if (string == NULL) {
1260
/* so we get the value of i in the assert text */
1261
g_assert_cmpint (0, ==, i);
1266
/* check we convert all the upgrade bitfield */
1267
for (i=0; i<PK_DISTRO_UPGRADE_ENUM_LAST; i++) {
1268
string = pk_distro_upgrade_enum_to_string (i);
1269
if (string == NULL) {
1270
/* so we get the value of i in the assert text */
1271
g_assert_cmpint (0, ==, i);
1276
/* check we convert all the license bitfield */
1277
for (i=0; i<PK_LICENSE_ENUM_LAST; i++) {
1278
string = pk_license_enum_to_string (i);
1279
if (string == NULL) {
1280
/* so we get the value of i in the assert text */
1281
g_assert_cmpint (0, ==, i);
1286
/* check we convert all the media type bitfield */
1287
for (i=0; i<PK_MEDIA_TYPE_ENUM_LAST; i++) {
1288
string = pk_media_type_enum_to_string (i);
1289
if (string == NULL) {
1290
/* so we get the value of i in the assert text */
1291
g_assert_cmpint (0, ==, i);
1298
pk_test_package_id_func (void)
1304
/* check not valid - NULL */
1305
ret = pk_package_id_check (NULL);
1308
/* check not valid - no name */
1309
ret = pk_package_id_check (";0.0.1;i386;fedora");
1312
/* check not valid - invalid */
1313
ret = pk_package_id_check ("moo;0.0.1;i386");
1317
ret = pk_package_id_check ("moo;0.0.1;i386;fedora");
1321
text = pk_package_id_build ("moo", "0.0.1", "i386", "fedora");
1322
g_assert_cmpstr (text, ==, "moo;0.0.1;i386;fedora");
1325
/* id build partial */
1326
text = pk_package_id_build ("moo", NULL, NULL, NULL);
1327
g_assert_cmpstr (text, ==, "moo;;;");
1330
/* test printable */
1331
text = pk_package_id_to_printable ("moo;0.0.1;i386;fedora");
1332
g_assert_cmpstr (text, ==, "moo-0.0.1.i386");
1335
/* test printable no arch */
1336
text = pk_package_id_to_printable ("moo;0.0.1;;");
1337
g_assert_cmpstr (text, ==, "moo-0.0.1");
1340
/* test printable just name */
1341
text = pk_package_id_to_printable ("moo;;;");
1342
g_assert_cmpstr (text, ==, "moo");
1345
/* test on real packageid */
1346
sections = pk_package_id_split ("kde-i18n-csb;4:3.5.8~pre20071001-0ubuntu1;all;");
1347
g_assert (sections != NULL);
1348
g_assert_cmpstr (sections[0], ==, "kde-i18n-csb");
1349
g_assert_cmpstr (sections[1], ==, "4:3.5.8~pre20071001-0ubuntu1");
1350
g_assert_cmpstr (sections[2], ==, "all");
1351
g_assert_cmpstr (sections[3], ==, "");
1352
g_strfreev (sections);
1354
/* test on short packageid */
1355
sections = pk_package_id_split ("kde-i18n-csb;4:3.5.8~pre20071001-0ubuntu1;;");
1356
g_assert (sections != NULL);
1357
g_assert_cmpstr (sections[0], ==, "kde-i18n-csb");
1358
g_assert_cmpstr (sections[1], ==, "4:3.5.8~pre20071001-0ubuntu1");
1359
g_assert_cmpstr (sections[2], ==, "");
1360
g_assert_cmpstr (sections[3], ==, "");
1361
g_strfreev (sections);
1363
/* test fail under */
1364
sections = pk_package_id_split ("foo;moo");
1365
g_assert (sections == NULL);
1367
/* test fail over */
1368
sections = pk_package_id_split ("foo;moo;dave;clive;dan");
1369
g_assert (sections == NULL);
1371
/* test fail missing first */
1372
sections = pk_package_id_split (";0.1.2;i386;data");
1373
g_assert (sections == NULL);
1377
pk_test_package_ids_func (void)
1380
gchar *package_ids_blank[] = {};
1381
gchar **package_ids;
1384
package_ids = pk_package_ids_from_string ("foo;0.0.1;i386;fedora&bar;0.1.1;noarch;livna");
1385
g_assert (package_ids != NULL);
1388
g_assert_cmpint (g_strv_length (package_ids), ==, 2);
1391
ret = pk_package_ids_check (package_ids_blank);
1395
ret = pk_package_ids_check (package_ids);
1398
g_strfreev (package_ids);
1402
pk_test_package_sack_resolve_cb (GObject *object, GAsyncResult *res, gpointer user_data)
1404
PkPackageSack *sack = PK_PACKAGE_SACK (object);
1405
GError *error = NULL;
1408
/* get the result */
1409
ret = pk_package_sack_merge_generic_finish (sack, res, &error);
1410
g_assert_no_error (error);
1413
_g_test_loop_quit ();
1417
pk_test_package_sack_details_cb (GObject *object, GAsyncResult *res, gpointer user_data)
1419
PkPackageSack *sack = PK_PACKAGE_SACK (object);
1420
GError *error = NULL;
1423
/* get the result */
1424
ret = pk_package_sack_merge_generic_finish (sack, res, &error);
1425
g_assert_no_error (error);
1428
_g_test_loop_quit ();
1432
pk_test_package_sack_update_detail_cb (GObject *object, GAsyncResult *res, gpointer user_data)
1434
PkPackageSack *sack = PK_PACKAGE_SACK (object);
1435
GError *error = NULL;
1438
/* get the result */
1439
ret = pk_package_sack_merge_generic_finish (sack, res, &error);
1440
g_assert_no_error (error);
1443
_g_test_loop_quit ();
1447
* pk_test_package_sack_filter_cb:
1450
pk_test_package_sack_filter_cb (PkPackage *package, gpointer user_data)
1452
if (pk_package_get_info (package) == PK_INFO_ENUM_UNKNOWN)
1458
pk_test_package_sack_func (void)
1461
PkPackageSack *sack;
1465
PkInfoEnum info = PK_INFO_ENUM_UNKNOWN;
1468
sack = pk_package_sack_new ();
1469
g_assert (sack != NULL);
1471
/* get size of unused package sack */
1472
size = pk_package_sack_get_size (sack);
1473
g_assert (size == 0);
1475
/* remove package not present */
1476
ret = pk_package_sack_remove_package_by_id (sack, "powertop;1.8-1.fc8;i386;fedora");
1479
/* find package not present */
1480
package = pk_package_sack_find_by_id (sack, "powertop;1.8-1.fc8;i386;fedora");
1481
g_assert (package == NULL);
1484
ret = pk_package_sack_add_package_by_id (sack, "powertop;1.8-1.fc8;i386;fedora", NULL);
1487
/* get size of package sack */
1488
size = pk_package_sack_get_size (sack);
1489
g_assert (size == 1);
1491
/* merge resolve results */
1492
pk_package_sack_resolve_async (sack, NULL, NULL, NULL, (GAsyncReadyCallback) pk_test_package_sack_resolve_cb, NULL);
1493
_g_test_loop_run_with_timeout (5000);
1494
g_debug ("resolved in %f", g_test_timer_elapsed ());
1496
/* find package which is present */
1497
package = pk_package_sack_find_by_id (sack, "powertop;1.8-1.fc8;i386;fedora");
1498
g_assert (package != NULL);
1500
/* check new summary */
1501
g_object_get (package,
1505
g_assert_cmpstr (text, ==, "Power consumption monitor");
1507
/* check new info */
1508
g_assert_cmpint (info, ==, PK_INFO_ENUM_INSTALLED);
1511
g_object_unref (package);
1513
/* merge details results */
1514
pk_package_sack_get_details_async (sack, NULL, NULL, NULL, (GAsyncReadyCallback) pk_test_package_sack_details_cb, NULL);
1515
_g_test_loop_run_with_timeout (5000);
1516
g_debug ("got details in %f", g_test_timer_elapsed ());
1518
/* find package which is present */
1519
package = pk_package_sack_find_by_id (sack, "powertop;1.8-1.fc8;i386;fedora");
1520
g_assert (package != NULL);
1523
g_object_get (package,
1526
g_assert_cmpstr (text, ==, "http://live.gnome.org/powertop");
1527
g_object_unref (package);
1530
/* merge update detail results */
1531
pk_package_sack_get_update_detail_async (sack, NULL, NULL, NULL, (GAsyncReadyCallback) pk_test_package_sack_update_detail_cb, NULL);
1532
_g_test_loop_run_with_timeout (5000);
1533
g_debug ("got update detail in %f", g_test_timer_elapsed ());
1535
/* find package which is present */
1536
package = pk_package_sack_find_by_id (sack, "powertop;1.8-1.fc8;i386;fedora");
1537
g_assert (package != NULL);
1539
/* check new vendor url */
1540
g_object_get (package,
1541
"update-vendor-url", &text,
1543
g_assert_cmpstr (text, ==, "http://www.distro-update.org/page?moo;Bugfix release for powertop");
1546
g_object_unref (package);
1548
/* chck size in bytes */
1549
bytes = pk_package_sack_get_total_bytes (sack);
1550
g_assert_cmpint (bytes, ==, 103424);
1552
/* remove package */
1553
ret = pk_package_sack_remove_package_by_id (sack, "powertop;1.8-1.fc8;i386;fedora");
1556
/* get size of package sack */
1557
size = pk_package_sack_get_size (sack);
1558
g_assert_cmpint (size, ==, 0);
1560
/* remove already removed package */
1561
ret = pk_package_sack_remove_package_by_id (sack, "powertop;1.8-1.fc8;i386;fedora");
1564
/* remove by filter */
1565
pk_package_sack_add_package_by_id (sack, "powertop;1.8-1.fc8;i386;fedora", NULL);
1566
pk_package_sack_add_package_by_id (sack, "powertop-debuginfo;1.8-1.fc8;i386;fedora", NULL);
1567
ret = pk_package_sack_remove_by_filter (sack, pk_test_package_sack_filter_cb, NULL);
1570
/* check all removed */
1571
size = pk_package_sack_get_size (sack);
1572
g_assert_cmpint (size, ==, 0);
1574
g_object_unref (sack);
1578
pk_test_progress_func (void)
1580
PkProgress *progress;
1582
progress = pk_progress_new ();
1583
g_assert (progress != NULL);
1585
g_object_unref (progress);
1589
pk_test_progress_bar (void)
1591
PkProgressBar *progress_bar;
1593
progress_bar = pk_progress_bar_new ();
1594
g_assert (progress_bar != NULL);
1596
g_object_unref (progress_bar);
1600
pk_test_results_func (void)
1604
PkExitEnum exit_enum;
1605
GPtrArray *packages;
1612
results = pk_results_new ();
1613
g_assert (results != NULL);
1615
/* get exit code of unset results */
1616
exit_enum = pk_results_get_exit_code (results);
1617
g_assert_cmpint (exit_enum, ==, PK_EXIT_ENUM_UNKNOWN);
1619
/* get package list of unset results */
1620
packages = pk_results_get_package_array (results);
1621
g_assert_cmpint (packages->len, ==, 0);
1622
g_ptr_array_unref (packages);
1624
/* set valid exit code */
1625
ret = pk_results_set_exit_code (results, PK_EXIT_ENUM_CANCELLED);
1628
/* get exit code of set results */
1629
exit_enum = pk_results_get_exit_code (results);
1630
g_assert_cmpint (exit_enum, ==, PK_EXIT_ENUM_CANCELLED);
1633
item = pk_package_new ();
1635
"info", PK_INFO_ENUM_AVAILABLE,
1636
"package-id", "gnome-power-manager;0.1.2;i386;fedora",
1637
"summary", "Power manager for GNOME",
1639
ret = pk_results_add_package (results, item);
1640
g_object_unref (item);
1643
/* get package list of set results */
1644
packages = pk_results_get_package_array (results);
1645
g_assert_cmpint (packages->len, ==, 1);
1648
item = g_ptr_array_index (packages, 0);
1651
"package-id", &package_id,
1652
"summary", &summary,
1654
g_assert_cmpint (info, ==, PK_INFO_ENUM_AVAILABLE);
1655
g_assert_cmpstr ("gnome-power-manager;0.1.2;i386;fedora", ==, package_id);
1656
g_assert_cmpstr ("Power manager for GNOME", ==, summary);
1657
g_object_ref (item);
1658
g_ptr_array_unref (packages);
1659
g_free (package_id);
1665
"package-id", &package_id,
1666
"summary", &summary,
1668
g_assert_cmpint (info, ==, PK_INFO_ENUM_AVAILABLE);
1669
g_assert_cmpstr ("gnome-power-manager;0.1.2;i386;fedora", ==, package_id);
1670
g_assert_cmpstr ("Power manager for GNOME", ==, summary);
1671
g_object_unref (item);
1672
g_free (package_id);
1675
g_object_unref (results);
1679
pk_test_service_pack_create_cb (GObject *object, GAsyncResult *res, gpointer user_data)
1681
PkServicePack *pack = PK_SERVICE_PACK (object);
1682
GError *error = NULL;
1685
/* get the results */
1686
ret = pk_service_pack_generic_finish (pack, res, &error);
1687
g_assert_no_error (error);
1690
_g_test_loop_quit ();
1694
pk_test_service_pack_progress_cb (PkProgress *progress, PkProgressType type, gpointer user_data)
1696
PkStatusEnum status;
1697
if (type == PK_PROGRESS_TYPE_STATUS) {
1698
g_object_get (progress,
1701
g_debug ("now %s", pk_status_enum_to_string (status));
1706
pk_test_service_pack_func (void)
1708
PkServicePack *pack;
1709
gchar **package_ids;
1711
pack = pk_service_pack_new ();
1712
g_assert (pack != NULL);
1714
/* install package */
1715
package_ids = pk_package_ids_from_id ("glib2;2.14.0;i386;fedora");
1716
pk_service_pack_create_for_package_ids_async (pack, "dave.servicepack", package_ids, NULL, NULL,
1717
(PkProgressCallback) pk_test_service_pack_progress_cb, NULL,
1718
(GAsyncReadyCallback) pk_test_service_pack_create_cb, NULL);
1719
g_strfreev (package_ids);
1720
_g_test_loop_run_with_timeout (150000);
1721
g_debug ("installed in %f", g_test_timer_elapsed ());
1723
g_object_unref (pack);
1727
pk_test_task_install_packages_cb (GObject *object, GAsyncResult *res, gpointer user_data)
1729
PkTask *task = PK_TASK (object);
1730
GError *error = NULL;
1733
/* get the results */
1734
results = pk_task_generic_finish (task, res, &error);
1735
g_assert (results == NULL);
1736
g_assert_cmpstr (error->message, ==, "could not do untrusted question as no klass support");
1738
g_error_free (error);
1739
if (results != NULL)
1740
g_object_unref (results);
1741
_g_test_loop_quit ();
1745
pk_test_task_progress_cb (PkProgress *progress, PkProgressType type, gpointer user_data)
1747
PkStatusEnum status;
1748
if (type == PK_PROGRESS_TYPE_STATUS) {
1749
g_object_get (progress,
1752
g_debug ("now %s", pk_status_enum_to_string (status));
1757
pk_test_task_func (void)
1760
gchar **package_ids;
1762
task = pk_task_new ();
1763
g_assert (task != NULL);
1765
/* install package */
1766
package_ids = pk_package_ids_from_id ("glib2;2.14.0;i386;fedora");
1767
pk_task_install_packages_async (task, package_ids, NULL,
1768
(PkProgressCallback) pk_test_task_progress_cb, NULL,
1769
(GAsyncReadyCallback) pk_test_task_install_packages_cb, NULL);
1770
g_strfreev (package_ids);
1771
_g_test_loop_run_with_timeout (150000);
1772
g_debug ("installed in %f", g_test_timer_elapsed ());
1774
g_object_unref (task);
1778
pk_test_task_text_install_packages_cb (GObject *object, GAsyncResult *res, gpointer user_data)
1780
PkTaskText *task = PK_TASK_TEXT (object);
1781
GError *error = NULL;
1783
PkExitEnum exit_enum;
1784
GPtrArray *packages;
1786
/* get the results */
1787
results = pk_task_generic_finish (PK_TASK (task), res, &error);
1788
g_assert_no_error (error);
1789
g_assert (results != NULL);
1791
exit_enum = pk_results_get_exit_code (results);
1792
g_assert_cmpint (exit_enum, ==, PK_EXIT_ENUM_SUCCESS);
1794
packages = pk_results_get_package_array (results);
1795
g_assert (packages != NULL);
1796
g_assert_cmpint (packages->len, ==, 4);
1798
g_ptr_array_unref (packages);
1800
g_debug ("results exit enum = %s", pk_exit_enum_to_string (exit_enum));
1802
if (results != NULL)
1803
g_object_unref (results);
1804
_g_test_loop_quit ();
1808
pk_test_task_text_progress_cb (PkProgress *progress, PkProgressType type, gpointer user_data)
1810
PkStatusEnum status;
1811
if (type == PK_PROGRESS_TYPE_STATUS) {
1812
g_object_get (progress,
1815
g_debug ("now %s", pk_status_enum_to_string (status));
1820
pk_test_task_text_func (void)
1823
gchar **package_ids;
1825
task = pk_task_text_new ();
1826
g_assert (task != NULL);
1828
/* For testing, you will need to manually do:
1829
pkcon repo-set-data dummy use-gpg 1
1830
pkcon repo-set-data dummy use-eula 1
1831
pkcon repo-set-data dummy use-media 1
1834
/* install package */
1835
package_ids = pk_package_ids_from_id ("vips-doc;7.12.4-2.fc8;noarch;linva");
1836
pk_task_install_packages_async (PK_TASK (task), package_ids, NULL,
1837
(PkProgressCallback) pk_test_task_text_progress_cb, NULL,
1838
(GAsyncReadyCallback) pk_test_task_text_install_packages_cb, NULL);
1839
g_strfreev (package_ids);
1840
_g_test_loop_run_with_timeout (150000);
1841
g_debug ("installed in %f", g_test_timer_elapsed ());
1843
g_object_unref (task);
1847
pk_test_task_wrapper_install_packages_cb (GObject *object, GAsyncResult *res, gpointer user_data)
1849
PkTaskWrapper *task = PK_TASK_WRAPPER (object);
1850
GError *error = NULL;
1852
PkExitEnum exit_enum;
1853
GPtrArray *packages;
1855
/* get the results */
1856
results = pk_task_generic_finish (PK_TASK (task), res, &error);
1857
g_assert_no_error (error);
1858
g_assert (results != NULL);
1860
exit_enum = pk_results_get_exit_code (results);
1861
g_assert_cmpint (exit_enum, ==, PK_EXIT_ENUM_SUCCESS);
1863
packages = pk_results_get_package_array (results);
1864
g_assert (packages != NULL);
1865
g_assert_cmpint (packages->len, ==, 4);
1867
g_ptr_array_unref (packages);
1869
g_debug ("results exit enum = %s", pk_exit_enum_to_string (exit_enum));
1871
if (results != NULL)
1872
g_object_unref (results);
1873
_g_test_loop_quit ();
1877
pk_test_task_wrapper_progress_cb (PkProgress *progress, PkProgressType type, gpointer user_data)
1879
PkStatusEnum status;
1880
if (type == PK_PROGRESS_TYPE_STATUS) {
1881
g_object_get (progress,
1884
g_debug ("now %s", pk_status_enum_to_string (status));
1889
pk_test_task_wrapper_func (void)
1891
PkTaskWrapper *task;
1892
gchar **package_ids;
1894
task = pk_task_wrapper_new ();
1895
g_assert (task != NULL);
1897
/* install package */
1898
package_ids = pk_package_ids_from_id ("vips-doc;7.12.4-2.fc8;noarch;linva");
1899
pk_task_install_packages_async (PK_TASK (task), package_ids, NULL,
1900
(PkProgressCallback) pk_test_task_wrapper_progress_cb, NULL,
1901
(GAsyncReadyCallback) pk_test_task_wrapper_install_packages_cb, NULL);
1902
g_strfreev (package_ids);
1903
_g_test_loop_run_with_timeout (150000);
1904
g_debug ("installed in %f", g_test_timer_elapsed ());
1906
g_object_unref (task);
1911
//guint _refcount = 0;
1914
pk_test_transaction_list_resolve_cb (GObject *object, GAsyncResult *res, gpointer user_data)
1916
PkClient *client = PK_CLIENT (object);
1917
GError *error = NULL;
1918
PkResults *results = NULL;
1919
PkExitEnum exit_enum;
1921
/* get the results */
1922
results = pk_client_generic_finish (client, res, &error);
1923
g_assert_no_error (error);
1924
g_assert (results != NULL);
1926
exit_enum = pk_results_get_exit_code (results);
1927
g_assert_cmpint (exit_enum, ==, PK_EXIT_ENUM_SUCCESS);
1929
if (results != NULL)
1930
g_object_unref (results);
1931
if (--_refcount == 0)
1932
_g_test_loop_quit ();
1936
pk_test_transaction_list_added_cb (PkTransactionList *tlist, const gchar *tid, gpointer user_data)
1938
g_debug ("added %s", tid);
1943
pk_test_transaction_list_removed_cb (PkTransactionList *tlist, const gchar *tid, gpointer user_data)
1945
g_debug ("removed %s", tid);
1950
pk_transaction_list_delay_cb (gpointer user_data)
1952
_g_test_loop_quit ();
1957
pk_test_transaction_list_func (void)
1959
PkTransactionList *tlist;
1961
gchar **package_ids;
1963
/* get transaction_list object */
1964
tlist = pk_transaction_list_new ();
1965
g_assert (tlist != NULL);
1966
g_signal_connect (tlist, "added",
1967
G_CALLBACK (pk_test_transaction_list_added_cb), NULL);
1968
g_signal_connect (tlist, "removed",
1969
G_CALLBACK (pk_test_transaction_list_removed_cb), NULL);
1972
client = pk_client_new ();
1973
g_assert (client != NULL);
1975
/* resolve package */
1976
package_ids = pk_package_ids_from_string ("glib2;2.14.0;i386;fedora&powertop");
1978
pk_client_resolve_async (client, pk_bitfield_value (PK_FILTER_ENUM_INSTALLED), package_ids, NULL, NULL, NULL,
1979
(GAsyncReadyCallback) pk_test_transaction_list_resolve_cb, NULL);
1980
pk_client_resolve_async (client, pk_bitfield_value (PK_FILTER_ENUM_NOT_INSTALLED), package_ids, NULL, NULL, NULL,
1981
(GAsyncReadyCallback) pk_test_transaction_list_resolve_cb, NULL);
1982
g_strfreev (package_ids);
1983
_g_test_loop_run_with_timeout (15000);
1984
g_debug ("resolved in %f", g_test_timer_elapsed ());
1986
/* wait for remove */
1987
g_timeout_add (100, (GSourceFunc) pk_transaction_list_delay_cb, NULL);
1988
_g_test_loop_run_with_timeout (15000);
1989
g_debug ("resolved in %f", g_test_timer_elapsed ());
1991
/* correct number of added signals */
1992
g_assert_cmpint (_added, ==, 2);
1994
/* correct number of removed signals */
1995
g_assert_cmpint (_removed, ==, 2);
1997
g_object_unref (tlist);
1998
g_object_unref (client);
2002
pk_test_package_func (void)
2010
package = pk_package_new ();
2011
g_assert (package != NULL);
2013
/* get id of unset package */
2014
id = pk_package_get_id (package);
2015
g_assert_cmpstr (id, ==, NULL);
2017
/* get id of unset package */
2018
g_object_get (package, "package-id", &text, NULL);
2019
g_assert_cmpstr (text, ==, NULL);
2022
/* set invalid id */
2023
ret = pk_package_set_id (package, "gnome-power-manager", NULL);
2026
/* set invalid id (sections) */
2027
ret = pk_package_set_id (package, "gnome-power-manager;0.1.2;i386", NULL);
2030
/* set invalid name */
2031
ret = pk_package_set_id (package, ";0.1.2;i386;fedora", NULL);
2034
/* set valid name */
2035
ret = pk_package_set_id (package, "gnome-power-manager;0.1.2;i386;fedora", NULL);
2038
/* get id of set package */
2039
id = pk_package_get_id (package);
2040
g_assert_cmpstr (id, ==, "gnome-power-manager;0.1.2;i386;fedora");
2042
/* get name of set package */
2043
g_object_get (package, "package-id", &text, NULL);
2044
g_assert_cmpstr (text, ==, "gnome-power-manager;0.1.2;i386;fedora");
2047
g_object_unref (package);
2051
main (int argc, char **argv)
2055
g_test_init (&argc, &argv, NULL);
2057
pk_debug_set_verbose (TRUE);
2058
pk_debug_add_log_domain (G_LOG_DOMAIN);
2061
g_test_add_func ("/packagekit-glib2/common", pk_test_common_func);
2062
g_test_add_func ("/packagekit-glib2/enum", pk_test_enum_func);
2063
g_test_add_func ("/packagekit-glib2/desktop", pk_test_desktop_func);
2064
g_test_add_func ("/packagekit-glib2/bitfield", pk_test_bitfield_func);
2065
g_test_add_func ("/packagekit-glib2/package-id", pk_test_package_id_func);
2066
g_test_add_func ("/packagekit-glib2/package-ids", pk_test_package_ids_func);
2067
g_test_add_func ("/packagekit-glib2/progress", pk_test_progress_func);
2068
g_test_add_func ("/packagekit-glib2/results", pk_test_results_func);
2069
g_test_add_func ("/packagekit-glib2/package", pk_test_package_func);
2070
g_test_add_func ("/packagekit-glib2/control", pk_test_control_func);
2071
g_test_add_func ("/packagekit-glib2/transaction-list", pk_test_transaction_list_func);
2072
g_test_add_func ("/packagekit-glib2/client-helper", pk_test_client_helper_func);
2073
g_test_add_func ("/packagekit-glib2/client", pk_test_client_func);
2074
g_test_add_func ("/packagekit-glib2/catalog", pk_test_catalog_func);
2075
g_test_add_func ("/packagekit-glib2/package-sack", pk_test_package_sack_func);
2076
g_test_add_func ("/packagekit-glib2/task", pk_test_task_func);
2077
g_test_add_func ("/packagekit-glib2/task-wrapper", pk_test_task_wrapper_func);
2078
g_test_add_func ("/packagekit-glib2/task-text", pk_test_task_text_func);
2079
g_test_add_func ("/packagekit-glib2/console", pk_test_console_func);
2080
g_test_add_func ("/packagekit-glib2/progress-bar", pk_test_progress_bar);
2081
g_test_add_func ("/packagekit-glib2/service-pack", pk_test_service_pack_func);
2083
return g_test_run ();