[packagekit] packagekit: Branch 'master'

Richard Hughes hughsient at kemper.freedesktop.org
Wed Oct 3 00:09:07 PDT 2007


 TODO                          |    1 
 libpackagekit/pk-package-id.c |  112 ++++++++++++++++++++++++++++++++++++++++++
 libpackagekit/pk-package-id.h |    4 +
 3 files changed, 116 insertions(+), 1 deletion(-)

New commits:
diff-tree b541123242f34411dda8a04102b8ecfffb11356f (from 74032405a96c4763c8f9cc93524f4a23896589dc)
Author: Richard Hughes <richard at hughsie.com>
Date:   Wed Oct 3 08:02:28 2007 +0100

    add the new functions pk_package_id_equal and pk_package_id_strcmp as helpers.

diff --git a/TODO b/TODO
index 517cb00..28a0f9f 100644
--- a/TODO
+++ b/TODO
@@ -8,7 +8,6 @@ NOTE: RELEASE BLOCKER
 *** don't output the same package in different repos ***
 Need to store Package() in the server properly, and compare the first chunk
 (not the data) to avoid reporting the same package more than once.
-Also: pk_package_id_compare (gboolean use_data)
 Need to properly unit test...
 NOTE: RELEASE BLOCKER
 
diff --git a/libpackagekit/pk-package-id.c b/libpackagekit/pk-package-id.c
index 2751738..af07038 100644
--- a/libpackagekit/pk-package-id.c
+++ b/libpackagekit/pk-package-id.c
@@ -86,6 +86,61 @@ out:
 }
 
 /**
+ * pk_package_id_strcmp:
+ **/
+gboolean
+pk_package_id_strcmp (const gchar *pid1, const gchar *pid2)
+{
+	if (pid1 == NULL || pid2 == NULL) {
+		pk_warning ("package id compare invalid '%s' and '%s'", pid1, pid2);
+		return FALSE;
+	}
+	return (strcmp (pid1, pid2) == 0);
+}
+
+/**
+ * pk_package_id_equal:
+ * only compare first three sections, not data
+ **/
+gboolean
+pk_package_id_equal (const gchar *pid1, const gchar *pid2)
+{
+	gchar **sections1;
+	gchar **sections2;
+	gboolean ret = FALSE;
+
+	if (pid1 == NULL || pid2 == NULL) {
+		pk_warning ("package id compare invalid '%s' and '%s'", pid1, pid2);
+		return FALSE;
+	}
+
+	/* split, NULL will be returned if error */
+	sections1 = pk_package_id_split (pid1);
+	sections2 = pk_package_id_split (pid2);
+
+	/* check we split okay */
+	if (sections1 == NULL) {
+		pk_warning ("package id compare sections1 invalid '%s'", pid1);
+		return FALSE;
+	}
+	if (sections2 == NULL) {
+		pk_warning ("package id compare sections2 invalid '%s'", pid2);
+		return FALSE;
+	}
+
+	/* only compare first three sections */
+	if ((strcmp (sections1[0], sections2[0]) == 0) &&
+	    (strcmp (sections1[1], sections2[1]) == 0) &&
+	    (strcmp (sections1[2], sections2[2]) == 0)) {
+		ret = TRUE;
+	}
+
+	g_strfreev (sections1);
+	g_strfreev (sections2);
+	return ret;
+}
+
+/**
  * pk_package_id_check:
  **/
 gboolean
@@ -191,6 +246,63 @@ libst_package_id (LibSelfTest *test)
 	/************************************************************
 	 ****************          IDENT           ******************
 	 ************************************************************/
+
+	libst_title (test, "pid strcmp pass");
+	ret = pk_package_id_strcmp ("moo;0.0.1;i386;fedora", "moo;0.0.1;i386;fedora");
+	if (ret == TRUE) {
+		libst_success (test, NULL);
+	} else {
+		libst_failed (test, NULL);
+	}
+
+	libst_title (test, "pid strcmp fail");
+	ret = pk_package_id_strcmp ("moo;0.0.1;i386;fedora", "moo;0.0.2;i386;fedora");
+	if (ret == FALSE) {
+		libst_success (test, NULL);
+	} else {
+		libst_failed (test, NULL);
+	}
+
+	libst_title (test, "pid equal pass (same)");
+	ret = pk_package_id_equal ("moo;0.0.1;i386;fedora", "moo;0.0.1;i386;fedora");
+	if (ret == TRUE) {
+		libst_success (test, NULL);
+	} else {
+		libst_failed (test, NULL);
+	}
+
+	libst_title (test, "pid equal pass (different)");
+	ret = pk_package_id_equal ("moo;0.0.1;i386;fedora", "moo;0.0.1;i386;data");
+	if (ret == TRUE) {
+		libst_success (test, NULL);
+	} else {
+		libst_failed (test, NULL);
+	}
+
+	libst_title (test, "pid equal fail1");
+	ret = pk_package_id_equal ("moo;0.0.1;i386;fedora", "moo;0.0.2;x64;fedora");
+	if (ret == FALSE) {
+		libst_success (test, NULL);
+	} else {
+		libst_failed (test, NULL);
+	}
+
+	libst_title (test, "pid equal fail2");
+	ret = pk_package_id_equal ("moo;0.0.1;i386;fedora", "gnome;0.0.2;i386;fedora");
+	if (ret == FALSE) {
+		libst_success (test, NULL);
+	} else {
+		libst_failed (test, NULL);
+	}
+
+	libst_title (test, "pid equal fail3");
+	ret = pk_package_id_equal ("moo;0.0.1;i386;fedora", "moo;0.0.3;i386;fedora");
+	if (ret == FALSE) {
+		libst_success (test, NULL);
+	} else {
+		libst_failed (test, NULL);
+	}
+
 	libst_title (test, "get an ident object");
 	ident = pk_package_id_new ();
 	if (ident != NULL) {
diff --git a/libpackagekit/pk-package-id.h b/libpackagekit/pk-package-id.h
index 28eeec1..330ed5e 100644
--- a/libpackagekit/pk-package-id.h
+++ b/libpackagekit/pk-package-id.h
@@ -42,6 +42,10 @@ gchar		*pk_package_id_build			(const gch
 gchar		*pk_package_id_to_string		(PkPackageId	*ident);
 gboolean	 pk_package_id_free			(PkPackageId	*ident);
 gboolean	 pk_package_id_check			(const gchar	*package_id);
+gboolean	 pk_package_id_equal			(const gchar	*tid1,
+							 const gchar	*tid2);
+gboolean	 pk_package_id_strcmp			(const gchar	*tid1,
+							 const gchar	*tid2);
 
 G_END_DECLS
 


More information about the PackageKit mailing list