static const gchar* _get_string_from_pkg(slapt_pkg_info_t *pkg)
{
	PkPackageId *pi;
	const gchar *package_id;

	pi = _get_id_from_pkg(pkg);
	if (pi == NULL)
	    return NULL;
	package_id = pk_package_id_to_string(pi);
	pk_package_id_free(pi);
	return package_id;
}
示例#2
0
void
pk_package_id_test (EggTest *test)
{
	gboolean ret;
	gchar *text;
	const gchar *temp;
	PkPackageId *id;
	PkPackageId *id2;
	gchar **array;

	if (!egg_test_start (test, "PkPackageId"))
		return;

	/************************************************************
	 ****************          id           ******************
	 ************************************************************/

	egg_test_title (test, "id build valid");
	text = pk_package_id_build ("moo", "0.0.1", "i386", "fedora");
	if (g_strcmp0 (text, "moo;0.0.1;i386;fedora") == 0)
		egg_test_success (test, NULL);
	else
		egg_test_failed (test, NULL);
	g_free (text);

	egg_test_title (test, "id build partial");
	text = pk_package_id_build ("moo", NULL, NULL, NULL);
	if (g_strcmp0 (text, "moo;;;") == 0)
		egg_test_success (test, NULL);
	else
		egg_test_failed (test, "got '%s', expected '%s'", text, "moo;;;");
	g_free (text);

	egg_test_title (test, "pid equal pass (same)");
	ret = pk_package_id_equal_strings ("moo;0.0.1;i386;fedora", "moo;0.0.1;i386;fedora");
	egg_test_assert (test, ret);

	/************************************************************/
	egg_test_title (test, "pid equal pass (different)");
	ret = pk_package_id_equal_strings ("moo;0.0.1;i386;fedora", "moo;0.0.1;i386;data");
	egg_test_assert (test, ret);

	/************************************************************/
	egg_test_title (test, "get an id object");
	id = pk_package_id_new ();
	egg_test_assert (test, id != NULL);

	/************************************************************/
	egg_test_title (test, "test id freeing early");
	ret = pk_package_id_free (id);
	egg_test_assert (test, ret);

	/************************************************************/
	egg_test_title (test, "parse incorrect package_id from string (empty)");
	temp = "";
	id = pk_package_id_new_from_string (temp);
	if (id == NULL)
		egg_test_success (test, NULL);
	else
		egg_test_failed (test, "passed an invalid string '%s'", temp);

	/************************************************************/
	egg_test_title (test, "parse incorrect package_id from string (not enough)");
	temp = "moo;0.0.1;i386";
	id = pk_package_id_new_from_string (temp);
	if (id == NULL)
		egg_test_success (test, NULL);
	else
		egg_test_failed (test, "passed an invalid string '%s'", temp);

	/************************************************************/
	egg_test_title (test, "parse package_id from string");
	id = pk_package_id_new_from_string ("moo;0.0.1;i386;fedora");
	if (id != NULL &&
	    g_strcmp0 (id->name, "moo") == 0 &&
	    g_strcmp0 (id->arch, "i386") == 0 &&
	    g_strcmp0 (id->data, "fedora") == 0 &&
	    g_strcmp0 (id->version, "0.0.1") == 0)
		egg_test_success (test, NULL);
	else
		egg_test_failed (test, NULL);

	/************************************************************/
	egg_test_title (test, "test copying");
	id2 = pk_package_id_copy (id);
	if (id2 != NULL)
		egg_test_success (test, NULL);
	else
		egg_test_failed (test, NULL);

	/************************************************************/
	egg_test_title (test, "test id building with valid data");
	text = pk_package_id_to_string (id2);
	if (g_strcmp0 (text, "moo;0.0.1;i386;fedora") == 0)
		egg_test_success (test, NULL);
	else
		egg_test_failed (test, "package_id is '%s'", text);
	g_free (text);
	pk_package_id_free (id);
	pk_package_id_free (id2);

	/************************************************************/
	egg_test_title (test, "test id building with partial data");
	id = pk_package_id_new_from_string ("moo;;;");
	text = pk_package_id_to_string (id);
	if (g_strcmp0 (text, "moo;;;") == 0)
		egg_test_success (test, NULL);
	else
		egg_test_failed (test, "package_id is '%s', should be '%s'", text, "moo;;;");
	g_free (text);
	pk_package_id_free (id);

	/************************************************************/
	egg_test_title (test, "parse short package_id from string");
	id = pk_package_id_new_from_string ("moo;0.0.1;;");
	if (id != NULL &&
	    (g_strcmp0 (id->name, "moo") == 0) &&
	    (g_strcmp0 (id->version, "0.0.1") == 0) &&
	    id->data == NULL &&
	    id->arch == NULL)
		egg_test_success (test, NULL);
	else
		egg_test_failed (test, NULL);
	pk_package_id_free (id);

	egg_test_title (test, "id equal pass (same)");
	ret = pk_strcmp_sections ("moo;0.0.1;i386;fedora", "moo;0.0.1;i386;fedora", 4, 3);
	egg_test_assert (test, ret);

	egg_test_title (test, "id equal pass (parts==match)");
	ret = pk_strcmp_sections ("moo;0.0.1;i386;fedora", "moo;0.0.1;i386;fedora", 4, 4);
	egg_test_assert (test, ret);

	egg_test_title (test, "id equal pass (different)");
	ret = pk_strcmp_sections ("moo;0.0.1;i386;fedora", "moo;0.0.1;i386;data", 4, 3);
	egg_test_assert (test, ret);

	egg_test_title (test, "id equal fail1");
	ret = pk_strcmp_sections ("moo;0.0.1;i386;fedora", "moo;0.0.2;x64;fedora", 4, 3);
	egg_test_assert (test, !ret);

	egg_test_title (test, "id equal fail2");
	ret = pk_strcmp_sections ("moo;0.0.1;i386;fedora", "gnome;0.0.2;i386;fedora", 4, 3);
	egg_test_assert (test, !ret);

	egg_test_title (test, "id equal fail3");
	ret = pk_strcmp_sections ("moo;0.0.1;i386;fedora", "moo;0.0.3;i386;fedora", 4, 3);
	egg_test_assert (test, !ret);

	egg_test_title (test, "id equal fail (match too high)");
	ret = pk_strcmp_sections ("moo;0.0.1;i386;fedora", "moo;0.0.3;i386;fedora", 4, 5);
	egg_test_assert (test, !ret);

	/************************************************************
	 ****************          splitting         ****************
	 ************************************************************/
	egg_test_title (test, "test pass 1");
	array = pk_strsplit ("foo", 1);
	if (array != NULL &&
	    g_strcmp0 (array[0], "foo") == 0)
		egg_test_success (test, NULL);
	else
		egg_test_failed (test, "got %s", array[0]);
	g_strfreev (array);

	/************************************************************/
	egg_test_title (test, "test pass 2");
	array = pk_strsplit ("foo;moo", 2);
	if (array != NULL &&
	    g_strcmp0 (array[0], "foo") == 0 &&
	    g_strcmp0 (array[1], "moo") == 0)
		egg_test_success (test, NULL);
	else
		egg_test_failed (test, "got %s, %s", array[0], array[1]);
	g_strfreev (array);

	/************************************************************/
	egg_test_title (test, "test pass 3");
	array = pk_strsplit ("foo;moo;bar", 3);
	if (array != NULL &&
	    g_strcmp0 (array[0], "foo") == 0 &&
	    g_strcmp0 (array[1], "moo") == 0 &&
	    g_strcmp0 (array[2], "bar") == 0)
		egg_test_success (test, NULL);
	else
		egg_test_failed (test, "got %s, %s, %s, %s", array[0], array[1], array[2], array[3]);
	g_strfreev (array);

	/************************************************************/
	egg_test_title (test, "test on real packageid");
	array = pk_strsplit ("kde-i18n-csb;4:3.5.8~pre20071001-0ubuntu1;all;", 4);
	if (array != NULL &&
	    g_strcmp0 (array[0], "kde-i18n-csb") == 0 &&
	    g_strcmp0 (array[1], "4:3.5.8~pre20071001-0ubuntu1") == 0 &&
	    g_strcmp0 (array[2], "all") == 0 &&
	    g_strcmp0 (array[3], "") == 0)
		egg_test_success (test, NULL);
	else
		egg_test_failed (test, "got %s, %s, %s, %s", array[0], array[1], array[2], array[3]);
	g_strfreev (array);

	/************************************************************/
	egg_test_title (test, "test on short packageid");
	array = pk_strsplit ("kde-i18n-csb;4:3.5.8~pre20071001-0ubuntu1;;", 4);
	if (array != NULL &&
	    g_strcmp0 (array[0], "kde-i18n-csb") == 0 &&
	    g_strcmp0 (array[1], "4:3.5.8~pre20071001-0ubuntu1") == 0 &&
	    g_strcmp0 (array[2], "") == 0 &&
	    g_strcmp0 (array[3], "") == 0)
		egg_test_success (test, NULL);
	else
		egg_test_failed (test, "got %s, %s, %s, %s", array[0], array[1], array[2], array[3]);
	g_strfreev (array);

	/************************************************************/
	egg_test_title (test, "test fail under");
	array = pk_strsplit ("foo;moo", 1);
	egg_test_assert (test, array == NULL);

	/************************************************************/
	egg_test_title (test, "test fail over");
	array = pk_strsplit ("foo;moo", 3);
	egg_test_assert (test, array == NULL);

	/************************************************************/
	egg_test_title (test, "test fail missing first");
	array = pk_strsplit (";moo", 2);
	egg_test_assert (test, array == NULL);

	egg_test_end (test);
}