[packagekit] packagekit: Branch 'master' - 7 commits
Richard Hughes
hughsient at kemper.freedesktop.org
Thu Aug 30 17:38:09 PDT 2007
Makefile.am | 1
client/pk-console.c | 13 +-
configure.ac | 1
libpackagekit/.gitignore | 1
libpackagekit/Makefile.am | 33 +++++
libpackagekit/pk-package-id.c | 260 ++++++++++++++++++++++++++++++++++++++++++
libpackagekit/pk-package-id.h | 48 +++++++
libpackagekit/pk-self-test.c | 44 +++++++
libpackagekit/pk-task-utils.c | 163 +++++++++-----------------
libpackagekit/pk-task-utils.h | 18 --
libselftest/.gitignore | 8 +
libselftest/Makefile.am | 20 +++
libselftest/libselftest.c | 142 ++++++++++++++++++++++
libselftest/libselftest.h | 30 ++--
src/Makefile.am | 9 +
src/pk-engine.c | 9 -
src/pk-self-test.c | 181 +----------------------------
src/pk-spawn.c | 26 ++--
src/pk-task-common.c | 3
tools/backend-change.sh | 2
20 files changed, 678 insertions(+), 334 deletions(-)
New commits:
diff-tree 2078b94b5269abcbd8f48b31670731fc425ac7ff (from 0e2e5a91ff9f5ca3b8307c37334f02ec74154de7)
Author: Richard Hughes <richard at hughsie.com>
Date: Fri Aug 31 01:33:49 2007 +0100
split out the package id stuff to a seporate file, also add some tests
diff --git a/client/pk-console.c b/client/pk-console.c
index b7ae8a3..88d1084 100644
--- a/client/pk-console.c
+++ b/client/pk-console.c
@@ -30,6 +30,7 @@
#include <pk-debug.h>
#include <pk-task-client.h>
+#include <pk-package-id.h>
/**
* pk_console_package_cb:
@@ -70,8 +71,8 @@ pk_console_package_cb (PkTaskClient *tcl
installed = "yes ";
}
- spacing = pk_task_package_id_new ();
- ident = pk_task_package_id_from_string (package_id);
+ spacing = pk_package_id_new ();
+ ident = pk_package_id_new_from_string (package_id);
/* these numbers are guesses */
extra = 0;
@@ -89,8 +90,8 @@ pk_console_package_cb (PkTaskClient *tcl
summary);
/* free all the data */
- pk_task_package_id_free (ident);
- pk_task_package_id_free (spacing);
+ pk_package_id_free (ident);
+ pk_package_id_free (spacing);
}
/**
diff --git a/libpackagekit/Makefile.am b/libpackagekit/Makefile.am
index a9dd28e..b4e9a62 100644
--- a/libpackagekit/Makefile.am
+++ b/libpackagekit/Makefile.am
@@ -27,6 +27,7 @@ libpackagekit_includedir = $(includedir)
libpackagekit_include_HEADERS = \
pk-debug.h \
pk-connection.h \
+ pk-package-id.h \
pk-task-utils.h \
pk-task-common.h \
pk-task-monitor.h \
@@ -43,6 +44,8 @@ libpackagekit_la_SOURCES = \
pk-marshal.h \
pk-connection.c \
pk-connection.h \
+ pk-package-id.h \
+ pk-package-id.c \
pk-task-utils.h \
pk-task-utils.c \
pk-task-common.c \
@@ -77,6 +80,8 @@ pk_self_test_SOURCES = \
pk-debug.h \
pk-task-utils.h \
pk-task-utils.c \
+ pk-package-id.h \
+ pk-package-id.c \
pk-self-test.c \
$(NULL)
diff --git a/libpackagekit/pk-package-id.c b/libpackagekit/pk-package-id.c
new file mode 100644
index 0000000..8356d68
--- /dev/null
+++ b/libpackagekit/pk-package-id.c
@@ -0,0 +1,260 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007 Richard Hughes <richard at hughsie.com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#include <glib/gi18n.h>
+
+#include "pk-debug.h"
+#include "pk-package-id.h"
+
+/**
+ * pk_package_id_new:
+ **/
+PkPackageId *
+pk_package_id_new (void)
+{
+ PkPackageId *ident;
+ ident = g_new0 (PkPackageId, 1);
+ ident->name = NULL;
+ ident->version = NULL;
+ ident->arch = NULL;
+ ident->data = NULL;
+ return ident;
+}
+
+/**
+ * pk_package_id_split:
+ *
+ * Returns the split, ONLY if package name is okay
+ * You need to use g_strfreev on the returned value
+ **/
+static gchar **
+pk_package_id_split (const gchar *package_id)
+{
+ gchar **sections = NULL;
+
+ if (package_id == NULL) {
+ pk_warning ("Package ident is null!");
+ goto out;
+ }
+
+ /* split by delimeter ';' */
+ sections = g_strsplit (package_id, ";", 0);
+ if (g_strv_length (sections) != 4) {
+ pk_warning ("Package ident '%s' is invalid (sections=%d)", package_id, g_strv_length (sections));
+ goto out;
+ }
+
+ /* name has to be valid */
+ sections = g_strsplit (package_id, ";", 0);
+ if (strlen (sections[0]) == 0) {
+ pk_warning ("Package ident package is empty");
+ goto out;
+ }
+
+ /* all okay, phew.. */
+ return sections;
+
+out:
+ /* free sections and return NULL */
+ if (sections != NULL) {
+ g_strfreev (sections);
+ }
+ return NULL;
+}
+
+/**
+ * pk_package_id_check:
+ **/
+gboolean
+pk_package_id_check (const gchar *package_id)
+{
+ gchar **sections;
+ sections = pk_package_id_split (package_id);
+ if (sections != NULL) {
+ g_strfreev (sections);
+ return TRUE;
+ }
+ return FALSE;
+}
+
+/**
+ * pk_package_id_new_from_string:
+ **/
+PkPackageId *
+pk_package_id_new_from_string (const gchar *package_id)
+{
+ gchar **sections;
+ PkPackageId *ident = NULL;
+
+ sections = pk_package_id_split (package_id);
+ if (sections == NULL) {
+ return NULL;
+ }
+
+ /* create new object */
+ ident = pk_package_id_new ();
+ ident->name = g_strdup (sections[0]);
+ ident->version = g_strdup (sections[1]);
+ ident->arch = g_strdup (sections[2]);
+ ident->data = g_strdup (sections[3]);
+ g_strfreev (sections);
+ return ident;
+}
+
+/**
+ * pk_package_id_to_string:
+ **/
+gchar *
+pk_package_id_to_string (PkPackageId *ident)
+{
+ return g_strdup_printf ("%s;%s;%s;%s",
+ ident->name, ident->version,
+ ident->arch, ident->data);
+}
+
+/**
+ * pk_package_id_build:
+ **/
+gchar *
+pk_package_id_build (const gchar *name, const gchar *version,
+ const gchar *arch, const gchar *data)
+{
+ return g_strdup_printf ("%s;%s;%s;%s", name, version, arch, data);
+}
+
+/**
+ * pk_package_id_free:
+ **/
+gboolean
+pk_package_id_free (PkPackageId *ident)
+{
+ if (ident == NULL) {
+ return FALSE;
+ }
+ g_free (ident->name);
+ g_free (ident->arch);
+ g_free (ident->version);
+ g_free (ident->data);
+ g_free (ident);
+ return TRUE;
+}
+
+/***************************************************************************
+ *** MAKE CHECK TESTS ***
+ ***************************************************************************/
+#ifdef PK_BUILD_TESTS
+#include <libselftest.h>
+
+void
+libst_package_id (LibSelfTest *test)
+{
+ gboolean ret;
+ gchar *text;
+ const gchar *temp;
+ PkPackageId *ident;
+
+ if (libst_start (test, "PkPackageId", CLASS_AUTO) == FALSE) {
+ return;
+ }
+
+ /************************************************************
+ **************** IDENT ******************
+ ************************************************************/
+ libst_title (test, "get an ident object");
+ ident = pk_package_id_new ();
+ if (ident != NULL) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, NULL);
+ }
+
+ /************************************************************/
+ libst_title (test, "test ident freeing early");
+ ret = pk_package_id_free (ident);
+ if (ret == TRUE) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, NULL);
+ }
+
+ /************************************************************/
+ libst_title (test, "parse incorrect package_id from string (null)");
+ temp = NULL;
+ ident = pk_package_id_new_from_string (temp);
+ if (ident == NULL) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, "passed an invalid string '%s'", temp);
+ }
+
+ /************************************************************/
+ libst_title (test, "parse incorrect package_id from string (empty)");
+ temp = "";
+ ident = pk_package_id_new_from_string (temp);
+ if (ident == NULL) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, "passed an invalid string '%s'", temp);
+ }
+
+ /************************************************************/
+ libst_title (test, "parse incorrect package_id from string (not enough)");
+ temp = "moo;0.0.1;i386";
+ ident = pk_package_id_new_from_string (temp);
+ if (ident == NULL) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, "passed an invalid string '%s'", temp);
+ }
+
+ /************************************************************/
+ libst_title (test, "parse package_id from string");
+ ident = pk_package_id_new_from_string ("moo;0.0.1;i386;fedora");
+ if (strcmp (ident->name, "moo") == 0 &&
+ strcmp (ident->arch, "i386") == 0 &&
+ strcmp (ident->data, "fedora") == 0 &&
+ strcmp (ident->version, "0.0.1") == 0) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, NULL);
+ }
+
+ /************************************************************/
+ libst_title (test, "test ident building with valid data");
+ text = pk_package_id_to_string (ident);
+ if (strcmp (text, "moo;0.0.1;i386;fedora") == 0) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, "package_id is '%s'", text);
+ }
+ g_free (text);
+ pk_package_id_free (ident);
+
+ libst_end (test);
+}
+#endif
+
diff --git a/libpackagekit/pk-package-id.h b/libpackagekit/pk-package-id.h
new file mode 100644
index 0000000..28eeec1
--- /dev/null
+++ b/libpackagekit/pk-package-id.h
@@ -0,0 +1,48 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007 Richard Hughes <richard at hughsie.com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __PK_PACKAGE_ID_H
+#define __PK_PACKAGE_ID_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+typedef struct {
+ gchar *name;
+ gchar *version;
+ gchar *arch;
+ gchar *data;
+} PkPackageId;
+
+PkPackageId *pk_package_id_new (void);
+PkPackageId *pk_package_id_new_from_string (const gchar *package_id);
+gchar *pk_package_id_build (const gchar *name,
+ const gchar *version,
+ const gchar *arch,
+ const gchar *data);
+gchar *pk_package_id_to_string (PkPackageId *ident);
+gboolean pk_package_id_free (PkPackageId *ident);
+gboolean pk_package_id_check (const gchar *package_id);
+
+G_END_DECLS
+
+#endif /* __PK_PACKAGE_ID_H */
diff --git a/libpackagekit/pk-self-test.c b/libpackagekit/pk-self-test.c
index 7658d08..87d4675 100644
--- a/libpackagekit/pk-self-test.c
+++ b/libpackagekit/pk-self-test.c
@@ -25,6 +25,7 @@
/* prototypes */
void libst_task_utils (LibSelfTest *test);
+void libst_package_id (LibSelfTest *test);
int
main (int argc, char **argv)
@@ -36,6 +37,7 @@ main (int argc, char **argv)
/* tests go here */
libst_task_utils (&test);
+ libst_package_id (&test);
return (libst_finish (&test));
}
diff --git a/libpackagekit/pk-task-utils.c b/libpackagekit/pk-task-utils.c
index b9f9e98..51eab8b 100644
--- a/libpackagekit/pk-task-utils.c
+++ b/libpackagekit/pk-task-utils.c
@@ -266,33 +266,6 @@ pk_task_action_to_text (PkTaskAction act
}
/**
- * pk_task_package_id_check:
- **/
-gboolean
-pk_task_package_id_check (const gchar *package_id)
-{
- guint i;
- guint length;
- guint sections;
-
- if (package_id == NULL) {
- return FALSE;
- }
-
- length = strlen (package_id);
- sections = 1;
- for (i=0; i<length; i++) {
- if (package_id[i] == ';') {
- sections += 1;
- }
- }
- if (sections != 4) {
- return FALSE;
- }
- return TRUE;
-}
-
-/**
* pk_task_check_filter_part:
**/
gboolean
@@ -353,89 +326,6 @@ out:
}
/**
- * pk_task_package_id_build:
- **/
-gchar *
-pk_task_package_id_build (const gchar *name, const gchar *version,
- const gchar *arch, const gchar *data)
-{
- return g_strdup_printf ("%s;%s;%s;%s", name, version, arch, data);
-}
-
-/**
- * pk_task_package_id_new:
- **/
-PkPackageId *
-pk_task_package_id_new (void)
-{
- PkPackageId *ident;
- ident = g_new0 (PkPackageId, 1);
- ident->name = NULL;
- ident->version = NULL;
- ident->arch = NULL;
- ident->data = NULL;
- return ident;
-}
-
-/**
- * pk_task_package_id_from_string:
- **/
-PkPackageId *
-pk_task_package_id_from_string (const gchar *package_id)
-{
- gchar **sections = NULL;
- PkPackageId *ident = NULL;
-
- if (package_id == NULL) {
- pk_warning ("Package ident is null!");
- goto out;
- }
-
- /* split by delimeter ';' */
- sections = g_strsplit (package_id, ";", 0);
- if (g_strv_length (sections) != 4) {
- pk_warning ("Package ident '%s' is invalid (sections=%d)", package_id, g_strv_length (sections));
- goto out;
- }
-
- /* create new object */
- ident = pk_task_package_id_new ();
- ident->name = g_strdup (sections[0]);
- ident->version = g_strdup (sections[1]);
- ident->arch = g_strdup (sections[2]);
- ident->data = g_strdup (sections[3]);
-out:
- if (sections != NULL) {
- g_strfreev (sections);
- }
- return ident;
-}
-
-/**
- * pk_task_package_id_to_string:
- **/
-gchar *
-pk_task_package_id_to_string (PkPackageId *ident)
-{
- return g_strdup_printf ("%s;%s;%s;%s", ident->name, ident->version,
- ident->arch, ident->data);
-}
-
-/**
- * pk_task_package_id_free:
- **/
-gboolean
-pk_task_package_id_free (PkPackageId *ident)
-{
- g_free (ident->name);
- g_free (ident->arch);
- g_free (ident->version);
- g_free (ident->data);
- g_free (ident);
- return TRUE;
-}
-
-/**
* pk_task_action_build:
**/
gchar *
@@ -499,8 +389,6 @@ libst_task_utils (LibSelfTest *test)
{
gboolean ret;
gchar *text;
- const gchar *temp;
- PkPackageId *ident;
if (libst_start (test, "PkTaskUtils", CLASS_AUTO) == FALSE) {
return;
@@ -546,80 +434,6 @@ libst_task_utils (LibSelfTest *test)
}
g_free (text);
- /************************************************************
- **************** IDENT ******************
- ************************************************************/
- libst_title (test, "get an ident object");
- ident = pk_task_package_id_new ();
- if (ident != NULL) {
- libst_success (test, NULL);
- } else {
- libst_failed (test, NULL);
- }
-
- /************************************************************/
- libst_title (test, "test ident freeing early");
- ret = pk_task_package_id_free (ident);
- if (ret == TRUE) {
- libst_success (test, NULL);
- } else {
- libst_failed (test, NULL);
- }
-
- /************************************************************/
- libst_title (test, "parse incorrect package_id from string (null)");
- temp = NULL;
- ident = pk_task_package_id_from_string (temp);
- if (ident == NULL) {
- libst_success (test, NULL);
- } else {
- libst_failed (test, "passed an invalid string '%s'", temp);
- }
-
- /************************************************************/
- libst_title (test, "parse incorrect package_id from string (empty)");
- temp = "";
- ident = pk_task_package_id_from_string (temp);
- if (ident == NULL) {
- libst_success (test, NULL);
- } else {
- libst_failed (test, "passed an invalid string '%s'", temp);
- }
-
- /************************************************************/
- libst_title (test, "parse incorrect package_id from string (not enough)");
- temp = "moo;0.0.1;i386";
- ident = pk_task_package_id_from_string (temp);
- if (ident == NULL) {
- libst_success (test, NULL);
- } else {
- libst_failed (test, "passed an invalid string '%s'", temp);
- }
-
- /************************************************************/
- libst_title (test, "parse package_id from string");
- ident = pk_task_package_id_from_string ("moo;0.0.1;i386;fedora");
- if (strcmp (ident->name, "moo") == 0 &&
- strcmp (ident->arch, "i386") == 0 &&
- strcmp (ident->data, "fedora") == 0 &&
- strcmp (ident->version, "0.0.1") == 0) {
- libst_success (test, NULL);
- } else {
- libst_failed (test, NULL);
- }
-
- /************************************************************/
- libst_title (test, "test ident building with valid data");
- text = pk_task_package_id_to_string (ident);
- if (strcmp (text, "moo;0.0.1;i386;fedora") == 0) {
- libst_success (test, NULL);
- } else {
- libst_failed (test, "package_id is '%s'", text);
- }
- g_free (text);
- pk_task_package_id_free (ident);
-
-
libst_end (test);
}
#endif
diff --git a/libpackagekit/pk-task-utils.h b/libpackagekit/pk-task-utils.h
index 7acb456..3230ca7 100644
--- a/libpackagekit/pk-task-utils.h
+++ b/libpackagekit/pk-task-utils.h
@@ -96,13 +96,6 @@ typedef enum {
PK_TASK_ACTION_UNKNOWN
} PkTaskAction;
-typedef struct {
- gchar *name;
- gchar *version;
- gchar *arch;
- gchar *data;
-} PkPackageId;
-
PkTaskExit pk_task_exit_from_text (const gchar *exit);
const gchar *pk_task_exit_to_text (PkTaskExit exit);
@@ -123,17 +116,6 @@ const gchar *pk_task_action_to_text (P
gboolean pk_task_check_filter (const gchar *filter);
-/* package_id parsing */
-PkPackageId *pk_task_package_id_new (void);
-PkPackageId *pk_task_package_id_from_string (const gchar *package_id);
-gchar *pk_task_package_id_build (const gchar *name,
- const gchar *version,
- const gchar *arch,
- const gchar *data);
-gchar *pk_task_package_id_to_string (PkPackageId *ident);
-gboolean pk_task_package_id_free (PkPackageId *ident);
-gboolean pk_task_package_id_check (const gchar *package_id);
-
/* actions */
gchar *pk_task_action_build (PkTaskAction action, ...);
gboolean pk_task_action_contains (const gchar *actions,
diff --git a/src/pk-engine.c b/src/pk-engine.c
index 1f7154d..a50c9ce 100644
--- a/src/pk-engine.c
+++ b/src/pk-engine.c
@@ -38,6 +38,7 @@
#include <dbus/dbus-glib-lowlevel.h>
#include <polkit/polkit.h>
#include <polkit-dbus/polkit-dbus.h>
+#include <pk-package-id.h>
#include <pk-debug.h>
#include "pk-task.h"
@@ -704,7 +705,7 @@ pk_engine_get_deps (PkEngine *engine, co
g_return_val_if_fail (PK_IS_ENGINE (engine), FALSE);
/* check package_id */
- ret = pk_task_package_id_check (package_id);
+ ret = pk_package_id_check (package_id);
if (ret == FALSE) {
*error = g_error_new (PK_ENGINE_ERROR, PK_ENGINE_ERROR_PACKAGE_ID_INVALID,
"The package id '%s' is not valid", package_id);
@@ -824,7 +825,7 @@ pk_engine_remove_package (PkEngine *engi
g_return_if_fail (PK_IS_ENGINE (engine));
/* check package_id */
- ret = pk_task_package_id_check (package_id);
+ ret = pk_package_id_check (package_id);
if (ret == FALSE) {
error = g_error_new (PK_ENGINE_ERROR, PK_ENGINE_ERROR_PACKAGE_ID_INVALID,
"The package id '%s' is not valid", package_id);
@@ -873,7 +874,7 @@ pk_engine_install_package (PkEngine *eng
g_return_if_fail (PK_IS_ENGINE (engine));
/* check package_id */
- ret = pk_task_package_id_check (package_id);
+ ret = pk_package_id_check (package_id);
if (ret == FALSE) {
error = g_error_new (PK_ENGINE_ERROR, PK_ENGINE_ERROR_PACKAGE_ID_INVALID,
"The package id '%s' is not valid", package_id);
@@ -922,7 +923,7 @@ pk_engine_update_package (PkEngine *engi
g_return_if_fail (PK_IS_ENGINE (engine));
/* check package_id */
- ret = pk_task_package_id_check (package_id);
+ ret = pk_package_id_check (package_id);
if (ret == FALSE) {
error = g_error_new (PK_ENGINE_ERROR, PK_ENGINE_ERROR_PACKAGE_ID_INVALID,
"The package id '%s' is not valid", package_id);
diff --git a/src/pk-task-common.c b/src/pk-task-common.c
index 43e4893..dbf6f66 100644
--- a/src/pk-task-common.c
+++ b/src/pk-task-common.c
@@ -24,6 +24,7 @@
#include <glib/gi18n.h>
#include <string.h>
#include <stdlib.h>
+#include <pk-package-id.h>
#include "pk-debug.h"
#include "pk-task.h"
@@ -125,7 +126,7 @@ pk_task_parse_common_output (PkTask *tas
ret = FALSE;
goto out;
}
- if (pk_task_package_id_check (sections[2]) == TRUE) {
+ if (pk_package_id_check (sections[2]) == TRUE) {
value = atoi(sections[1]);
pk_debug ("value=%i, package='%s' shortdesc='%s'", value, sections[2], sections[3]);
pk_task_package (task, value, sections[2], sections[3]);
diff-tree 0e2e5a91ff9f5ca3b8307c37334f02ec74154de7 (from e4c09766f32f477e815fd08193b23bc842b75ccb)
Author: Richard Hughes <richard at hughsie.com>
Date: Fri Aug 31 01:10:32 2007 +0100
rename ident to id
diff --git a/client/pk-console.c b/client/pk-console.c
index f3da273..b7ae8a3 100644
--- a/client/pk-console.c
+++ b/client/pk-console.c
@@ -59,8 +59,8 @@ pk_console_make_space (const gchar *data
static void
pk_console_package_cb (PkTaskClient *tclient, guint value, const gchar *package_id, const gchar *summary, gpointer data)
{
- PkPackageIdent *ident;
- PkPackageIdent *spacing;
+ PkPackageId *ident;
+ PkPackageId *spacing;
const gchar *installed;
guint extra;
@@ -70,8 +70,8 @@ pk_console_package_cb (PkTaskClient *tcl
installed = "yes ";
}
- spacing = pk_task_package_ident_new ();
- ident = pk_task_package_ident_from_string (package_id);
+ spacing = pk_task_package_id_new ();
+ ident = pk_task_package_id_from_string (package_id);
/* these numbers are guesses */
extra = 0;
@@ -89,8 +89,8 @@ pk_console_package_cb (PkTaskClient *tcl
summary);
/* free all the data */
- pk_task_package_ident_free (ident);
- pk_task_package_ident_free (spacing);
+ pk_task_package_id_free (ident);
+ pk_task_package_id_free (spacing);
}
/**
diff --git a/libpackagekit/pk-task-utils.c b/libpackagekit/pk-task-utils.c
index 63b1893..b9f9e98 100644
--- a/libpackagekit/pk-task-utils.c
+++ b/libpackagekit/pk-task-utils.c
@@ -266,10 +266,10 @@ pk_task_action_to_text (PkTaskAction act
}
/**
- * pk_task_check_package_id:
+ * pk_task_package_id_check:
**/
gboolean
-pk_task_check_package_id (const gchar *package_id)
+pk_task_package_id_check (const gchar *package_id)
{
guint i;
guint length;
@@ -353,23 +353,23 @@ out:
}
/**
- * pk_task_package_ident_build:
+ * pk_task_package_id_build:
**/
gchar *
-pk_task_package_ident_build (const gchar *name, const gchar *version,
+pk_task_package_id_build (const gchar *name, const gchar *version,
const gchar *arch, const gchar *data)
{
return g_strdup_printf ("%s;%s;%s;%s", name, version, arch, data);
}
/**
- * pk_task_package_ident_new:
+ * pk_task_package_id_new:
**/
-PkPackageIdent *
-pk_task_package_ident_new (void)
+PkPackageId *
+pk_task_package_id_new (void)
{
- PkPackageIdent *ident;
- ident = g_new0 (PkPackageIdent, 1);
+ PkPackageId *ident;
+ ident = g_new0 (PkPackageId, 1);
ident->name = NULL;
ident->version = NULL;
ident->arch = NULL;
@@ -378,13 +378,13 @@ pk_task_package_ident_new (void)
}
/**
- * pk_task_package_ident_from_string:
+ * pk_task_package_id_from_string:
**/
-PkPackageIdent*
-pk_task_package_ident_from_string (const gchar *package_id)
+PkPackageId *
+pk_task_package_id_from_string (const gchar *package_id)
{
gchar **sections = NULL;
- PkPackageIdent *ident = NULL;
+ PkPackageId *ident = NULL;
if (package_id == NULL) {
pk_warning ("Package ident is null!");
@@ -399,7 +399,7 @@ pk_task_package_ident_from_string (const
}
/* create new object */
- ident = pk_task_package_ident_new ();
+ ident = pk_task_package_id_new ();
ident->name = g_strdup (sections[0]);
ident->version = g_strdup (sections[1]);
ident->arch = g_strdup (sections[2]);
@@ -412,20 +412,20 @@ out:
}
/**
- * pk_task_package_ident_to_string:
+ * pk_task_package_id_to_string:
**/
gchar *
-pk_task_package_ident_to_string (PkPackageIdent *ident)
+pk_task_package_id_to_string (PkPackageId *ident)
{
return g_strdup_printf ("%s;%s;%s;%s", ident->name, ident->version,
ident->arch, ident->data);
}
/**
- * pk_task_package_ident_free:
+ * pk_task_package_id_free:
**/
gboolean
-pk_task_package_ident_free (PkPackageIdent *ident)
+pk_task_package_id_free (PkPackageId *ident)
{
g_free (ident->name);
g_free (ident->arch);
@@ -500,7 +500,7 @@ libst_task_utils (LibSelfTest *test)
gboolean ret;
gchar *text;
const gchar *temp;
- PkPackageIdent *ident;
+ PkPackageId *ident;
if (libst_start (test, "PkTaskUtils", CLASS_AUTO) == FALSE) {
return;
@@ -550,7 +550,7 @@ libst_task_utils (LibSelfTest *test)
**************** IDENT ******************
************************************************************/
libst_title (test, "get an ident object");
- ident = pk_task_package_ident_new ();
+ ident = pk_task_package_id_new ();
if (ident != NULL) {
libst_success (test, NULL);
} else {
@@ -559,7 +559,7 @@ libst_task_utils (LibSelfTest *test)
/************************************************************/
libst_title (test, "test ident freeing early");
- ret = pk_task_package_ident_free (ident);
+ ret = pk_task_package_id_free (ident);
if (ret == TRUE) {
libst_success (test, NULL);
} else {
@@ -569,7 +569,7 @@ libst_task_utils (LibSelfTest *test)
/************************************************************/
libst_title (test, "parse incorrect package_id from string (null)");
temp = NULL;
- ident = pk_task_package_ident_from_string (temp);
+ ident = pk_task_package_id_from_string (temp);
if (ident == NULL) {
libst_success (test, NULL);
} else {
@@ -579,7 +579,7 @@ libst_task_utils (LibSelfTest *test)
/************************************************************/
libst_title (test, "parse incorrect package_id from string (empty)");
temp = "";
- ident = pk_task_package_ident_from_string (temp);
+ ident = pk_task_package_id_from_string (temp);
if (ident == NULL) {
libst_success (test, NULL);
} else {
@@ -589,7 +589,7 @@ libst_task_utils (LibSelfTest *test)
/************************************************************/
libst_title (test, "parse incorrect package_id from string (not enough)");
temp = "moo;0.0.1;i386";
- ident = pk_task_package_ident_from_string (temp);
+ ident = pk_task_package_id_from_string (temp);
if (ident == NULL) {
libst_success (test, NULL);
} else {
@@ -598,7 +598,7 @@ libst_task_utils (LibSelfTest *test)
/************************************************************/
libst_title (test, "parse package_id from string");
- ident = pk_task_package_ident_from_string ("moo;0.0.1;i386;fedora");
+ ident = pk_task_package_id_from_string ("moo;0.0.1;i386;fedora");
if (strcmp (ident->name, "moo") == 0 &&
strcmp (ident->arch, "i386") == 0 &&
strcmp (ident->data, "fedora") == 0 &&
@@ -610,14 +610,14 @@ libst_task_utils (LibSelfTest *test)
/************************************************************/
libst_title (test, "test ident building with valid data");
- text = pk_task_package_ident_to_string (ident);
+ text = pk_task_package_id_to_string (ident);
if (strcmp (text, "moo;0.0.1;i386;fedora") == 0) {
libst_success (test, NULL);
} else {
libst_failed (test, "package_id is '%s'", text);
}
g_free (text);
- pk_task_package_ident_free (ident);
+ pk_task_package_id_free (ident);
libst_end (test);
diff --git a/libpackagekit/pk-task-utils.h b/libpackagekit/pk-task-utils.h
index c105c74..7acb456 100644
--- a/libpackagekit/pk-task-utils.h
+++ b/libpackagekit/pk-task-utils.h
@@ -101,7 +101,7 @@ typedef struct {
gchar *version;
gchar *arch;
gchar *data;
-} PkPackageIdent;
+} PkPackageId;
PkTaskExit pk_task_exit_from_text (const gchar *exit);
const gchar *pk_task_exit_to_text (PkTaskExit exit);
@@ -121,18 +121,18 @@ const gchar *pk_task_group_to_text (Pk
PkTaskAction pk_task_action_from_text (const gchar *action);
const gchar *pk_task_action_to_text (PkTaskAction action);
-gboolean pk_task_check_package_id (const gchar *package_id);
gboolean pk_task_check_filter (const gchar *filter);
-/* ident parsing */
-PkPackageIdent *pk_task_package_ident_new (void);
-PkPackageIdent *pk_task_package_ident_from_string (const gchar *package_id);
-gchar *pk_task_package_ident_build (const gchar *name,
+/* package_id parsing */
+PkPackageId *pk_task_package_id_new (void);
+PkPackageId *pk_task_package_id_from_string (const gchar *package_id);
+gchar *pk_task_package_id_build (const gchar *name,
const gchar *version,
const gchar *arch,
const gchar *data);
-gchar *pk_task_package_ident_to_string (PkPackageIdent *ident);
-gboolean pk_task_package_ident_free (PkPackageIdent *ident);
+gchar *pk_task_package_id_to_string (PkPackageId *ident);
+gboolean pk_task_package_id_free (PkPackageId *ident);
+gboolean pk_task_package_id_check (const gchar *package_id);
/* actions */
gchar *pk_task_action_build (PkTaskAction action, ...);
diff --git a/src/pk-engine.c b/src/pk-engine.c
index 793587a..1f7154d 100644
--- a/src/pk-engine.c
+++ b/src/pk-engine.c
@@ -704,7 +704,7 @@ pk_engine_get_deps (PkEngine *engine, co
g_return_val_if_fail (PK_IS_ENGINE (engine), FALSE);
/* check package_id */
- ret = pk_task_check_package_id (package_id);
+ ret = pk_task_package_id_check (package_id);
if (ret == FALSE) {
*error = g_error_new (PK_ENGINE_ERROR, PK_ENGINE_ERROR_PACKAGE_ID_INVALID,
"The package id '%s' is not valid", package_id);
@@ -824,7 +824,7 @@ pk_engine_remove_package (PkEngine *engi
g_return_if_fail (PK_IS_ENGINE (engine));
/* check package_id */
- ret = pk_task_check_package_id (package_id);
+ ret = pk_task_package_id_check (package_id);
if (ret == FALSE) {
error = g_error_new (PK_ENGINE_ERROR, PK_ENGINE_ERROR_PACKAGE_ID_INVALID,
"The package id '%s' is not valid", package_id);
@@ -873,7 +873,7 @@ pk_engine_install_package (PkEngine *eng
g_return_if_fail (PK_IS_ENGINE (engine));
/* check package_id */
- ret = pk_task_check_package_id (package_id);
+ ret = pk_task_package_id_check (package_id);
if (ret == FALSE) {
error = g_error_new (PK_ENGINE_ERROR, PK_ENGINE_ERROR_PACKAGE_ID_INVALID,
"The package id '%s' is not valid", package_id);
@@ -922,7 +922,7 @@ pk_engine_update_package (PkEngine *engi
g_return_if_fail (PK_IS_ENGINE (engine));
/* check package_id */
- ret = pk_task_check_package_id (package_id);
+ ret = pk_task_package_id_check (package_id);
if (ret == FALSE) {
error = g_error_new (PK_ENGINE_ERROR, PK_ENGINE_ERROR_PACKAGE_ID_INVALID,
"The package id '%s' is not valid", package_id);
diff --git a/src/pk-task-common.c b/src/pk-task-common.c
index 5826db9..43e4893 100644
--- a/src/pk-task-common.c
+++ b/src/pk-task-common.c
@@ -125,7 +125,7 @@ pk_task_parse_common_output (PkTask *tas
ret = FALSE;
goto out;
}
- if (pk_task_check_package_id (sections[2]) == TRUE) {
+ if (pk_task_package_id_check (sections[2]) == TRUE) {
value = atoi(sections[1]);
pk_debug ("value=%i, package='%s' shortdesc='%s'", value, sections[2], sections[3]);
pk_task_package (task, value, sections[2], sections[3]);
diff-tree e4c09766f32f477e815fd08193b23bc842b75ccb (from 85a4c10ea2dd211dd80cbf5c24afe59231621618)
Author: Richard Hughes <richard at hughsie.com>
Date: Fri Aug 31 01:01:48 2007 +0100
add some more tests
diff --git a/libpackagekit/pk-task-utils.c b/libpackagekit/pk-task-utils.c
index 821ce01..63b1893 100644
--- a/libpackagekit/pk-task-utils.c
+++ b/libpackagekit/pk-task-utils.c
@@ -383,13 +383,18 @@ pk_task_package_ident_new (void)
PkPackageIdent*
pk_task_package_ident_from_string (const gchar *package_id)
{
- gchar **sections;
+ gchar **sections = NULL;
PkPackageIdent *ident = NULL;
+ if (package_id == NULL) {
+ pk_warning ("Package ident is null!");
+ goto out;
+ }
+
/* split by delimeter ';' */
- sections = g_strsplit (package_id, ";", 4);
+ sections = g_strsplit (package_id, ";", 0);
if (g_strv_length (sections) != 4) {
- pk_debug ("Package ident '%s' is invalid (sections=%d)", package_id, g_strv_length (sections));
+ pk_warning ("Package ident '%s' is invalid (sections=%d)", package_id, g_strv_length (sections));
goto out;
}
@@ -400,7 +405,9 @@ pk_task_package_ident_from_string (const
ident->arch = g_strdup (sections[2]);
ident->data = g_strdup (sections[3]);
out:
- g_strfreev (sections);
+ if (sections != NULL) {
+ g_strfreev (sections);
+ }
return ident;
}
@@ -492,12 +499,16 @@ libst_task_utils (LibSelfTest *test)
{
gboolean ret;
gchar *text;
+ const gchar *temp;
+ PkPackageIdent *ident;
if (libst_start (test, "PkTaskUtils", CLASS_AUTO) == FALSE) {
return;
}
- /************************************************************/
+ /************************************************************
+ **************** ACTIONS ******************
+ ************************************************************/
libst_title (test, "test the action building (single)");
text = pk_task_action_build (PK_TASK_ACTION_INSTALL, 0);
if (strcmp (text, "install") == 0) {
@@ -535,6 +546,80 @@ libst_task_utils (LibSelfTest *test)
}
g_free (text);
+ /************************************************************
+ **************** IDENT ******************
+ ************************************************************/
+ libst_title (test, "get an ident object");
+ ident = pk_task_package_ident_new ();
+ if (ident != NULL) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, NULL);
+ }
+
+ /************************************************************/
+ libst_title (test, "test ident freeing early");
+ ret = pk_task_package_ident_free (ident);
+ if (ret == TRUE) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, NULL);
+ }
+
+ /************************************************************/
+ libst_title (test, "parse incorrect package_id from string (null)");
+ temp = NULL;
+ ident = pk_task_package_ident_from_string (temp);
+ if (ident == NULL) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, "passed an invalid string '%s'", temp);
+ }
+
+ /************************************************************/
+ libst_title (test, "parse incorrect package_id from string (empty)");
+ temp = "";
+ ident = pk_task_package_ident_from_string (temp);
+ if (ident == NULL) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, "passed an invalid string '%s'", temp);
+ }
+
+ /************************************************************/
+ libst_title (test, "parse incorrect package_id from string (not enough)");
+ temp = "moo;0.0.1;i386";
+ ident = pk_task_package_ident_from_string (temp);
+ if (ident == NULL) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, "passed an invalid string '%s'", temp);
+ }
+
+ /************************************************************/
+ libst_title (test, "parse package_id from string");
+ ident = pk_task_package_ident_from_string ("moo;0.0.1;i386;fedora");
+ if (strcmp (ident->name, "moo") == 0 &&
+ strcmp (ident->arch, "i386") == 0 &&
+ strcmp (ident->data, "fedora") == 0 &&
+ strcmp (ident->version, "0.0.1") == 0) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, NULL);
+ }
+
+ /************************************************************/
+ libst_title (test, "test ident building with valid data");
+ text = pk_task_package_ident_to_string (ident);
+ if (strcmp (text, "moo;0.0.1;i386;fedora") == 0) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, "package_id is '%s'", text);
+ }
+ g_free (text);
+ pk_task_package_ident_free (ident);
+
+
libst_end (test);
}
#endif
diff-tree 85a4c10ea2dd211dd80cbf5c24afe59231621618 (from 189907f399ebeca7c3fd92d2e13b111016bd3996)
Author: Richard Hughes <richard at hughsie.com>
Date: Fri Aug 31 00:42:50 2007 +0100
start to add tests
diff --git a/libpackagekit/pk-task-utils.c b/libpackagekit/pk-task-utils.c
index 5fdb9ef..821ce01 100644
--- a/libpackagekit/pk-task-utils.c
+++ b/libpackagekit/pk-task-utils.c
@@ -490,12 +490,51 @@ pk_task_action_contains (const gchar *ac
void
libst_task_utils (LibSelfTest *test)
{
-// gboolean ret;
+ gboolean ret;
+ gchar *text;
- if (libst_start (test, "PktaskUtils", CLASS_AUTO) == FALSE) {
+ if (libst_start (test, "PkTaskUtils", CLASS_AUTO) == FALSE) {
return;
}
+ /************************************************************/
+ libst_title (test, "test the action building (single)");
+ text = pk_task_action_build (PK_TASK_ACTION_INSTALL, 0);
+ if (strcmp (text, "install") == 0) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, "incorrect single argument '%s'", text);
+ }
+ g_free (text);
+
+ /************************************************************/
+ libst_title (test, "test the action building (multiple)");
+ text = pk_task_action_build (PK_TASK_ACTION_INSTALL, PK_TASK_ACTION_SEARCH_NAME, PK_TASK_ACTION_GET_DEPS, 0);
+ if (strcmp (text, "install;search-name;get-deps") == 0) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, "incorrect multiple argument '%s'", text);
+ }
+
+ /************************************************************/
+ libst_title (test, "test the action checking (present)");
+ ret = pk_task_action_contains (text, PK_TASK_ACTION_INSTALL);
+ if (ret == TRUE) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, "not found present");
+ }
+
+ /************************************************************/
+ libst_title (test, "test the action checking (not-present)");
+ ret = pk_task_action_contains (text, PK_TASK_ACTION_REMOVE);
+ if (ret == FALSE) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, "found present");
+ }
+ g_free (text);
+
libst_end (test);
}
#endif
diff --git a/libselftest/libselftest.h b/libselftest/libselftest.h
index 39c469d..c2d7d8a 100644
--- a/libselftest/libselftest.h
+++ b/libselftest/libselftest.h
@@ -23,6 +23,7 @@
#define __LIBSELFTEST_H
#include <glib.h>
+#include <string.h>
typedef enum
{
diff-tree 189907f399ebeca7c3fd92d2e13b111016bd3996 (from 34c7dee49a776ed6de257465091857ec5f765e5b)
Author: Richard Hughes <richard at hughsie.com>
Date: Fri Aug 31 00:26:31 2007 +0100
make libselftest -> libst for my typing...
diff --git a/libpackagekit/pk-self-test.c b/libpackagekit/pk-self-test.c
index 364a797..7658d08 100644
--- a/libpackagekit/pk-self-test.c
+++ b/libpackagekit/pk-self-test.c
@@ -24,7 +24,7 @@
#include <libselftest.h>
/* prototypes */
-void libselftest_task_utils (LibSelfTest *test);
+void libst_task_utils (LibSelfTest *test);
int
main (int argc, char **argv)
@@ -32,11 +32,11 @@ main (int argc, char **argv)
LibSelfTest test;
g_type_init ();
- libselftest_init (&test);
+ libst_init (&test);
/* tests go here */
- libselftest_task_utils (&test);
+ libst_task_utils (&test);
- return (libselftest_finish (&test));
+ return (libst_finish (&test));
}
diff --git a/libpackagekit/pk-task-utils.c b/libpackagekit/pk-task-utils.c
index daa2c26..5fdb9ef 100644
--- a/libpackagekit/pk-task-utils.c
+++ b/libpackagekit/pk-task-utils.c
@@ -488,15 +488,15 @@ pk_task_action_contains (const gchar *ac
#include <libselftest.h>
void
-libselftest_task_utils (LibSelfTest *test)
+libst_task_utils (LibSelfTest *test)
{
// gboolean ret;
- if (libselftest_start (test, "PktaskUtils", CLASS_AUTO) == FALSE) {
+ if (libst_start (test, "PktaskUtils", CLASS_AUTO) == FALSE) {
return;
}
- libselftest_end (test);
+ libst_end (test);
}
#endif
diff --git a/libselftest/libselftest.c b/libselftest/libselftest.c
index 362ccb0..270eb80 100644
--- a/libselftest/libselftest.c
+++ b/libselftest/libselftest.c
@@ -28,7 +28,7 @@
#include "libselftest.h"
void
-libselftest_init (LibSelfTest *test)
+libst_init (LibSelfTest *test)
{
test->total = 0;
test->succeeded = 0;
@@ -39,7 +39,7 @@ libselftest_init (LibSelfTest *test)
}
gint
-libselftest_finish (LibSelfTest *test)
+libst_finish (LibSelfTest *test)
{
gint retval;
g_print ("test passes (%u/%u) : ", test->succeeded, test->total);
@@ -54,7 +54,7 @@ libselftest_finish (LibSelfTest *test)
}
gboolean
-libselftest_start (LibSelfTest *test, const gchar *name, LibSelfTestClass class)
+libst_start (LibSelfTest *test, const gchar *name, LibSelfTestClass class)
{
if (class == CLASS_AUTO && test->class == CLASS_MANUAL) {
return FALSE;
@@ -75,7 +75,7 @@ libselftest_start (LibSelfTest *test, co
}
void
-libselftest_end (LibSelfTest *test)
+libst_end (LibSelfTest *test)
{
if (test->started == FALSE) {
g_print ("Not started test! Cannot finish!\n");
@@ -89,7 +89,7 @@ libselftest_end (LibSelfTest *test)
}
void
-libselftest_title (LibSelfTest *test, const gchar *format, ...)
+libst_title (LibSelfTest *test, const gchar *format, ...)
{
va_list args;
gchar va_args_buffer [1025];
@@ -103,7 +103,7 @@ libselftest_title (LibSelfTest *test, co
}
void
-libselftest_success (LibSelfTest *test, const gchar *format, ...)
+libst_success (LibSelfTest *test, const gchar *format, ...)
{
va_list args;
gchar va_args_buffer [1025];
@@ -122,7 +122,7 @@ finish:
}
void
-libselftest_failed (LibSelfTest *test, const gchar *format, ...)
+libst_failed (LibSelfTest *test, const gchar *format, ...)
{
va_list args;
gchar va_args_buffer [1025];
diff --git a/libselftest/libselftest.h b/libselftest/libselftest.h
index aa5bd0f..39c469d 100644
--- a/libselftest/libselftest.h
+++ b/libselftest/libselftest.h
@@ -50,13 +50,13 @@ typedef struct
gchar *type;
} LibSelfTest;
-gboolean libselftest_start (LibSelfTest *test, const gchar *name, LibSelfTestClass class);
-void libselftest_end (LibSelfTest *test);
-void libselftest_title (LibSelfTest *test, const gchar *format, ...);
-void libselftest_success (LibSelfTest *test, const gchar *format, ...);
-void libselftest_failed (LibSelfTest *test, const gchar *format, ...);
-void libselftest_init (LibSelfTest *test);
-gint libselftest_finish (LibSelfTest *test);
+gboolean libst_start (LibSelfTest *test, const gchar *name, LibSelfTestClass class);
+void libst_end (LibSelfTest *test);
+void libst_title (LibSelfTest *test, const gchar *format, ...);
+void libst_success (LibSelfTest *test, const gchar *format, ...);
+void libst_failed (LibSelfTest *test, const gchar *format, ...);
+void libst_init (LibSelfTest *test);
+gint libst_finish (LibSelfTest *test);
#endif /* __LIBSELFTEST_H */
diff --git a/src/pk-self-test.c b/src/pk-self-test.c
index 99dde81..f8a7e49 100644
--- a/src/pk-self-test.c
+++ b/src/pk-self-test.c
@@ -24,7 +24,7 @@
#include <libselftest.h>
/* prototypes */
-void libselftest_spawn (LibSelfTest *test);
+void libst_spawn (LibSelfTest *test);
int
main (int argc, char **argv)
@@ -32,11 +32,11 @@ main (int argc, char **argv)
LibSelfTest test;
g_type_init ();
- libselftest_init (&test);
+ libst_init (&test);
/* tests go here */
- libselftest_spawn (&test);
+ libst_spawn (&test);
- return (libselftest_finish (&test));
+ return (libst_finish (&test));
}
diff --git a/src/pk-spawn.c b/src/pk-spawn.c
index 9717195..7901e38 100644
--- a/src/pk-spawn.c
+++ b/src/pk-spawn.c
@@ -361,12 +361,12 @@ pk_test_stderr_cb (PkSpawn *spawn, const
}
void
-libselftest_spawn (LibSelfTest *test)
+libst_spawn (LibSelfTest *test)
{
PkSpawn *spawn;
gboolean ret;
- if (libselftest_start (test, "PkSpawn", CLASS_AUTO) == FALSE) {
+ if (libst_start (test, "PkSpawn", CLASS_AUTO) == FALSE) {
return;
}
@@ -379,22 +379,22 @@ libselftest_spawn (LibSelfTest *test)
G_CALLBACK (pk_test_stderr_cb), test);
/************************************************************/
- libselftest_title (test, "make sure return error for missing file");
+ libst_title (test, "make sure return error for missing file");
ret = pk_spawn_command (spawn, "./pk-spawn-test-xxx.sh");
if (ret == FALSE) {
- libselftest_success (test, "failed to run invalid file");
+ libst_success (test, "failed to run invalid file");
} else {
- libselftest_failed (test, "ran incorrect file");
+ libst_failed (test, "ran incorrect file");
}
#if 0
/************************************************************/
- libselftest_title (test, "make sure run correct helper");
+ libst_title (test, "make sure run correct helper");
ret = pk_spawn_command (spawn, "./pk-spawn-test.sh");
if (ret == TRUE) {
- libselftest_success (test, "ran correct file");
+ libst_success (test, "ran correct file");
} else {
- libselftest_failed (test, "did not run helper");
+ libst_failed (test, "did not run helper");
}
#endif
@@ -406,7 +406,7 @@ libselftest_spawn (LibSelfTest *test)
g_object_unref (spawn);
- libselftest_end (test);
+ libst_end (test);
}
#endif
diff-tree 34c7dee49a776ed6de257465091857ec5f765e5b (from f2e239b7f7ee856baf236861b10596ee3482458a)
Author: Richard Hughes <richard at hughsie.com>
Date: Fri Aug 31 00:22:25 2007 +0100
correct header define
diff --git a/libselftest/libselftest.h b/libselftest/libselftest.h
index ea6d928..aa5bd0f 100644
--- a/libselftest/libselftest.h
+++ b/libselftest/libselftest.h
@@ -19,8 +19,8 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-#ifndef __libselftest_H
-#define __libselftest_H
+#ifndef __LIBSELFTEST_H
+#define __LIBSELFTEST_H
#include <glib.h>
@@ -58,5 +58,5 @@ void libselftest_failed (LibSelfTest *t
void libselftest_init (LibSelfTest *test);
gint libselftest_finish (LibSelfTest *test);
-#endif /* __libselftest_H */
+#endif /* __LIBSELFTEST_H */
diff-tree f2e239b7f7ee856baf236861b10596ee3482458a (from 9db7bdd032ce7b5fc79282eda2d81f87f187297f)
Author: Richard Hughes <richard at hughsie.com>
Date: Fri Aug 31 00:20:13 2007 +0100
use a selftest library
diff --git a/Makefile.am b/Makefile.am
index 8920b1d..50a956f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,6 +1,7 @@
SUBDIRS = \
policy \
man \
+ libselftest \
libgbus \
libpackagekit \
src \
diff --git a/configure.ac b/configure.ac
index 4e55c70..6aaefd2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -302,6 +302,7 @@ AC_OUTPUT([
packagekit.pc
Makefile
man/Makefile
+libselftest/Makefile
libgbus/Makefile
libpackagekit/Makefile
policy/Makefile
diff --git a/libpackagekit/.gitignore b/libpackagekit/.gitignore
index c25dd54..f9799a9 100644
--- a/libpackagekit/.gitignore
+++ b/libpackagekit/.gitignore
@@ -5,4 +5,5 @@
*.lo
*-marshal.c
*-marshal.h
+pk-self-test
diff --git a/libpackagekit/Makefile.am b/libpackagekit/Makefile.am
index e6d3ce6..a9dd28e 100644
--- a/libpackagekit/Makefile.am
+++ b/libpackagekit/Makefile.am
@@ -6,6 +6,7 @@ INCLUDES = \
$(DBUS_CFLAGS) \
-I$(top_srcdir)/libpackagekit \
-I$(top_srcdir)/libgbus \
+ -I$(top_srcdir)/libselftest \
-DPACKAGE_DATA_DIR=\""$(datadir)"\" \
-DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\"
@@ -13,6 +14,10 @@ GBUS_LIBS = \
$(top_builddir)/libgbus/libgbus.la \
$(NULL)
+SELFTEST_LIBS = \
+ $(top_builddir)/libselftest/libselftest.la \
+ $(NULL)
+
lib_LTLIBRARIES = \
libpackagekit.la \
$(NULL)
@@ -64,6 +69,27 @@ libpackagekit_la_LDFLAGS = \
-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \
$(NULL)
+check_PROGRAMS = \
+ pk-self-test
+
+pk_self_test_SOURCES = \
+ pk-debug.c \
+ pk-debug.h \
+ pk-task-utils.h \
+ pk-task-utils.c \
+ pk-self-test.c \
+ $(NULL)
+
+pk_self_test_LDADD = \
+ $(GLIB_LIBS) \
+ $(DBUS_LIBS) \
+ $(SELFTEST_LIBS) \
+ $(PK_LIBS) \
+ $(NULL)
+
+pk_self_test_CPPFLAGS= \
+ -DPK_BUILD_TESTS
+
EXTRA_DIST = \
pk-marshal.list
@@ -85,3 +111,5 @@ clean-local:
CLEANFILES = $(BUILT_SOURCES)
+TESTS = pk-self-test
+
diff --git a/libpackagekit/pk-self-test.c b/libpackagekit/pk-self-test.c
new file mode 100644
index 0000000..364a797
--- /dev/null
+++ b/libpackagekit/pk-self-test.c
@@ -0,0 +1,42 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007 Richard Hughes <richard at hughsie.com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <glib.h>
+#include <glib-object.h>
+#include <libselftest.h>
+
+/* prototypes */
+void libselftest_task_utils (LibSelfTest *test);
+
+int
+main (int argc, char **argv)
+{
+ LibSelfTest test;
+
+ g_type_init ();
+ libselftest_init (&test);
+
+ /* tests go here */
+ libselftest_task_utils (&test);
+
+ return (libselftest_finish (&test));
+}
+
diff --git a/libpackagekit/pk-task-utils.c b/libpackagekit/pk-task-utils.c
index 0099144..daa2c26 100644
--- a/libpackagekit/pk-task-utils.c
+++ b/libpackagekit/pk-task-utils.c
@@ -481,3 +481,22 @@ pk_task_action_contains (const gchar *ac
return ret;
}
+/***************************************************************************
+ *** MAKE CHECK TESTS ***
+ ***************************************************************************/
+#ifdef PK_BUILD_TESTS
+#include <libselftest.h>
+
+void
+libselftest_task_utils (LibSelfTest *test)
+{
+// gboolean ret;
+
+ if (libselftest_start (test, "PktaskUtils", CLASS_AUTO) == FALSE) {
+ return;
+ }
+
+ libselftest_end (test);
+}
+#endif
+
diff --git a/libselftest/.gitignore b/libselftest/.gitignore
new file mode 100644
index 0000000..c25dd54
--- /dev/null
+++ b/libselftest/.gitignore
@@ -0,0 +1,8 @@
+.deps
+.libs
+*.o
+*.la
+*.lo
+*-marshal.c
+*-marshal.h
+
diff --git a/libselftest/Makefile.am b/libselftest/Makefile.am
new file mode 100644
index 0000000..3f119a5
--- /dev/null
+++ b/libselftest/Makefile.am
@@ -0,0 +1,20 @@
+INCLUDES = \
+ $(GLIB_CFLAGS) \
+ $(DBUS_CFLAGS) \
+ -I$(top_srcdir)/libselftest-glib \
+ -DPACKAGE_DATA_DIR=\""$(datadir)"\" \
+ -DPACKAGE_LOCALE_DIR=\""$(prefix)/$(DATADIRNAME)/locale"\"
+
+noinst_LTLIBRARIES = \
+ libselftest.la
+
+libselftest_la_SOURCES = \
+ libselftest.c \
+ libselftest.h
+libselftest_la_LIBADD = @DBUS_LIBS@ $(INTLLIBS) $(GLIB_LIBS)
+
+clean-local:
+ rm -f *~
+
+CLEANFILES = $(BUILT_SOURCES)
+
diff --git a/libselftest/libselftest.c b/libselftest/libselftest.c
new file mode 100644
index 0000000..362ccb0
--- /dev/null
+++ b/libselftest/libselftest.c
@@ -0,0 +1,142 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007 Richard Hughes <richard at hughsie.com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <stdlib.h>
+#include <glib.h>
+#include <string.h>
+#include <glib/gi18n.h>
+#include <glib-object.h>
+
+#include "libselftest.h"
+
+void
+libselftest_init (LibSelfTest *test)
+{
+ test->total = 0;
+ test->succeeded = 0;
+ test->type = NULL;
+ test->started = FALSE;
+ test->class = CLASS_AUTO;
+ test->level = LEVEL_ALL;
+}
+
+gint
+libselftest_finish (LibSelfTest *test)
+{
+ gint retval;
+ g_print ("test passes (%u/%u) : ", test->succeeded, test->total);
+ if (test->succeeded == test->total) {
+ g_print ("ALL OKAY\n");
+ retval = 0;
+ } else {
+ g_print ("%u FAILURE(S)\n", test->total - test->succeeded);
+ retval = 1;
+ }
+ return retval;
+}
+
+gboolean
+libselftest_start (LibSelfTest *test, const gchar *name, LibSelfTestClass class)
+{
+ if (class == CLASS_AUTO && test->class == CLASS_MANUAL) {
+ return FALSE;
+ }
+ if (class == CLASS_MANUAL && test->class == CLASS_AUTO) {
+ return FALSE;
+ }
+ if (test->started == TRUE) {
+ g_print ("Not ended test! Cannot start!\n");
+ exit (1);
+ }
+ test->type = g_strdup (name);
+ test->started = TRUE;
+ if (test->level == LEVEL_NORMAL) {
+ g_print ("%s...", test->type);
+ }
+ return TRUE;
+}
+
+void
+libselftest_end (LibSelfTest *test)
+{
+ if (test->started == FALSE) {
+ g_print ("Not started test! Cannot finish!\n");
+ exit (1);
+ }
+ if (test->level == LEVEL_NORMAL) {
+ g_print ("OK\n");
+ }
+ test->started = FALSE;
+ g_free (test->type);
+}
+
+void
+libselftest_title (LibSelfTest *test, const gchar *format, ...)
+{
+ va_list args;
+ gchar va_args_buffer [1025];
+ if (test->level == LEVEL_ALL) {
+ va_start (args, format);
+ g_vsnprintf (va_args_buffer, 1024, format, args);
+ va_end (args);
+ g_print ("> check #%u\t%s: \t%s...", test->total+1, test->type, va_args_buffer);
+ }
+ test->total++;
+}
+
+void
+libselftest_success (LibSelfTest *test, const gchar *format, ...)
+{
+ va_list args;
+ gchar va_args_buffer [1025];
+ if (test->level == LEVEL_ALL) {
+ if (format == NULL) {
+ g_print ("...OK\n");
+ goto finish;
+ }
+ va_start (args, format);
+ g_vsnprintf (va_args_buffer, 1024, format, args);
+ va_end (args);
+ g_print ("...OK [%s]\n", va_args_buffer);
+ }
+finish:
+ test->succeeded++;
+}
+
+void
+libselftest_failed (LibSelfTest *test, const gchar *format, ...)
+{
+ va_list args;
+ gchar va_args_buffer [1025];
+ if (test->level == LEVEL_ALL || test->level == LEVEL_NORMAL) {
+ if (format == NULL) {
+ g_print ("FAILED\n");
+ goto failed;
+ }
+ va_start (args, format);
+ g_vsnprintf (va_args_buffer, 1024, format, args);
+ va_end (args);
+ g_print ("FAILED [%s]\n", va_args_buffer);
+ }
+failed:
+ exit (1);
+}
+
diff --git a/libselftest/libselftest.h b/libselftest/libselftest.h
new file mode 100644
index 0000000..ea6d928
--- /dev/null
+++ b/libselftest/libselftest.h
@@ -0,0 +1,62 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007 Richard Hughes <richard at hughsie.com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __libselftest_H
+#define __libselftest_H
+
+#include <glib.h>
+
+typedef enum
+{
+ CLASS_ALL,
+ CLASS_AUTO,
+ CLASS_MANUAL,
+ CLASS_LAST
+} LibSelfTestClass;
+
+typedef enum
+{
+ LEVEL_QUIET,
+ LEVEL_NORMAL,
+ LEVEL_ALL,
+ LEVEL_LAST
+} LibSelfTestLevel;
+
+typedef struct
+{
+ guint total;
+ guint succeeded;
+ gboolean started;
+ LibSelfTestClass class;
+ LibSelfTestLevel level;
+ gchar *type;
+} LibSelfTest;
+
+gboolean libselftest_start (LibSelfTest *test, const gchar *name, LibSelfTestClass class);
+void libselftest_end (LibSelfTest *test);
+void libselftest_title (LibSelfTest *test, const gchar *format, ...);
+void libselftest_success (LibSelfTest *test, const gchar *format, ...);
+void libselftest_failed (LibSelfTest *test, const gchar *format, ...);
+void libselftest_init (LibSelfTest *test);
+gint libselftest_finish (LibSelfTest *test);
+
+#endif /* __libselftest_H */
+
diff --git a/src/Makefile.am b/src/Makefile.am
index 87584cd..e608601 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -14,6 +14,10 @@ PK_LIBS = \
$(top_builddir)/libpackagekit/libpackagekit.la \
$(NULL)
+SELFTEST_LIBS = \
+ $(top_builddir)/libselftest/libselftest.la \
+ $(NULL)
+
EXTRA_DIST = \
pk-marshal.list \
pk-interface.xml \
@@ -34,6 +38,7 @@ INCLUDES = \
-DVERSION="\"$(VERSION)\"" \
-DPK_DATA=\"$(pkgdatadir)\" \
-I$(top_srcdir)/libpackagekit \
+ -I$(top_srcdir)/libselftest \
$(NULL)
sbin_PROGRAMS = \
@@ -84,7 +89,7 @@ packagekitd_LDADD = \
$(NULL)
if BACKEND_TYPE_APT
-INCLUDES += \
+INCLUDES += \
$(APT_CFLAGS)
packagekitd_LDADD += \
$(APT_LIBS)
@@ -117,12 +122,12 @@ pk_self_test_SOURCES = \
pk-spawn.h \
pk-spawn.c \
pk-self-test.c \
- pk-self-test.h \
$(NULL)
pk_self_test_LDADD = \
$(GLIB_LIBS) \
$(DBUS_LIBS) \
+ $(SELFTEST_LIBS) \
$(LIBNM_LIBS) \
$(PK_LIBS) \
$(POLKIT_LIBS) \
diff --git a/src/pk-self-test.c b/src/pk-self-test.c
index 97d7aa8..99dde81 100644
--- a/src/pk-self-test.c
+++ b/src/pk-self-test.c
@@ -19,189 +19,24 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-#include "config.h"
-#include <stdlib.h>
#include <glib.h>
-#include <string.h>
-#include <glib/gi18n.h>
#include <glib-object.h>
+#include <libselftest.h>
-#include "pk-debug.h"
-#include "pk-self-test.h"
-
-gboolean
-pk_st_start (PkSelfTest *test, const gchar *name, PkSelfTestClass class)
-{
- if (class == CLASS_AUTO && test->class == CLASS_MANUAL) {
- return FALSE;
- }
- if (class == CLASS_MANUAL && test->class == CLASS_AUTO) {
- return FALSE;
- }
- if (test->started == TRUE) {
- g_print ("Not ended test! Cannot start!\n");
- exit (1);
- }
- test->type = g_strdup (name);
- test->started = TRUE;
- if (test->level == LEVEL_NORMAL) {
- g_print ("%s...", test->type);
- }
- return TRUE;
-}
-
-void
-pk_st_end (PkSelfTest *test)
-{
- if (test->started == FALSE) {
- g_print ("Not started test! Cannot finish!\n");
- exit (1);
- }
- if (test->level == LEVEL_NORMAL) {
- g_print ("OK\n");
- }
- test->started = FALSE;
- g_free (test->type);
-}
-
-void
-pk_st_title (PkSelfTest *test, const gchar *format, ...)
-{
- va_list args;
- gchar va_args_buffer [1025];
- if (test->level == LEVEL_ALL) {
- va_start (args, format);
- g_vsnprintf (va_args_buffer, 1024, format, args);
- va_end (args);
- g_print ("> check #%u\t%s: \t%s...", test->total+1, test->type, va_args_buffer);
- }
- test->total++;
-}
-
-void
-pk_st_success (PkSelfTest *test, const gchar *format, ...)
-{
- va_list args;
- gchar va_args_buffer [1025];
- if (test->level == LEVEL_ALL) {
- if (format == NULL) {
- g_print ("...OK\n");
- goto finish;
- }
- va_start (args, format);
- g_vsnprintf (va_args_buffer, 1024, format, args);
- va_end (args);
- g_print ("...OK [%s]\n", va_args_buffer);
- }
-finish:
- test->succeeded++;
-}
-
-void
-pk_st_failed (PkSelfTest *test, const gchar *format, ...)
-{
- va_list args;
- gchar va_args_buffer [1025];
- if (test->level == LEVEL_ALL || test->level == LEVEL_NORMAL) {
- if (format == NULL) {
- g_print ("FAILED\n");
- goto failed;
- }
- va_start (args, format);
- g_vsnprintf (va_args_buffer, 1024, format, args);
- va_end (args);
- g_print ("FAILED [%s]\n", va_args_buffer);
- }
-failed:
- exit (1);
-}
-
-static void
-pk_st_run_test (PkSelfTest *test, PkSelfTestFunc func)
-{
- func (test);
-}
+/* prototypes */
+void libselftest_spawn (LibSelfTest *test);
int
main (int argc, char **argv)
{
- GOptionContext *context;
- int retval;
+ LibSelfTest test;
- gboolean verbose = FALSE;
- char *class = NULL;
- char *level = NULL;
- char **tests = NULL;
-
- const GOptionEntry options[] = {
- { "verbose", '\0', 0, G_OPTION_ARG_NONE, &verbose,
- "Show verbose debugging information", NULL },
- { "class", '\0', 0, G_OPTION_ARG_STRING, &class,
- "Debug class, [manual|auto|all]", NULL },
- { "level", '\0', 0, G_OPTION_ARG_STRING, &level,
- "Set the printing level, [quiet|normal|all]", NULL },
- { "tests", '\0', 0, G_OPTION_ARG_STRING_ARRAY, &tests,
- "Debug specific modules, [common,webcam,arrayfloat]", NULL },
- { NULL}
- };
-
-verbose = TRUE;
-
- context = g_option_context_new ("GNOME Power Manager Self Test");
- g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE);
- g_option_context_parse (context, &argc, &argv, NULL);
g_type_init ();
+ libselftest_init (&test);
- pk_debug_init (verbose);
-
- PkSelfTest ttest;
- PkSelfTest *test = &ttest;
- test->total = 0;
- test->succeeded = 0;
- test->type = NULL;
- test->started = FALSE;
- test->class = CLASS_AUTO;
- test->level = LEVEL_ALL;
-
- if (class != NULL) {
- if (strcmp (class, "auto") == 0) {
- test->class = CLASS_AUTO;
- } else if (strcmp (class, "all") == 0) {
- test->class = CLASS_ALL;
- } else if (strcmp (class, "manual") == 0) {
- test->class = CLASS_MANUAL;
- } else {
- g_print ("Invalid class specified\n");
- exit (1);
- }
- }
-
- if (level != NULL) {
- if (strcmp (level, "quiet") == 0) {
- test->level = LEVEL_QUIET;
- } else if (strcmp (level, "normal") == 0) {
- test->level = LEVEL_NORMAL;
- } else if (strcmp (level, "all") == 0) {
- test->level = LEVEL_ALL;
- } else {
- g_print ("Invalid level specified\n");
- exit (1);
- }
- }
-
- /* auto */
- pk_st_run_test (test, pk_st_spawn);
-
- g_print ("test passes (%u/%u) : ", test->succeeded, test->total);
- if (test->succeeded == test->total) {
- g_print ("ALL OKAY\n");
- retval = 0;
- } else {
- g_print ("%u FAILURE(S)\n", test->total - test->succeeded);
- retval = 1;
- }
+ /* tests go here */
+ libselftest_spawn (&test);
- g_option_context_free (context);
- return retval;
+ return (libselftest_finish (&test));
}
diff --git a/src/pk-self-test.h b/src/pk-self-test.h
deleted file mode 100644
index d0a33e1..0000000
--- a/src/pk-self-test.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * Copyright (C) 2007 Richard Hughes <richard at hughsie.com>
- *
- * Licensed under the GNU General Public License Version 2
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#include <glib.h>
-
-typedef enum
-{
- CLASS_ALL,
- CLASS_AUTO,
- CLASS_MANUAL,
- CLASS_LAST
-} PkSelfTestClass;
-
-typedef enum
-{
- LEVEL_QUIET,
- LEVEL_NORMAL,
- LEVEL_ALL,
- LEVEL_LAST
-} PkSelfTestLevel;
-
-typedef struct
-{
- guint total;
- guint succeeded;
- gboolean started;
- PkSelfTestClass class;
- PkSelfTestLevel level;
- gchar *type;
-} PkSelfTest;
-
-typedef void (*PkSelfTestFunc) (PkSelfTest *test);
-
-gboolean pk_st_start (PkSelfTest *test, const gchar *name, PkSelfTestClass class);
-void pk_st_end (PkSelfTest *test);
-void pk_st_title (PkSelfTest *test, const gchar *format, ...);
-void pk_st_success (PkSelfTest *test, const gchar *format, ...);
-void pk_st_failed (PkSelfTest *test, const gchar *format, ...);
-
-void pk_st_spawn (PkSelfTest *test);
-
diff --git a/src/pk-spawn.c b/src/pk-spawn.c
index a09b23c..9717195 100644
--- a/src/pk-spawn.c
+++ b/src/pk-spawn.c
@@ -328,7 +328,7 @@ pk_spawn_new (void)
*** MAKE CHECK TESTS ***
***************************************************************************/
#ifdef PK_BUILD_TESTS
-#include "pk-self-test.h"
+#include <libselftest.h>
static GMainLoop *loop;
@@ -336,7 +336,7 @@ static GMainLoop *loop;
* pk_test_finished_cb:
**/
static void
-pk_test_finished_cb (PkSpawn *spawn, gint exitcode, PkSelfTest *test)
+pk_test_finished_cb (PkSpawn *spawn, gint exitcode, LibSelfTest *test)
{
pk_debug ("spawn exitcode=%i", exitcode);
g_main_loop_quit (loop);
@@ -346,7 +346,7 @@ pk_test_finished_cb (PkSpawn *spawn, gin
* pk_test_stdout_cb:
**/
static void
-pk_test_stdout_cb (PkSpawn *spawn, const gchar *line, PkSelfTest *test)
+pk_test_stdout_cb (PkSpawn *spawn, const gchar *line, LibSelfTest *test)
{
pk_debug ("stdout '%s'", line);
}
@@ -355,18 +355,18 @@ pk_test_stdout_cb (PkSpawn *spawn, const
* pk_test_stderr_cb:
**/
static void
-pk_test_stderr_cb (PkSpawn *spawn, const gchar *line, PkSelfTest *test)
+pk_test_stderr_cb (PkSpawn *spawn, const gchar *line, LibSelfTest *test)
{
pk_debug ("stderr '%s'", line);
}
void
-pk_st_spawn (PkSelfTest *test)
+libselftest_spawn (LibSelfTest *test)
{
PkSpawn *spawn;
gboolean ret;
- if (pk_st_start (test, "PkSpawn", CLASS_AUTO) == FALSE) {
+ if (libselftest_start (test, "PkSpawn", CLASS_AUTO) == FALSE) {
return;
}
@@ -379,22 +379,22 @@ pk_st_spawn (PkSelfTest *test)
G_CALLBACK (pk_test_stderr_cb), test);
/************************************************************/
- pk_st_title (test, "make sure return error for missing file");
+ libselftest_title (test, "make sure return error for missing file");
ret = pk_spawn_command (spawn, "./pk-spawn-test-xxx.sh");
if (ret == FALSE) {
- pk_st_success (test, "failed to run invalid file");
+ libselftest_success (test, "failed to run invalid file");
} else {
- pk_st_failed (test, "ran incorrect file");
+ libselftest_failed (test, "ran incorrect file");
}
#if 0
/************************************************************/
- pk_st_title (test, "make sure run correct helper");
+ libselftest_title (test, "make sure run correct helper");
ret = pk_spawn_command (spawn, "./pk-spawn-test.sh");
if (ret == TRUE) {
- pk_st_success (test, "ran correct file");
+ libselftest_success (test, "ran correct file");
} else {
- pk_st_failed (test, "did not run helper");
+ libselftest_failed (test, "did not run helper");
}
#endif
@@ -406,7 +406,7 @@ pk_st_spawn (PkSelfTest *test)
g_object_unref (spawn);
- pk_st_end (test);
+ libselftest_end (test);
}
#endif
diff --git a/tools/backend-change.sh b/tools/backend-change.sh
index 70a6b83..4c0338f 100755
--- a/tools/backend-change.sh
+++ b/tools/backend-change.sh
@@ -1,5 +1,5 @@
make clean
-./autogen.sh --prefix=/home/hughsie/.root --with-backend=$1
+./autogen.sh --prefix=/home/hughsie/.root --with-backend=$1 --enable-tests
make
make install
More information about the PackageKit
mailing list