summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorStefan Walter <stefw@src.gnome.org>2007-05-18 15:42:43 +0000
committerStefan Walter <stefw@src.gnome.org>2007-05-18 15:42:43 +0000
commit3c2311b7f5861b3e15891863d276c7dc37f8c227 (patch)
tree1f413d2496327bd5b1bb9464ce27fa00253e77ca /tests
parent7b7b5d534f5756285b676678739fd37b8bfbd336 (diff)
downloadgnome-keyring-3c2311b7f5861b3e15891863d276c7dc37f8c227.tar.gz
Consolidate our testing and use proper make files.
* configure.in: * Makefile.am: * library/Makefile.am: * library/test.c (moved to tests/): * library/list-keyrings.c (moved to tests/): * tests/Makefile.am (added): * tests/list-keyrings.c (moved from library/): * tests/test-keyrings.c (moved from library/): * tests/unit-test-keyrings.c: * tests/unit-tests-prep.sh: * tests/Makefile (removed): Consolidate our testing and use proper make files. svn path=/trunk/; revision=605
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile12
-rw-r--r--tests/Makefile.am49
-rw-r--r--tests/list-keyrings.c225
-rw-r--r--tests/test-keyrings.c502
-rw-r--r--tests/unit-test-keyrings.c8
-rwxr-xr-xtests/unit-tests-prep.sh108
6 files changed, 860 insertions, 44 deletions
diff --git a/tests/Makefile b/tests/Makefile
deleted file mode 100644
index 065f5c30..00000000
--- a/tests/Makefile
+++ /dev/null
@@ -1,12 +0,0 @@
-
-TESTS = \
- unit-test-keyrings.c
-
-all: unit-test
-
-unit-test-harness.c: $(TESTS)
- sh unit-tests-prep.sh $(TESTS) > $@
-
-unit-test: unit-test-harness.c $(TESTS)
- sh -c "gcc -o $@ -g -O0 -I cu-test `pkg-config --cflags --libs gnome-keyring-1 gtk+-2.0` \
- unit-test-harness.c $(TESTS) cu-test/CuTest.c"
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644
index 00000000..1b4f7760
--- /dev/null
+++ b/tests/Makefile.am
@@ -0,0 +1,49 @@
+
+EXTRA_DIST = cu-test
+
+INCLUDES= \
+ -I$(top_srcdir) \
+ -I$(top_builddir) \
+ $(GTK_CFLAGS) \
+ $(GLIB_CFLAGS)
+
+LIBS = \
+ $(top_builddir)/library/libgnome-keyring.la \
+ $(GTK_LIBS)
+
+noinst_PROGRAMS= \
+ list-keyrings \
+ test-keyring \
+ test-keyring-two \
+ unit-test-auto
+
+# \
+# unit-test-prompt
+
+# Simply list all the keyrings and whatever they have access to
+
+list_keyrings_SOURCES = \
+ list-keyrings.c
+
+# A generic testing program
+
+test_keyring_SOURCES = \
+ test-keyrings.c
+
+test_keyring_two_SOURCES = \
+ test-keyrings.c
+
+# Automatic tests
+
+UNIT_TESTS_AUTO = \
+ unit-test-keyrings.c
+
+unit-test-auto.c: $(UNIT_TESTS_AUTO) unit-tests-prep.sh
+ sh unit-tests-prep.sh -b unit-test-auto $(UNIT_TESTS_AUTO)
+
+unit_test_auto_SOURCES = \
+ unit-test-auto.c \
+ unit-test-auto.h \
+ cu-test/CuTest.c \
+ $(UNIT_TESTS_AUTO)
+
diff --git a/tests/list-keyrings.c b/tests/list-keyrings.c
new file mode 100644
index 00000000..adbdb5bf
--- /dev/null
+++ b/tests/list-keyrings.c
@@ -0,0 +1,225 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* list-keyrings.c - test app to list keyrings
+
+ Copyright (C) 2003 Red Hat, Inc
+
+ The Gnome Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The Gnome Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the Gnome Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Author: Alexander Larsson <alexl@redhat.com>
+*/
+#include "library/gnome-keyring.h"
+
+static GMainLoop *loop = NULL;
+
+
+static void
+string_callback (GnomeKeyringResult result,
+ const char *str,
+ gpointer data)
+{
+ char **out;
+
+ out = data;
+
+ if (result != GNOME_KEYRING_RESULT_OK) {
+ g_print ("string op failed: %d\n", result);
+ *out = NULL;
+ } else {
+ *out = g_strdup (str);
+ }
+ g_main_loop_quit (loop);
+}
+
+
+static void
+print_keyring_info (GnomeKeyringResult result,
+ GnomeKeyringInfo *info,
+ gpointer data)
+{
+ gboolean *locked;
+ locked = data;
+
+ *locked = TRUE;
+ if (result != GNOME_KEYRING_RESULT_OK) {
+ g_print ("error getting keyring info: %d\n", result);
+ } else {
+ g_print ("lock_on_idle: %d\n", gnome_keyring_info_get_lock_on_idle (info));
+ g_print ("lock timeout: %d\n", gnome_keyring_info_get_lock_timeout (info));
+ g_print ("mtime: %lu\n", (unsigned long)gnome_keyring_info_get_mtime (info));
+ g_print ("ctime: %lu\n", (unsigned long)gnome_keyring_info_get_ctime (info));
+ g_print ("locked: %d\n", gnome_keyring_info_get_is_locked (info));
+ *locked = gnome_keyring_info_get_is_locked (info);
+ }
+
+ g_main_loop_quit (loop);
+}
+
+static void
+print_item_info (GnomeKeyringResult result,
+ GnomeKeyringItemInfo *info,
+ gpointer data)
+{
+ char *secret;
+ char *name;
+ if (result != GNOME_KEYRING_RESULT_OK) {
+ g_print ("error getting item info: %d\n", result);
+ } else {
+ name = gnome_keyring_item_info_get_display_name (info);
+ secret = gnome_keyring_item_info_get_secret (info);
+ g_print (" type: %u\n", gnome_keyring_item_info_get_type (info));
+ g_print (" name: %s\n", name);
+ g_print (" secret: %s\n", secret);
+ g_print (" mtime: %lu\n", (unsigned long)gnome_keyring_item_info_get_mtime (info));
+ g_print (" ctime: %lu\n", (unsigned long)gnome_keyring_item_info_get_ctime (info));
+ gnome_keyring_free_password (secret);
+ g_free (name);
+ }
+
+ g_main_loop_quit (loop);
+}
+
+static void
+print_attributes (GnomeKeyringResult result,
+ GnomeKeyringAttributeList *attributes,
+ gpointer data)
+{
+ GnomeKeyringAttribute *array;
+ int i;
+
+ if (result != GNOME_KEYRING_RESULT_OK) {
+ g_print ("error getting item attributes: %d\n", result);
+ } else {
+ array = (GnomeKeyringAttribute *)attributes->data;
+ g_print (" Attributes:\n");
+ for (i = 0; i < attributes->len; i++) {
+ if (array[i].type == GNOME_KEYRING_ATTRIBUTE_TYPE_STRING) {
+ g_print (" %s = '%s'\n", array[i].name, array[i].value.string);
+ } else if (array[i].type == GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32) {
+ g_print (" %s = %u\n", array[i].name, array[i].value.integer);
+ } else {
+ g_print (" %s = ** unsupported attribute type **\n", array[i].name);
+ }
+ }
+ }
+
+ g_main_loop_quit (loop);
+}
+
+static void
+get_items_callback (GnomeKeyringResult result,
+ GList *list,
+ gpointer data)
+{
+ GList **out;
+
+ out = data;
+ *out = NULL;
+
+ if (result != GNOME_KEYRING_RESULT_OK) {
+ g_print ("error getting item list: %d\n", result);
+ } else {
+ *out = g_list_copy (list);
+ }
+
+ g_main_loop_quit (loop);
+}
+
+static void
+string_list_callback (GnomeKeyringResult result,
+ GList *list,
+ gpointer data)
+{
+ GList *l;
+ char *name;
+ GList **out;
+
+ out = data;
+
+ *out = NULL;
+
+ if (result != GNOME_KEYRING_RESULT_OK) {
+ g_print ("error getting keyring list: %d\n", result);
+ } else {
+ for (l = list; l != NULL; l = l->next) {
+ name = l->data;
+ *out = g_list_append (*out, g_strdup (name));
+ }
+ }
+
+ g_main_loop_quit (loop);
+}
+
+
+int
+main (int argc, char *argv[])
+{
+ GList *keyrings, *l, *items, *ll;
+ char *keyring;
+ gboolean locked;
+ guint32 item_id;
+
+ g_set_application_name("list-keyrings");
+ loop = g_main_loop_new (NULL, FALSE);
+
+ g_print ("Keyrings:\n");
+ gnome_keyring_list_keyring_names (string_list_callback, &keyrings, NULL);
+ g_main_loop_run (loop);
+ for (l = keyrings; l != NULL; l = l->next) {
+ keyring = l->data;
+ g_print ("\nkeyring: %s\n", keyring);
+
+ gnome_keyring_get_info (keyring, print_keyring_info, &locked, NULL);
+ g_main_loop_run (loop);
+
+ if (1 || !locked) {
+ gnome_keyring_list_item_ids (keyring, get_items_callback, &items, NULL);
+ g_main_loop_run (loop);
+
+ if (items != NULL) {
+ g_print ("Items: \n");
+ }
+ for (ll = items; ll != NULL; ll = ll->next) {
+ item_id = GPOINTER_TO_UINT(ll->data);
+
+ g_print ("\n");
+ g_print (" id: %u\n", item_id);
+ gnome_keyring_item_get_info (keyring,
+ item_id,
+ print_item_info, NULL, NULL);
+ g_main_loop_run (loop);
+ gnome_keyring_item_get_attributes (keyring,
+ item_id,
+ print_attributes, NULL, NULL);
+ g_main_loop_run (loop);
+ }
+ g_list_free (items);
+ }
+
+ g_free (keyring);
+ }
+ g_list_free (keyrings);
+
+ gnome_keyring_get_default_keyring (string_callback, &keyring, NULL);
+ g_main_loop_run (loop);
+ g_print ("\n");
+ if (keyring != NULL) {
+ g_print ("The default keyring for storage is '%s'\n", keyring);
+ } else {
+ g_print ("No default keyring defined\n");
+ }
+
+ return 0;
+}
diff --git a/tests/test-keyrings.c b/tests/test-keyrings.c
new file mode 100644
index 00000000..4f3366e4
--- /dev/null
+++ b/tests/test-keyrings.c
@@ -0,0 +1,502 @@
+#include <stdlib.h>
+
+#include "library/gnome-keyring.h"
+
+static GMainLoop *loop = NULL;
+
+static void
+print_attributes (GnomeKeyringAttributeList *attributes)
+{
+ GnomeKeyringAttribute *array;
+ int i;
+
+ array = (GnomeKeyringAttribute *)attributes->data;
+ g_print (" Attributes:\n");
+ for (i = 0; i < attributes->len; i++) {
+ if (array[i].type == GNOME_KEYRING_ATTRIBUTE_TYPE_STRING) {
+ g_print (" %s = '%s'\n", array[i].name, array[i].value.string);
+ } else if (array[i].type == GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32) {
+ g_print (" %s = %u\n", array[i].name, array[i].value.integer);
+ } else {
+ g_print (" %s = ** unsupported attribute type **\n", array[i].name);
+ }
+ }
+}
+
+static const gchar* result_msg[] = {
+ "GNOME_KEYRING_RESULT_OK",
+ "GNOME_KEYRING_RESULT_DENIED",
+ "GNOME_KEYRING_RESULT_NO_KEYRING_DAEMON",
+ "GNOME_KEYRING_RESULT_ALREADY_UNLOCKED",
+ "GNOME_KEYRING_RESULT_NO_SUCH_KEYRING",
+ "GNOME_KEYRING_RESULT_BAD_ARGUMENTS",
+ "GNOME_KEYRING_RESULT_IO_ERROR",
+ "GNOME_KEYRING_RESULT_CANCELLED",
+ "GNOME_KEYRING_RESULT_ALREADY_EXISTS"
+};
+
+static const gchar*
+get_msg_for_keyring_result (GnomeKeyringResult result)
+{
+ if (result<=GNOME_KEYRING_RESULT_ALREADY_EXISTS) {
+ return result_msg[result];
+ } else {
+ return "Unknown GnomeKeyringResult";
+ }
+}
+
+static void
+ok_cb (GnomeKeyringResult result,
+ gpointer data)
+{
+ g_print ("%s: %d (%s)\n", (char *)data, result, get_msg_for_keyring_result (result));
+ g_main_loop_quit (loop);
+}
+
+static void
+lock_all (void)
+{
+ gnome_keyring_lock_all (ok_cb, "lock all", NULL);
+ g_main_loop_run (loop);
+}
+
+static void
+lock (char *keyring)
+{
+ gnome_keyring_lock (keyring,
+ ok_cb, "lock", NULL);
+ g_main_loop_run (loop);
+}
+
+static void
+unlock (char *keyring, char *password)
+{
+ gnome_keyring_unlock (keyring, password,
+ ok_cb, "unlock", NULL);
+ g_main_loop_run (loop);
+}
+
+static void
+find_items_cb (GnomeKeyringResult result,
+ GList *found_items,
+ gpointer data)
+{
+ g_print ("found items: res: %d (%s) nr items: %d\n", result, get_msg_for_keyring_result (result), g_list_length (found_items));
+
+ if (found_items != NULL) {
+ GnomeKeyringFound *found = found_items->data;
+
+ g_print ("Found item: keyring=%s, id=%d, secret='%s'\n", found->keyring, found->item_id, found->secret);
+ print_attributes (found->attributes);
+ }
+
+ g_main_loop_quit (loop);
+}
+
+static void
+find_items (char *attr_val)
+{
+ gnome_keyring_find_itemsv (GNOME_KEYRING_ITEM_NOTE,
+ find_items_cb, NULL, NULL,
+ "testattribute", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING, attr_val,
+ NULL);
+ g_main_loop_run (loop);
+}
+
+static void
+creat_item_cb (GnomeKeyringResult result,
+ guint32 id,
+ gpointer data)
+{
+ g_print ("created item: res: %d (%s) id: %d\n", result, get_msg_for_keyring_result (result), id);
+ g_main_loop_quit (loop);
+}
+
+static void
+create_item (char *name, char *attr_name, gboolean update_if_exists)
+{
+ GnomeKeyringAttributeList *attributes;
+ GnomeKeyringAttribute attribute;
+
+ attribute.name = g_strdup ("testattribute");
+ attribute.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING;
+ attribute.value.string = g_strdup (attr_name);
+
+ attributes = gnome_keyring_attribute_list_new ();
+ g_array_append_val (attributes, attribute);
+
+ gnome_keyring_item_create (NULL,
+ GNOME_KEYRING_ITEM_NOTE,
+ name,
+ attributes,
+ "secret text",
+ update_if_exists,
+ creat_item_cb, NULL, NULL);
+ gnome_keyring_attribute_list_free (attributes);
+ g_main_loop_run (loop);
+}
+
+static void
+creat_application_item_cb (GnomeKeyringResult result,
+ guint32 id,
+ gpointer data)
+{
+ g_print ("created application item: res: %d (%s) id: %d\n", result, get_msg_for_keyring_result (result), id);
+ g_main_loop_quit (loop);
+}
+
+static void
+create_application_item (char *name, char *attr_name, gboolean update_if_exists)
+{
+ GnomeKeyringAttributeList *attributes;
+ GnomeKeyringAttribute attribute;
+
+ attribute.name = g_strdup ("testattribute");
+ attribute.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING;
+ attribute.value.string = g_strdup (attr_name);
+
+ attributes = gnome_keyring_attribute_list_new ();
+ g_array_append_val (attributes, attribute);
+
+ gnome_keyring_item_create (NULL,
+ GNOME_KEYRING_ITEM_NOTE | GNOME_KEYRING_ITEM_APPLICATION_SECRET,
+ name,
+ attributes,
+ "application secret text",
+ update_if_exists,
+ creat_application_item_cb, NULL, NULL);
+ gnome_keyring_attribute_list_free (attributes);
+ g_main_loop_run (loop);
+}
+
+static void
+show_item_cb (GnomeKeyringResult result,
+ GnomeKeyringItemInfo *info,
+ gpointer data)
+{
+ char *secret;
+ char *name;
+ if (result != GNOME_KEYRING_RESULT_OK) {
+ g_print ("error getting item info: %d (%s)\n", result, get_msg_for_keyring_result (result));
+ } else {
+ name = gnome_keyring_item_info_get_display_name (info);
+ secret = gnome_keyring_item_info_get_secret (info);
+ g_print (" type: %u\n", gnome_keyring_item_info_get_type (info));
+ g_print (" name: %s\n", name);
+ g_print (" secret: %s\n", secret);
+ g_print (" mtime: %lu\n", (unsigned long)gnome_keyring_item_info_get_mtime (info));
+ g_print (" ctime: %lu\n", (unsigned long)gnome_keyring_item_info_get_ctime (info));
+ gnome_keyring_free_password (secret);
+ g_free (name);
+ }
+
+ g_main_loop_quit (loop);
+}
+
+static void
+print_attributes_cb (GnomeKeyringResult result,
+ GnomeKeyringAttributeList *attributes,
+ gpointer data)
+{
+ if (result != GNOME_KEYRING_RESULT_OK) {
+ g_print ("error getting item attributes: %d (%s)\n", result, get_msg_for_keyring_result (result));
+ } else {
+ print_attributes (attributes);
+ }
+
+ g_main_loop_quit (loop);
+}
+
+static void
+show_item (char *keyring, guint32 item_id, guint32 parts)
+{
+ gnome_keyring_item_get_info_full (keyring, item_id, parts,
+ show_item_cb, NULL, NULL);
+ g_main_loop_run (loop);
+ gnome_keyring_item_get_attributes (keyring, item_id,
+ print_attributes_cb, NULL, NULL);
+ g_main_loop_run (loop);
+}
+
+static void
+delete_item (char *keyring, guint32 item_id)
+{
+ gnome_keyring_item_delete (keyring, item_id,
+ ok_cb, "delete item", NULL);
+ g_main_loop_run (loop);
+}
+
+static void
+set_item_secret (char *keyring, guint32 item_id, char *secret)
+{
+ GnomeKeyringItemInfo *info;
+
+ info = gnome_keyring_item_info_new ();
+ gnome_keyring_item_info_set_secret (info, secret);
+ gnome_keyring_item_set_info (keyring, item_id, info,
+ ok_cb, "set item", NULL);
+ gnome_keyring_item_info_free (info);
+ g_main_loop_run (loop);
+}
+
+static void
+set_item_attribute (char *keyring, guint32 item_id, char *value)
+{
+ GnomeKeyringAttributeList *attributes;
+ GnomeKeyringAttribute attribute;
+
+ attribute.name = g_strdup ("testattribute");
+ attribute.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING;
+ attribute.value.string = g_strdup (value);
+
+ attributes = gnome_keyring_attribute_list_new ();
+ g_array_append_val (attributes, attribute);
+
+ gnome_keyring_item_set_attributes (keyring, item_id, attributes,
+ ok_cb, "set attributes", NULL);
+ gnome_keyring_attribute_list_free (attributes);
+ g_main_loop_run (loop);
+}
+
+static void
+create_keyring (char *name, char *password)
+{
+ gnome_keyring_create (name, password,
+ ok_cb, "create keyring", NULL);
+ g_main_loop_run (loop);
+}
+
+static void
+set_default (char *name)
+{
+ gnome_keyring_set_default_keyring (name,
+ ok_cb, "set default", NULL);
+ g_main_loop_run (loop);
+}
+
+static void
+set_network_cb (GnomeKeyringResult result,
+ guint32 id,
+ gpointer data)
+{
+ g_print ("set network password: res: %d id: %d\n", result, id);
+ g_main_loop_quit (loop);
+}
+
+
+static void
+set_network (char *server, char *password)
+{
+ gnome_keyring_set_network_password (NULL /* default keyring */,
+ NULL,
+ NULL,
+ server,
+ NULL,
+ "smb",
+ NULL,
+ 0,
+ password,
+ set_network_cb, NULL, NULL);
+ g_main_loop_run (loop);
+}
+
+static void
+set_network_sync (char *server, char *password)
+{
+ guint32 id;
+ GnomeKeyringResult res;
+ res = gnome_keyring_set_network_password_sync (NULL /* default keyring */,
+ NULL,
+ NULL,
+ server,
+ NULL,
+ "smb",
+ NULL,
+ 0,
+ password,
+ &id);
+ g_print ("set network password: res: %d id: %d\n", res, id);
+}
+
+static void
+find_network (char *server)
+{
+ GnomeKeyringResult res;
+ GList *list, *l;
+
+ list = NULL;
+ res = gnome_keyring_find_network_password_sync (NULL, NULL,
+ server, NULL,
+ "smb",
+ NULL,
+ 0,
+ &list);
+ g_print ("find network password, res: %d, len: %d\n", res, g_list_length (list));
+ for (l = list; l != NULL; l = l->next) {
+ GnomeKeyringNetworkPasswordData *data;
+ data = l->data;
+
+ g_print ("%s:%d - proto: %s, server: %s, object: %s, authtype: %s, port: %d, user: %s, domain: %s, password: %s\n",
+ data->keyring,
+ data->item_id,
+ data->protocol,
+ data->server,
+ data->object,
+ data->authtype,
+ data->port,
+ data->user,
+ data->domain,
+ data->password);
+ }
+}
+
+static void
+list_items_cb (GnomeKeyringResult result, GList *list, gpointer data)
+{
+ g_print ("list items: res: %d (%s)\n", result, get_msg_for_keyring_result (result));
+ for ( ; list; list = list->next)
+ g_print (" id: %d\n", GPOINTER_TO_UINT (list->data));
+ g_main_loop_quit (loop);
+}
+
+static void
+list_items (const char *keyring)
+{
+ gnome_keyring_list_item_ids (keyring, list_items_cb, NULL, NULL);
+ g_main_loop_run (loop);
+}
+
+int
+main (int argc, char *argv[])
+{
+ char arg;
+
+ g_set_application_name("test-keyring");
+ loop = g_main_loop_new (NULL, FALSE);
+
+ arg = 0;
+ if (argc >= 2) {
+ arg = argv[1][0];
+ }
+
+ if (arg == 'L') {
+ lock_all ();
+ } else if (arg == 'l') {
+ if (argc >= 3) {
+ lock (argv[2]);
+ } else {
+ lock (NULL);
+ }
+ } else if (arg == 'u') {
+ if (argc >= 4) {
+ unlock (argv[2], argv[3]);
+ } else {
+ g_print ("unlock requires keyring and password\n");
+ }
+ } else if (arg == 'c') {
+ if (argc >= 4) {
+ create_item (argv[2], argv[3], FALSE);
+ } else {
+ g_print ("create item requires item name and attr value\n");
+ }
+ } else if (arg == 'C') {
+ if (argc >= 4) {
+ create_item (argv[2], argv[3], TRUE);
+ } else {
+ g_print ("create item requires item name and attr value\n");
+ }
+
+ } else if (arg == 'A') {
+ if (argc >= 4) {
+ create_application_item (argv[2], argv[3], FALSE);
+ } else {
+ g_print ("create application item requires item name and attr value\n");
+ }
+
+ /* Show complete item information */
+ } else if (arg == 'i') {
+ if (argc >= 4) {
+ show_item (argv[2], atoi(argv[3]), GNOME_KEYRING_ITEM_INFO_SECRET);
+ } else {
+ g_print ("must give keyring & item id to show\n");
+ }
+
+ /* Show basic item information */
+ } else if (arg == 'b') {
+ if (argc >= 4) {
+ show_item (argv[2], atoi(argv[3]), GNOME_KEYRING_ITEM_INFO_BASICS);
+ } else {
+ g_print ("must give keyring & item id to show\n");
+ }
+ } else if (arg == 'd') {
+ if (argc >= 4) {
+ delete_item (argv[2] ,atoi (argv[3]));
+ } else {
+ g_print ("must give keyring & item id to delete\n");
+ }
+ } else if (arg == 's') {
+ if (argc >= 5) {
+ set_item_secret (argv[2] ,atoi (argv[3]), argv[4]);
+ } else {
+ g_print ("must give keyring & item id & secret\n");
+ }
+ } else if (arg == 'a') {
+ if (argc >= 5) {
+ set_item_attribute (argv[2] ,atoi (argv[3]), argv[4]);
+ } else {
+ g_print ("must give keyring & item id & attribute value\n");
+ }
+ } else if (arg == 'f') {
+ if (argc >= 3) {
+ find_items (argv[2]);
+ } else {
+ g_print ("must give testattribute value\n");
+ }
+ } else if (arg == 'k') {
+ if (argc >= 4) {
+ create_keyring (argv[2], argv[3]);
+ } else if (argc >= 3) {
+ create_keyring (argv[2], NULL);
+ } else {
+ g_print ("create keyring requires keyring name\n");
+ }
+ } else if (arg == 'D') {
+ if (argc >= 3) {
+ set_default (argv[2]);
+ } else {
+ set_default (NULL);
+ }
+ } else if (arg == 'n') {
+ if (argc >= 4) {
+ set_network (argv[2], argv[3]);
+ } else {
+ g_print ("need server & password\n");
+ }
+ } else if (arg == 'N') {
+ if (argc >= 4) {
+ set_network_sync (argv[2], argv[3]);
+ } else {
+ g_print ("need server & password\n");
+ }
+ } else if (arg == 'p') {
+ if (argc >= 3) {
+ find_network (argv[2]);
+ } else {
+ g_print ("need server\n");
+ }
+ } else if (arg == 't') {
+ g_print ("gnome keyring is: %s\n",
+ gnome_keyring_is_available ()?"available":"not available");
+ } else if (arg == 'I') {
+ if (argc >= 3) {
+ list_items(argv[2]);
+ } else {
+ g_print ("need keyring\n");
+ }
+ } else {
+ g_print ("unsupported test\n");
+ }
+
+
+ return 0;
+}
diff --git a/tests/unit-test-keyrings.c b/tests/unit-test-keyrings.c
index f88c8076..85fa1022 100644
--- a/tests/unit-test-keyrings.c
+++ b/tests/unit-test-keyrings.c
@@ -23,10 +23,10 @@
#include <stdlib.h>
#include <stdio.h>
+#include <string.h>
-#include <glib.h>
-#include <gnome-keyring.h>
-#include "CuTest.h"
+#include "unit-test-auto.h"
+#include "library/gnome-keyring.h"
static GList* keyrings = NULL;
#define PASSWORD "my-keyring-password"
@@ -45,7 +45,7 @@ void unit_test_list_keyrings (CuTest* cu)
printf("\t\tkeyrings:\n");
for (l = keyrings; l; l = g_list_next (l))
- printf("\t\t %s\n", l->data);
+ printf("\t\t %s\n", (gchar*)l->data);
}
void unit_test_create_keyring (CuTest* cu)
diff --git a/tests/unit-tests-prep.sh b/tests/unit-tests-prep.sh
index 9f98c51e..a27e0195 100755
--- a/tests/unit-tests-prep.sh
+++ b/tests/unit-tests-prep.sh
@@ -1,53 +1,105 @@
-#!/usr/local/bin/bash
+#!/bin/sh -e
-# Auto generate single AllTests file for CuTest.
-# Searches through all *.c files in the current directory.
-# Prints to stdout.
-# Author: Asim Jalis
-# Date: 01/08/2003
+set -e
-if test $# -eq 0 ; then FILES=*.c ; else FILES=$* ; fi
+# --------------------------------------------------------------------
-echo '
+usage()
+{
+ echo "usage: unit-test-prep.sh -b base-name files.c ..." >&2
+ exit 2
+}
+header_top()
+{
+cat << END
/* This is auto-generated code. Edit at your own peril. */
-#include "CuTest.h"
+#include "cu-test/CuTest.h"
#include <stdio.h>
+#include <gtk/gtk.h>
-'
-
-cat $FILES | grep '^void unit_test_' |
- sed -e 's/(.*$//' \
- -e 's/$/(CuTest*);/' \
- -e 's/^/extern /'
+END
+}
-echo \
-'
+header_bottom()
+{
+cat << END
+END
+}
-void RunAllTests(void)
+source_top()
+{
+cat << END
+static void RunAllTests(void)
{
CuString *output = CuStringNew();
CuSuite* suite = CuSuiteNew();
-'
-cat $FILES | grep '^void unit_test_' |
- sed -e 's/^void //' \
- -e 's/(.*$//' \
- -e 's/^/ SUITE_ADD_TEST(suite, /' \
- -e 's/$/);/'
+END
+}
-echo \
-'
+source_bottom()
+{
+cat << END
CuSuiteRun(suite);
CuSuiteSummary(suite, output);
CuSuiteDetails(suite, output);
printf("%s\\n", output->buffer);
}
-int main(int argc, char* argv)
+int main(int argc, char* argv[])
{
gtk_init(&argc, &argv);
RunAllTests();
+ return 0;
+}
+END
}
-'
+
+# --------------------------------------------------------------------
+
+BASE=unit-test
+
+while [ $# -gt 0 ]; do
+ case "$1" in
+ -b)
+ BASE="$2"
+ shift
+ ;;
+ --)
+ shift
+ break
+ ;;
+ -*)
+ usage
+ ;;
+ *)
+ break
+ ;;
+ esac
+ shift
+done
+
+# Must specify some files
+if [ $# -eq 0 ]; then
+ usage
+fi
+
+FILES=$*
+
+(
+ header_top
+ cat $FILES | grep '^void unit_test_' | sed -e 's/$/;/'
+ header_bottom
+) > $BASE.h
+
+(
+ echo "#include \"$BASE.h\""
+ source_top
+ cat $FILES | grep '^void unit_test_' | \
+ sed -e 's/^void //' -e 's/(.*$//' \
+ -e 's/^/ SUITE_ADD_TEST(suite, /' -e 's/$/);/'
+ source_bottom
+) > $BASE.c
+