From 06fd58779af09c91af274433e0f45103bd9574f0 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Tue, 8 Sep 2020 13:43:29 +0200 Subject: libtracker-common: Drop type util function helpers We (now) use none of this, the code can be removed. --- src/libtracker-common/meson.build | 1 - src/libtracker-common/tracker-common.h | 1 - src/libtracker-common/tracker-date-time.c | 1 - src/libtracker-common/tracker-file-utils.c | 1 - src/libtracker-common/tracker-type-utils.c | 218 ---------------------- src/libtracker-common/tracker-type-utils.h | 47 ----- tests/libtracker-common/.gitignore | 1 - tests/libtracker-common/meson.build | 1 - tests/libtracker-common/tracker-type-utils-test.c | 217 --------------------- 9 files changed, 488 deletions(-) delete mode 100644 src/libtracker-common/tracker-type-utils.c delete mode 100644 src/libtracker-common/tracker-type-utils.h delete mode 100644 tests/libtracker-common/tracker-type-utils-test.c diff --git a/src/libtracker-common/meson.build b/src/libtracker-common/meson.build index 5a1ab7637..aff153637 100644 --- a/src/libtracker-common/meson.build +++ b/src/libtracker-common/meson.build @@ -15,7 +15,6 @@ tracker_common_sources = [ 'tracker-debug.c', 'tracker-file-utils.c', 'tracker-term-utils.c', - 'tracker-type-utils.c', 'tracker-utils.c', 'tracker-locale.c', 'tracker-parser-utils.c', diff --git a/src/libtracker-common/tracker-common.h b/src/libtracker-common/tracker-common.h index afcecfdaa..5bc03c9bf 100644 --- a/src/libtracker-common/tracker-common.h +++ b/src/libtracker-common/tracker-common.h @@ -34,7 +34,6 @@ #include "tracker-language.h" #include "tracker-parser.h" #include "tracker-term-utils.h" -#include "tracker-type-utils.h" #include "tracker-utils.h" #include "tracker-locale.h" #include "tracker-enum-types.h" diff --git a/src/libtracker-common/tracker-date-time.c b/src/libtracker-common/tracker-date-time.c index 162d9081a..8370cfc0e 100644 --- a/src/libtracker-common/tracker-date-time.c +++ b/src/libtracker-common/tracker-date-time.c @@ -34,7 +34,6 @@ #include #include "tracker-date-time.h" -#include "tracker-type-utils.h" GQuark tracker_date_error_quark (void) { return g_quark_from_static_string ("tracker_date_error-quark"); diff --git a/src/libtracker-common/tracker-file-utils.c b/src/libtracker-common/tracker-file-utils.c index 6dbb416da..9994a079b 100644 --- a/src/libtracker-common/tracker-file-utils.c +++ b/src/libtracker-common/tracker-file-utils.c @@ -39,7 +39,6 @@ #include #include "tracker-file-utils.h" -#include "tracker-type-utils.h" #define TEXT_SNIFF_SIZE 4096 diff --git a/src/libtracker-common/tracker-type-utils.c b/src/libtracker-common/tracker-type-utils.c deleted file mode 100644 index 37a095f20..000000000 --- a/src/libtracker-common/tracker-type-utils.c +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Copyright (C) 2006, Jamie McCracken - * Copyright (C) 2008, Nokia - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "config.h" - -#define _XOPEN_SOURCE -#define _XOPEN_SOURCE_EXTENDED 1 /* strcasecmp is XPG4v2 */ -#include - -#include -#include -#include - -#include - -#include "tracker-utils.h" -#include "tracker-type-utils.h" - -gint -tracker_string_in_string_list (const gchar *str, - gchar **strv) -{ - gchar **p; - gint i; - - g_return_val_if_fail (str != NULL, -1); - - if (!strv) { - return -1; - } - - for (p = strv, i = 0; *p; p++, i++) { - if (strcasecmp (*p, str) == 0) { - return i; - } - } - - return -1; -} - -gboolean -tracker_string_in_gslist (const gchar *str, - GSList *list) -{ - GSList *l; - - g_return_val_if_fail (str != NULL, FALSE); - - for (l = list; l; l = l->next) { - if (g_strcmp0 (l->data, str) == 0) { - return TRUE; - } - } - - return FALSE; -} - -GSList * -tracker_string_list_to_gslist (gchar **strv, - gsize size) -{ - GSList *list; - gsize i; - gsize size_used; - - if (!strv) { - return NULL; - } - - if (size < 1) { - size_used = g_strv_length (strv); - } else { - size_used = size; - } - - list = NULL; - - for (i = 0; i < size_used; i++) { - if (strv[i]) { - list = g_slist_prepend (list, g_strdup (strv[i])); - } else { - break; - } - } - - return g_slist_reverse (list); -} - - -gchar ** -tracker_string_to_string_list (const gchar *str) -{ - gchar **result; - - result = g_new0 (gchar *, 2); - - result [0] = g_strdup (str); - result [1] = NULL; - - return result; -} - -static gchar ** -list_to_string_list (GSList *list, gint length) -{ - GSList *l; - gchar **strv; - gint i; - - strv = g_new0 (gchar*, length + 1); - - for (l = list, i = 0; l; l = l->next) { - if (!l->data) { - continue; - } - - strv[i++] = g_strdup (l->data); - } - - strv[i] = NULL; - - return strv; -} - -gchar ** -tracker_gslist_to_string_list (GSList *list) -{ - return list_to_string_list (list, g_slist_length (list)); -} - -gchar ** -tracker_glist_to_string_list (GList *list) -{ - return list_to_string_list ((GSList*) list, g_list_length (list)); -} - -gboolean -tracker_gslist_with_string_data_equal (GSList *list1, - GSList *list2) -{ - GSList *sl; - - if (list1 == list2) { - return TRUE; - } - - if (g_slist_length (list1) != g_slist_length (list2)) { - return FALSE; - } - - /* NOTE: This is probably not the most efficient way to do - * this, but we don't want to order the list first since that - * would involve creating new memory. This would make sense - * for large list operations I think. We don't expect to be - * doing much if any of that. - */ - for (sl = list1; sl; sl = sl->next) { - const gchar *str; - - str = sl->data; - - /* If we are not still in the list, remove the dir */ - if (!tracker_string_in_gslist (str, list2)) { - return FALSE; - } - } - - for (sl = list2; sl; sl = sl->next) { - const gchar *str; - - str = sl->data; - - /* If we are now in the list, add the dir */ - if (!tracker_string_in_gslist (str, list1)) { - return FALSE; - } - } - - return TRUE; -} - -GSList * -tracker_gslist_copy_with_string_data (GSList *list) -{ - GSList *l; - GSList *new_list; - - if (!list) { - return NULL; - } - - new_list = NULL; - - for (l = list; l; l = l->next) { - new_list = g_slist_prepend (new_list, g_strdup (l->data)); - } - - new_list = g_slist_reverse (new_list); - - return new_list; -} diff --git a/src/libtracker-common/tracker-type-utils.h b/src/libtracker-common/tracker-type-utils.h deleted file mode 100644 index e73142ff9..000000000 --- a/src/libtracker-common/tracker-type-utils.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (C) 2006, Jamie McCracken - * Copyright (C) 2008, Nokia - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef __LIBTRACKER_COMMON_TYPE_UTILS_H__ -#define __LIBTRACKER_COMMON_TYPE_UTILS_H__ - -#include - -G_BEGIN_DECLS - -#if !defined (__LIBTRACKER_COMMON_INSIDE__) && !defined (TRACKER_COMPILATION) -#error "only must be included directly." -#endif - -gint tracker_string_in_string_list (const gchar *str, - gchar **strv); -gboolean tracker_string_in_gslist (const gchar *str, - GSList *list); -GSList * tracker_string_list_to_gslist (gchar **strv, - gsize length); -gchar ** tracker_string_to_string_list (const gchar *str); -gchar ** tracker_gslist_to_string_list (GSList *list); -gchar ** tracker_glist_to_string_list (GList *list); -gboolean tracker_gslist_with_string_data_equal (GSList *list1, - GSList *list2); -GSList * tracker_gslist_copy_with_string_data (GSList *list); - -G_END_DECLS - -#endif /* __LIBTRACKER_COMMON_TYPE_UTILS_H__ */ diff --git a/tests/libtracker-common/.gitignore b/tests/libtracker-common/.gitignore index 6e6fae69c..b2a0e1b03 100644 --- a/tests/libtracker-common/.gitignore +++ b/tests/libtracker-common/.gitignore @@ -6,7 +6,6 @@ tracker-dbus tracker-file-utils tracker-ontology tracker-thumbnailer -tracker-type-utils tracker-utils tracker-date-time-test tracker-media-art-test diff --git a/tests/libtracker-common/meson.build b/tests/libtracker-common/meson.build index 7ad0f20ad..a748e57f1 100644 --- a/tests/libtracker-common/meson.build +++ b/tests/libtracker-common/meson.build @@ -1,7 +1,6 @@ libtracker_common_tests = [ 'date-time', 'file-utils', - 'type-utils', 'utils', ] diff --git a/tests/libtracker-common/tracker-type-utils-test.c b/tests/libtracker-common/tracker-type-utils-test.c deleted file mode 100644 index 7508efd2e..000000000 --- a/tests/libtracker-common/tracker-type-utils-test.c +++ /dev/null @@ -1,217 +0,0 @@ -/* - * Copyright (C) 2008, Nokia - * - * This library 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 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 - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include -#include - -#include - -#include - -static void -test_string_in_string_list_failures_subprocess (void) -{ - const gchar *complete = "This is an extract of text with different terms an props like Audio:Title ..."; - gchar **pieces; - - pieces = g_strsplit (complete, " ", -1); - - g_assert_cmpint (tracker_string_in_string_list (NULL, pieces), ==, -1); - - g_strfreev (pieces); -} - -static void -test_string_in_string_list_failures (void) -{ - - g_test_trap_subprocess ("/libtracker-common/tracker-type-utils/string_in_string_list_failures/subprocess", 0, 0); - g_test_trap_assert_failed (); - g_test_trap_assert_stderr ("*assertion 'str != NULL' failed*"); -} - -static void -test_string_in_string_list (void) -{ - const gchar *complete = "This is an extract of text with different terms an props like Audio:Title ..."; - gchar **pieces; - - pieces = g_strsplit (complete, " ", -1); - - g_assert_cmpint (tracker_string_in_string_list ("is", pieces), ==, 1); - g_assert_cmpint (tracker_string_in_string_list ("Audio:Title", pieces), ==, 12); - g_strfreev (pieces); - - g_assert_cmpint (tracker_string_in_string_list ("terms", NULL), ==, -1); -} - -static void -test_string_in_gslist (void) -{ - GSList *input = NULL; - - input = g_slist_prepend (input, g_strdup ("one")); - input = g_slist_prepend (input, g_strdup ("two")); - input = g_slist_prepend (input, g_strdup ("three")); - input = g_slist_prepend (input, g_strdup ("four")); - - g_assert_true (tracker_string_in_gslist ("one", input)); - g_assert_true (tracker_string_in_gslist ("two", input)); - g_assert_true (tracker_string_in_gslist ("three", input)); - g_assert_true (tracker_string_in_gslist ("four", input)); - g_assert_true (!tracker_string_in_gslist ("five", input)); - - g_slist_foreach (input, (GFunc)g_free, NULL); - g_slist_free (input); -} - -static void -test_gslist_to_string_list (void) -{ - GSList *input = NULL; - gchar **result; - - input = g_slist_prepend (input, (gpointer) "four"); - input = g_slist_prepend (input, (gpointer) "three"); - input = g_slist_prepend (input, (gpointer) "two"); - input = g_slist_prepend (input, (gpointer) "one"); - - result = tracker_gslist_to_string_list (input); - - g_assert_cmpstr (result[0], ==, "one"); - g_assert_cmpstr (result[1], ==, "two"); - g_assert_cmpstr (result[2], ==, "three"); - g_assert_cmpstr (result[3], ==, "four"); - - g_strfreev (result); - - result = tracker_gslist_to_string_list (NULL); - g_assert_true (result != NULL); - g_strfreev (result); -} - -static void -test_string_list_to_gslist (void) -{ - const gchar *input [] = {"one", "two", "three", "four", NULL}; - GSList *result = NULL; - - result = tracker_string_list_to_gslist ((gchar **)input, -1); - g_assert_true (result); - g_assert_cmpint (g_slist_length (result), ==, 4); - - /* This function is tested in other test, so it should work or fail there also */ - g_assert_true (tracker_string_in_gslist ("one", result)); - g_assert_true (tracker_string_in_gslist ("two", result)); - g_assert_true (tracker_string_in_gslist ("three", result)); - g_assert_true (tracker_string_in_gslist ("four", result)); - - g_slist_foreach (result, (GFunc)g_free, NULL); - g_slist_free (result); - - result = tracker_string_list_to_gslist ((gchar **)input, 2); - g_assert_true (result); - g_assert_cmpint (g_slist_length (result), ==, 2); - - g_assert_true (tracker_string_in_gslist ("one", result)); - g_assert_true (tracker_string_in_gslist ("two", result)); - g_assert_true (!tracker_string_in_gslist ("three", result)); - g_assert_true (!tracker_string_in_gslist ("four", result)); -} - -static void -test_string_to_string_list (void) -{ - const gchar *input = "first line"; - gchar **result; - - result = tracker_string_to_string_list (input); - g_assert_cmpint (g_strv_length (result), ==, 1); - g_assert_cmpstr (result [0], ==, "first line"); - g_strfreev (result); -} - -static void -test_gslist_with_string_data_equal (void) -{ - GSList *list1 = NULL; - GSList *list2 = NULL; - GSList *shorty = NULL; - GSList *list3 = NULL; - - list1 = g_slist_prepend (list1, g_strdup ("one")); - list1 = g_slist_prepend (list1, g_strdup ("two")); - list1 = g_slist_prepend (list1, g_strdup ("three")); - - g_assert_true (tracker_gslist_with_string_data_equal (list1, list1)); - - shorty = g_slist_prepend (shorty, g_strdup ("one")); - g_assert_true (!tracker_gslist_with_string_data_equal (list1, shorty)); - g_assert_true (!tracker_gslist_with_string_data_equal (shorty, list1)); - - list2 = g_slist_prepend (list2, g_strdup ("one")); - list2 = g_slist_prepend (list2, g_strdup ("two")); - list2 = g_slist_prepend (list2, g_strdup ("three")); - g_assert_true (tracker_gslist_with_string_data_equal (list1, list2)); - g_assert_true (tracker_gslist_with_string_data_equal (list2, list1)); - - list3 = g_slist_prepend (list3, g_strdup ("one")); - list3 = g_slist_prepend (list3, g_strdup ("something different")); - list3 = g_slist_prepend (list3, g_strdup ("three")); - g_assert_true (!tracker_gslist_with_string_data_equal (list1, list3)); - g_assert_true (!tracker_gslist_with_string_data_equal (list3, list1)); - - g_slist_foreach (list1, (GFunc)g_free, NULL); - g_slist_foreach (list2, (GFunc)g_free, NULL); - g_slist_foreach (shorty, (GFunc)g_free, NULL); - g_slist_foreach (list3, (GFunc)g_free, NULL); - - g_slist_free (list1); - g_slist_free (list2); - g_slist_free (shorty); - g_slist_free (list3); -} - -int -main (int argc, char **argv) -{ - gint result; - - g_test_init (&argc, &argv, NULL); - - g_test_add_func ("/libtracker-common/tracker-type-utils/string_list_as_list", - test_string_to_string_list); - g_test_add_func ("/libtracker-common/tracker-type-utils/gslist_to_string_list", - test_gslist_to_string_list); - g_test_add_func ("/libtracker-common/tracker-type-utils/string_in_string_list", - test_string_in_string_list); - g_test_add_func ("/libtracker-common/tracker-type-utils/string_in_string_list_failures", - test_string_in_string_list_failures); - g_test_add_func ("/libtracker-common/tracker-type-utils/string_in_string_list_failures/subprocess", - test_string_in_string_list_failures_subprocess); - g_test_add_func ("/libtracker-common/tracker-type-utils/string_in_gslist", - test_string_in_gslist); - g_test_add_func ("/libtracker-common/tracker-type-utils/string_list_to_gslist", - test_string_list_to_gslist); - g_test_add_func ("/libtracker-common/tracker-type-utils/gslist_with_string_data_equal", - test_gslist_with_string_data_equal); - result = g_test_run (); - - return result; -} -- cgit v1.2.1