summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Thursfield <sam@afuera.me.uk>2020-09-16 11:28:05 +0000
committerSam Thursfield <sam@afuera.me.uk>2020-09-16 11:28:05 +0000
commitc45541690738b8b12db9b7679b0690b139a7d35a (patch)
tree88d6fec228919e96fa97c70d5b735927453bc42c
parent6c02592fdded3b18bcbdf79bedd3b9a8331c0d12 (diff)
parent419b11611723f08b17557eead4ef22eccc38fbff (diff)
downloadtracker-c45541690738b8b12db9b7679b0690b139a7d35a.tar.gz
Merge branch 'wip/carlosg/libtracker-common-cleanup' into 'master'
Clean up libtracker-common See merge request GNOME/tracker!313
-rw-r--r--src/libtracker-common/meson.build1
-rw-r--r--src/libtracker-common/tracker-common.h1
-rw-r--r--src/libtracker-common/tracker-date-time.c25
-rw-r--r--src/libtracker-common/tracker-date-time.h2
-rw-r--r--src/libtracker-common/tracker-file-utils.c577
-rw-r--r--src/libtracker-common/tracker-file-utils.h23
-rw-r--r--src/libtracker-common/tracker-type-utils.c218
-rw-r--r--src/libtracker-common/tracker-type-utils.h47
-rw-r--r--src/libtracker-common/tracker-utils.c133
-rw-r--r--src/libtracker-common/tracker-utils.h11
-rw-r--r--src/libtracker-fts/tracker-fts.c20
-rw-r--r--tests/libtracker-common/.gitignore1
-rw-r--r--tests/libtracker-common/meson.build1
-rw-r--r--tests/libtracker-common/tracker-date-time-test.c32
-rw-r--r--tests/libtracker-common/tracker-file-utils-test.c351
-rw-r--r--tests/libtracker-common/tracker-type-utils-test.c217
-rw-r--r--tests/libtracker-common/tracker-utils-test.c99
17 files changed, 14 insertions, 1745 deletions
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..03ee078d5 100644
--- a/src/libtracker-common/tracker-date-time.c
+++ b/src/libtracker-common/tracker-date-time.c
@@ -34,7 +34,6 @@
#include <glib.h>
#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");
@@ -350,27 +349,3 @@ tracker_date_time_get_offset (const GValue *value)
/* UTC offset */
return value->data[1].v_int;
}
-
-gint
-tracker_date_time_get_local_date (const GValue *value)
-{
- gdouble local_timestamp;
-
- g_return_val_if_fail (G_VALUE_HOLDS (value, TRACKER_TYPE_DATE_TIME), 0);
-
- /* return number of days since epoch */
- local_timestamp = tracker_date_time_get_time (value) + tracker_date_time_get_offset (value);
- return (gint) (local_timestamp / 3600 / 24);
-}
-
-gint
-tracker_date_time_get_local_time (const GValue *value)
-{
- gdouble local_timestamp;
-
- g_return_val_if_fail (G_VALUE_HOLDS (value, TRACKER_TYPE_DATE_TIME), 0);
-
- /* return local time of day */
- local_timestamp = tracker_date_time_get_time (value) + tracker_date_time_get_offset (value);
- return (int) local_timestamp % (24 * 3600);
-}
diff --git a/src/libtracker-common/tracker-date-time.h b/src/libtracker-common/tracker-date-time.h
index df949e90e..cd3111b49 100644
--- a/src/libtracker-common/tracker-date-time.h
+++ b/src/libtracker-common/tracker-date-time.h
@@ -51,8 +51,6 @@ void tracker_date_time_set_from_string (GValue *value,
GError **error);
gdouble tracker_date_time_get_time (const GValue *value);
gint tracker_date_time_get_offset (const GValue *value);
-gint tracker_date_time_get_local_date (const GValue *value);
-gint tracker_date_time_get_local_time (const GValue *value);
gdouble tracker_string_to_date (const gchar *date_string,
gint *offset,
diff --git a/src/libtracker-common/tracker-file-utils.c b/src/libtracker-common/tracker-file-utils.c
index 1962a23d2..9994a079b 100644
--- a/src/libtracker-common/tracker-file-utils.c
+++ b/src/libtracker-common/tracker-file-utils.c
@@ -39,68 +39,9 @@
#include <gio/gio.h>
#include "tracker-file-utils.h"
-#include "tracker-type-utils.h"
#define TEXT_SNIFF_SIZE 4096
-int
-tracker_file_open_fd (const gchar *path)
-{
- int fd;
-
- g_return_val_if_fail (path != NULL, -1);
-
-#if defined(__linux__)
- fd = g_open (path, O_RDONLY | O_NOATIME, 0);
- if (fd == -1 && errno == EPERM) {
- fd = g_open (path, O_RDONLY, 0);
- }
-#else
- fd = g_open (path, O_RDONLY, 0);
-#endif
-
- return fd;
-}
-
-FILE *
-tracker_file_open (const gchar *path)
-{
- FILE *file;
- int fd;
-
- g_return_val_if_fail (path != NULL, NULL);
-
- fd = tracker_file_open_fd (path);
-
- if (fd == -1) {
- return NULL;
- }
-
- file = fdopen (fd, "r");
-
- if (!file) {
- return NULL;
- }
-
- return file;
-}
-
-void
-tracker_file_close (FILE *file,
- gboolean need_again_soon)
-{
- g_return_if_fail (file != NULL);
-
-#ifdef HAVE_POSIX_FADVISE
- if (!need_again_soon) {
- if (posix_fadvise (fileno (file), 0, 0, POSIX_FADV_DONTNEED) != 0)
- g_warning ("posix_fadvise() call failed: %m");
- }
-#endif /* HAVE_POSIX_FADVISE */
-
- fclose (file);
-}
-
goffset
tracker_file_get_size (const gchar *path)
{
@@ -138,106 +79,6 @@ tracker_file_get_size (const gchar *path)
return size;
}
-static
-guint64
-file_get_mtime (GFile *file)
-{
- GFileInfo *info;
- GError *error = NULL;
- guint64 mtime;
-
- info = g_file_query_info (file,
- G_FILE_ATTRIBUTE_TIME_MODIFIED,
- G_FILE_QUERY_INFO_NONE,
- NULL,
- &error);
-
- if (G_UNLIKELY (error)) {
- gchar *uri;
-
- uri = g_file_get_uri (file);
- g_message ("Could not get mtime for '%s': %s",
- uri,
- error->message);
- g_free (uri);
- g_error_free (error);
- mtime = 0;
- } else {
- mtime = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
- g_object_unref (info);
- }
-
- return mtime;
-}
-
-guint64
-tracker_file_get_mtime (const gchar *path)
-{
- GFile *file;
- guint64 mtime;
-
- g_return_val_if_fail (path != NULL, 0);
-
- file = g_file_new_for_path (path);
-
- mtime = file_get_mtime (file);
-
- g_object_unref (file);
-
- return mtime;
-}
-
-
-guint64
-tracker_file_get_mtime_uri (const gchar *uri)
-{
- GFile *file;
- guint64 mtime;
-
- g_return_val_if_fail (uri != NULL, 0);
-
- file = g_file_new_for_uri (uri);
-
- mtime = file_get_mtime (file);
-
- g_object_unref (file);
-
- return mtime;
-}
-
-gchar *
-tracker_file_get_mime_type (GFile *file)
-{
- GFileInfo *info;
- GError *error = NULL;
- gchar *content_type;
-
- g_return_val_if_fail (G_IS_FILE (file), NULL);
-
- info = g_file_query_info (file,
- G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
- G_FILE_QUERY_INFO_NONE,
- NULL,
- &error);
-
- if (G_UNLIKELY (error)) {
- gchar *uri;
-
- uri = g_file_get_uri (file);
- g_message ("Could not guess mimetype for '%s', %s",
- uri,
- error->message);
- g_free (uri);
- g_error_free (error);
- content_type = NULL;
- } else {
- content_type = g_strdup (g_file_info_get_content_type (info));
- g_object_unref (info);
- }
-
- return content_type ? content_type : g_strdup ("unknown");
-}
-
#ifdef __linux__
#define __bsize f_bsize
@@ -290,7 +131,7 @@ statvfs_helper (const gchar *path, struct __statvfs *st)
return (retval == 0);
}
-guint64
+static guint64
tracker_file_system_get_remaining_space (const gchar *path)
{
struct __statvfs st;
@@ -305,20 +146,6 @@ tracker_file_system_get_remaining_space (const gchar *path)
}
}
-gdouble
-tracker_file_system_get_remaining_space_percentage (const gchar *path)
-{
- struct __statvfs st;
- guint64 available;
-
- if (statvfs_helper (path, &st)) {
- available = (geteuid () == 0) ? st.f_bfree : st.f_bavail;
- return (((gdouble) available * 100) / st.f_blocks);
- } else {
- return 0.0;
- }
-}
-
gboolean
tracker_file_system_has_enough_space (const gchar *path,
gulong required_bytes,
@@ -356,405 +183,3 @@ tracker_file_system_has_enough_space (const gchar *path,
return enough;
}
-
-gboolean
-tracker_path_is_in_path (const gchar *path,
- const gchar *in_path)
-{
- gchar *new_path;
- gchar *new_in_path;
- gboolean is_in_path = FALSE;
-
- g_return_val_if_fail (path != NULL, FALSE);
- g_return_val_if_fail (in_path != NULL, FALSE);
-
- if (!g_str_has_suffix (path, G_DIR_SEPARATOR_S)) {
- new_path = g_strconcat (path, G_DIR_SEPARATOR_S, NULL);
- } else {
- new_path = g_strdup (path);
- }
-
- if (!g_str_has_suffix (in_path, G_DIR_SEPARATOR_S)) {
- new_in_path = g_strconcat (in_path, G_DIR_SEPARATOR_S, NULL);
- } else {
- new_in_path = g_strdup (in_path);
- }
-
- if (g_str_has_prefix (new_path, new_in_path)) {
- is_in_path = TRUE;
- }
-
- g_free (new_in_path);
- g_free (new_path);
-
- return is_in_path;
-}
-
-GSList *
-tracker_path_list_filter_duplicates (GSList *roots,
- const gchar *basename_exception_prefix,
- gboolean is_recursive)
-{
- GSList *l1, *l2;
- GSList *new_list;
-
- new_list = tracker_gslist_copy_with_string_data (roots);
- l1 = new_list;
-
- while (l1) {
- const gchar *path;
- gchar *p;
- gboolean reset = FALSE;
-
- path = l1->data;
-
- l2 = new_list;
-
- while (l2 && !reset) {
- const gchar *in_path;
-
- in_path = l2->data;
-
- if (path == in_path) {
- /* Do nothing */
- l2 = l2->next;
- continue;
- }
-
- if (basename_exception_prefix) {
- gchar *lbasename;
- gboolean has_prefix = FALSE;
-
- lbasename = g_path_get_basename (path);
- if (!g_str_has_prefix (lbasename, basename_exception_prefix)) {
- g_free (lbasename);
-
- lbasename = g_path_get_basename (in_path);
- if (g_str_has_prefix (lbasename, basename_exception_prefix)) {
- has_prefix = TRUE;
- }
- } else {
- has_prefix = TRUE;
- }
-
- g_free (lbasename);
-
- /* This is so we can ignore this check
- * on files which prefix with ".".
- */
- if (has_prefix) {
- l2 = l2->next;
- continue;
- }
- }
-
- if (is_recursive && tracker_path_is_in_path (path, in_path)) {
- g_debug ("Removing path:'%s', it is in path:'%s'",
- path, in_path);
-
- g_free (l1->data);
- new_list = g_slist_delete_link (new_list, l1);
- l1 = new_list;
-
- reset = TRUE;
-
- continue;
- } else if (is_recursive && tracker_path_is_in_path (in_path, path)) {
- g_debug ("Removing path:'%s', it is in path:'%s'",
- in_path, path);
-
- g_free (l2->data);
- new_list = g_slist_delete_link (new_list, l2);
- l2 = new_list;
-
- reset = TRUE;
-
- continue;
- }
-
- l2 = l2->next;
- }
-
- if (G_LIKELY (!reset)) {
- p = strrchr (path, G_DIR_SEPARATOR);
-
- /* Make sure the path doesn't have the '/' suffix. */
- if (p && !p[1]) {
- *p = '\0';
- }
-
- l1 = l1->next;
- }
- }
-
-#ifdef TESTING
- g_debug ("GSList paths were filtered down to:");
-
- if (TRUE) {
- GSList *l;
-
- for (l = new_list; l; l = l->next) {
- g_debug (" %s", (gchar*) l->data);
- }
- }
-#endif /* TESTING */
-
- return new_list;
-}
-
-const struct {
- const gchar *symbol;
- GUserDirectory user_dir;
-} special_dirs[] = {
- {"&DESKTOP", G_USER_DIRECTORY_DESKTOP},
- {"&DOCUMENTS", G_USER_DIRECTORY_DOCUMENTS},
- {"&DOWNLOAD", G_USER_DIRECTORY_DOWNLOAD},
- {"&MUSIC", G_USER_DIRECTORY_MUSIC},
- {"&PICTURES", G_USER_DIRECTORY_PICTURES},
- {"&PUBLIC_SHARE", G_USER_DIRECTORY_PUBLIC_SHARE},
- {"&TEMPLATES", G_USER_DIRECTORY_TEMPLATES},
- {"&VIDEOS", G_USER_DIRECTORY_VIDEOS}
-};
-
-
-static gboolean
-get_user_special_dir_if_not_home (const gchar *path,
- gchar **special_dir)
-{
- int i;
- const gchar *real_path;
- GFile *home, *file;
-
- real_path = NULL;
- *special_dir = NULL;
-
- for (i = 0; i < G_N_ELEMENTS(special_dirs); i++) {
- if (strcmp (path, special_dirs[i].symbol) == 0) {
- real_path = g_get_user_special_dir (special_dirs[i].user_dir);
-
- if (real_path == NULL) {
- g_warning ("Unable to get XDG user directory path for special "
- "directory %s. Ignoring this location.", path);
- }
-
- break;
- }
- }
-
- if (real_path == NULL)
- return FALSE;
-
- file = g_file_new_for_path (real_path);
- home = g_file_new_for_path (g_get_home_dir ());
-
- /* ignore XDG directories set to $HOME */
- if (!g_file_equal (file, home)) {
- *special_dir = g_strdup (real_path);
- }
-
- g_object_unref (file);
- g_object_unref (home);
-
- return TRUE;
-}
-
-
-gchar *
-tracker_path_evaluate_name (const gchar *path)
-{
- gchar *special_dir_path;
- gchar *final_path;
- gchar **tokens;
- gchar **token;
- gchar *start;
- gchar *end;
- const gchar *env;
- gchar *expanded;
-
- if (!path || path[0] == '\0') {
- return NULL;
- }
-
- /* See if it is a special directory name. */
- if (get_user_special_dir_if_not_home (path, &special_dir_path))
- return special_dir_path;
-
- /* First check the simple case of using tilde */
- if (path[0] == '~') {
- const gchar *home;
-
- home = g_getenv ("HOME");
- if (! home) {
- home = g_get_home_dir ();
- }
-
- if (!home || home[0] == '\0') {
- return NULL;
- }
-
- return g_build_path (G_DIR_SEPARATOR_S,
- home,
- path + 1,
- NULL);
- }
-
- /* Second try to find any environment variables and expand
- * them, like $HOME or ${FOO}
- */
- tokens = g_strsplit (path, G_DIR_SEPARATOR_S, -1);
-
- for (token = tokens; *token; token++) {
- if (**token != '$') {
- continue;
- }
-
- start = *token + 1;
-
- if (*start == '{') {
- start++;
- end = start + (strlen (start)) - 1;
- *end='\0';
- }
-
- env = g_getenv (start);
- g_free (*token);
-
- /* Don't do g_strdup (s?s1:s2) as that doesn't work
- * with certain gcc 2.96 versions.
- */
- *token = env ? g_strdup (env) : g_strdup ("");
- }
-
- /* Third get the real path removing any "../" and other
- * symbolic links to other places, returning only the REAL
- * location.
- */
- expanded = g_strjoinv (G_DIR_SEPARATOR_S, tokens);
- g_strfreev (tokens);
-
- /* Only resolve relative paths if there is a directory
- * separator in the path, otherwise it is just a name.
- */
- if (strchr (expanded, G_DIR_SEPARATOR)) {
- GFile *file;
-
- file = g_file_new_for_commandline_arg (expanded);
- final_path = g_file_get_path (file);
- g_object_unref (file);
- g_free (expanded);
- } else {
- final_path = expanded;
- }
-
- return final_path;
-}
-
-gboolean
-tracker_file_is_hidden (GFile *file)
-{
- GFileInfo *file_info;
- gboolean is_hidden = FALSE;
-
- file_info = g_file_query_info (file,
- G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN,
- G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
- NULL, NULL);
- if (file_info) {
- /* Check if GIO says the file is hidden */
- is_hidden = g_file_info_get_is_hidden (file_info);
- g_object_unref (file_info);
- } else {
- gchar *basename;
-
- /* Resort last to basename checks, this might happen on
- * already deleted files.
- */
- basename = g_file_get_basename (file);
- is_hidden = basename[0] == '.';
- g_free (basename);
- }
-
- return is_hidden;
-}
-
-gint
-tracker_file_cmp (GFile *file_a,
- GFile *file_b)
-{
- /* Returns 0 if files are equal.
- * Useful to be used in g_list_find_custom() or g_queue_find_custom() */
- return !g_file_equal (file_a, file_b);
-}
-
-/**
- * tracker_filename_casecmp_without_extension:
- * @a: a string containing a file name
- * @b: filename to be compared with @a
- *
- * This function performs a case-insensitive comparison of @a and @b.
- * Additionally, text beyond the last '.' in a string is not considered
- * part of the match, so for example given the inputs "file.mp3" and
- * "file.wav" this function will return %TRUE.
- *
- * Internally, the g_ascii_tolower() function is used - this means that
- * @a and @b must be in an encoding in which ASCII characters always
- * represent themselves, such as UTF-8 or the ISO-8859-* charsets.
- *
- * Returns: %TRUE if the two file names match.
- **/
-gboolean
-tracker_filename_casecmp_without_extension (const gchar *a,
- const gchar *b)
-{
- gchar *pa;
- gchar *pb;
- gint len_a;
- gint len_b;
-
- g_return_val_if_fail (a != NULL, FALSE);
- g_return_val_if_fail (b != NULL, FALSE);
-
- pa = strrchr (a, '.');
- pb = strrchr (b, '.');
-
- /* Did we find a "." */
- if (pa) {
- len_a = pa - a;
- } else {
- len_a = -1;
- }
-
- if (pb) {
- len_b = pb - b;
- } else {
- len_b = -1;
- }
-
- /* If one has a "." and the other doesn't, we do length
- * comparison with strlen() which is less optimal but this is
- * not a case we consider common operation.
- */
- if (len_a == -1 && len_b > -1) {
- len_a = strlen (a);
- } else if (len_b == -1 && len_a > -1) {
- len_b = strlen (b);
- }
-
- /* If we have length for both and it's different then these
- * strings are not the same. If we have no length for the
- * strings then it's a simple -1 != -1 comparison.
- */
- if (len_a != len_b) {
- return FALSE;
- }
-
- /* Now we know we either have the same length string or no
- * extension in a and b, meaning it's a strcmp() of the
- * string only. We test only len_a or len_b here for that:
- */
- if (G_UNLIKELY (len_a == -1)) {
- return g_ascii_strcasecmp (a, b) == 0;
- }
-
- return g_ascii_strncasecmp (a, b, len_a) == 0;
-}
diff --git a/src/libtracker-common/tracker-file-utils.h b/src/libtracker-common/tracker-file-utils.h
index 45c5f9374..679a4543e 100644
--- a/src/libtracker-common/tracker-file-utils.h
+++ b/src/libtracker-common/tracker-file-utils.h
@@ -32,35 +32,12 @@ G_BEGIN_DECLS
#endif
/* File utils */
-int tracker_file_open_fd (const gchar *path);
-FILE* tracker_file_open (const gchar *path);
-void tracker_file_close (FILE *file,
- gboolean need_again_soon);
goffset tracker_file_get_size (const gchar *path);
-guint64 tracker_file_get_mtime (const gchar *path);
-guint64 tracker_file_get_mtime_uri (const gchar *uri);
-gchar * tracker_file_get_mime_type (GFile *file);
-gboolean tracker_file_is_locked (GFile *file);
-gboolean tracker_file_is_hidden (GFile *file);
-gint tracker_file_cmp (GFile *file_a,
- GFile *file_b);
-
-/* Path utils */
-gboolean tracker_path_is_in_path (const gchar *path,
- const gchar *in_path);
-GSList * tracker_path_list_filter_duplicates (GSList *roots,
- const gchar *basename_exception_prefix,
- gboolean is_recursive);
-gchar * tracker_path_evaluate_name (const gchar *uri);
-gboolean tracker_filename_casecmp_without_extension (const gchar *a,
- const gchar *b);
/* File system utils */
gboolean tracker_file_system_has_enough_space (const gchar *path,
gulong required_bytes,
gboolean creating_db);
-guint64 tracker_file_system_get_remaining_space (const gchar *path);
-gdouble tracker_file_system_get_remaining_space_percentage (const gchar *path);
G_END_DECLS
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 <jamiemcc@gnome.org>
- * Copyright (C) 2008, Nokia <ivan.frade@nokia.com>
- *
- * 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 <time.h>
-
-#include <strings.h>
-#include <string.h>
-#include <stdlib.h>
-
-#include <glib.h>
-
-#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 <jamiemcc@gnome.org>
- * Copyright (C) 2008, Nokia <ivan.frade@nokia.com>
- *
- * 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 <glib.h>
-
-G_BEGIN_DECLS
-
-#if !defined (__LIBTRACKER_COMMON_INSIDE__) && !defined (TRACKER_COMPILATION)
-#error "only <libtracker-common/tracker-common.h> 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/src/libtracker-common/tracker-utils.c b/src/libtracker-common/tracker-utils.c
index b5f22174d..3bcb5628f 100644
--- a/src/libtracker-common/tracker-utils.c
+++ b/src/libtracker-common/tracker-utils.c
@@ -29,139 +29,6 @@
#include "tracker-utils.h"
-inline gboolean
-tracker_is_empty_string (const char *str)
-{
- return str == NULL || str[0] == '\0';
-}
-
-inline gboolean
-tracker_is_blank_string (const char *str)
-{
- register const gchar *p;
-
- if (str == NULL || str[0] == '\0') {
- return TRUE;
- }
-
- for (p = str; *p; p = g_utf8_next_char (p)) {
- register gunichar c;
-
- c = g_utf8_get_char (p);
-
- if (!g_unichar_isspace (c)) {
- return FALSE;
- }
- }
-
- return TRUE;
-}
-
-guint
-tracker_seconds_estimate (gdouble seconds_elapsed,
- guint items_done,
- guint items_remaining)
-{
- /* Return 0 if unknown */
- if (seconds_elapsed <= 0 ||
- items_done < 1 ||
- items_remaining < 1) {
- return 0;
- }
-
- /* A estimate is an estimate, and full seconds is probably
- * more correct than a floating point value... */
- return (guint)((seconds_elapsed / items_done) * items_remaining);
-}
-
-gchar *
-tracker_seconds_estimate_to_string (gdouble seconds_elapsed,
- gboolean short_string,
- guint items_done,
- guint items_remaining)
-{
- guint estimate;
-
- estimate = tracker_seconds_estimate (seconds_elapsed,
- items_done,
- items_remaining);
-
- if (estimate == 0)
- return g_strdup (_("unknown time"));
-
- return tracker_seconds_to_string (estimate, short_string);
-}
-
-gchar *
-tracker_seconds_to_string (gdouble seconds_elapsed,
- gboolean short_string)
-{
- GString *s;
- gchar *str;
- gdouble total;
- gint days, hours, minutes, seconds;
-
- g_return_val_if_fail (seconds_elapsed >= 0.0, g_strdup (_("less than one second")));
-
- total = seconds_elapsed;
-
- seconds = (gint) total % 60;
- total /= 60;
- minutes = (gint) total % 60;
- total /= 60;
- hours = (gint) total % 24;
- days = (gint) total / 24;
-
- s = g_string_new ("");
-
- if (short_string) {
- if (days) { /* Translators: this is %d days */
- g_string_append_printf (s, _(" %dd"), days);
- }
-
- if (hours) { /* Translators: this is %2.2d hours */
- g_string_append_printf (s, _(" %2.2dh"), hours);
- }
-
- if (minutes) { /* Translators: this is %2.2d minutes */
- g_string_append_printf (s, _(" %2.2dm"), minutes);
- }
-
- if (seconds) { /* Translators: this is %2.2d seconds */
- g_string_append_printf (s, _(" %2.2ds"), seconds);
- }
- } else {
- if (days) {
- g_string_append_printf (s, ngettext (" %d day", " %d days", days), days);
- }
-
- if (hours) {
- g_string_append_printf (s, ngettext (" %2.2d hour", " %2.2d hours", hours), hours);
- }
-
- if (minutes) {
- g_string_append_printf (s, ngettext (" %2.2d minute", " %2.2d minutes", minutes), minutes);
- }
-
- if (seconds) {
- g_string_append_printf (s, ngettext (" %2.2d second", " %2.2d seconds", seconds), seconds);
- }
- }
-
- str = g_string_free (s, FALSE);
-
- if (str[0] == '\0') {
- g_free (str);
- str = g_strdup (_("less than one second"));
- } else {
- g_strchug (str);
- }
-
- return str;
-}
-
-
-
/**
* tracker_strhex:
* @data: The input array of bytes
diff --git a/src/libtracker-common/tracker-utils.h b/src/libtracker-common/tracker-utils.h
index 0b27b1643..1420ed4c0 100644
--- a/src/libtracker-common/tracker-utils.h
+++ b/src/libtracker-common/tracker-utils.h
@@ -30,17 +30,6 @@ G_BEGIN_DECLS
#error "only <libtracker-common/tracker-common.h> must be included directly."
#endif
-gboolean tracker_is_empty_string (const char *str);
-gboolean tracker_is_blank_string (const char *str);
-guint tracker_seconds_estimate (gdouble seconds_elapsed,
- guint items_done,
- guint items_remaining);
-gchar * tracker_seconds_estimate_to_string (gdouble seconds_elapsed,
- gboolean short_string,
- guint items_done,
- guint items_remaining);
-gchar * tracker_seconds_to_string (gdouble seconds,
- gboolean short_string);
gchar * tracker_strhex (const guint8 *data,
gsize size,
gchar delimiter);
diff --git a/src/libtracker-fts/tracker-fts.c b/src/libtracker-fts/tracker-fts.c
index 079d83a3c..1cb5041fe 100644
--- a/src/libtracker-fts/tracker-fts.c
+++ b/src/libtracker-fts/tracker-fts.c
@@ -38,24 +38,30 @@ int sqlite3_fts5_init ();
static gchar **
get_fts_properties (GHashTable *tables)
{
- GList *table_columns, *columns;
- gchar **property_names;
+ GList *table_columns;
+ GArray *property_names;
GList *keys, *l;
- columns = NULL;
keys = g_hash_table_get_keys (tables);
keys = g_list_sort (keys, (GCompareFunc) strcmp);
+ property_names = g_array_new (TRUE, FALSE, sizeof (gchar *));
+
for (l = keys; l; l = l->next) {
table_columns = g_hash_table_lookup (tables, l->data);
- columns = g_list_concat (columns, g_list_copy (table_columns));
+
+ while (table_columns) {
+ gchar *str;
+
+ str = g_strdup (table_columns->data);
+ g_array_append_val (property_names, str);
+ table_columns = table_columns->next;
+ }
}
- property_names = tracker_glist_to_string_list (columns);
- g_list_free (columns);
g_list_free (keys);
- return property_names;
+ return (gchar **) g_array_free (property_names, FALSE);
}
gboolean
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-date-time-test.c b/tests/libtracker-common/tracker-date-time-test.c
index 268cac58a..888269120 100644
--- a/tests/libtracker-common/tracker-date-time-test.c
+++ b/tests/libtracker-common/tracker-date-time-test.c
@@ -229,34 +229,6 @@ test_date_time_from_string ()
}
static void
-test_date_time_get_local_date ()
-{
- GValue value = G_VALUE_INIT;
- GError *error = NULL;
-
- g_value_init (&value, TRACKER_TYPE_DATE_TIME);
-
- tracker_date_time_set_from_string (&value, "2011-10-28T17:43:00+03:00", &error);
- g_assert_true (!error);
-
- g_assert_cmpint (tracker_date_time_get_local_date (&value), ==, 15275);
-}
-
-static void
-test_date_time_get_local_time ()
-{
- GValue value = G_VALUE_INIT;
- GError *error = NULL;
-
- g_value_init (&value, TRACKER_TYPE_DATE_TIME);
-
- tracker_date_time_set_from_string (&value, "2011-10-28T17:43:00+03:00", &error);
- g_assert_true (!error);
-
- g_assert_cmpint (tracker_date_time_get_local_time (&value), ==, 63780);
-}
-
-static void
test_date_time_conversions (void)
{
GError *error = NULL;
@@ -295,10 +267,6 @@ main (gint argc, gchar **argv)
test_date_time_get_set);
g_test_add_func ("/libtracker-common/date-time/from_string",
test_date_time_from_string);
- g_test_add_func ("/libtracker-common/date-time/get_local_date",
- test_date_time_get_local_date);
- g_test_add_func ("/libtracker-common/date-time/get_local_time",
- test_date_time_get_local_time);
g_test_add_func ("/libtracker-common/date-time/conversions",
test_date_time_conversions);
diff --git a/tests/libtracker-common/tracker-file-utils-test.c b/tests/libtracker-common/tracker-file-utils-test.c
index a508386fb..1286aa6e8 100644
--- a/tests/libtracker-common/tracker-file-utils-test.c
+++ b/tests/libtracker-common/tracker-file-utils-test.c
@@ -50,251 +50,6 @@ remove_file (const gchar *filename)
g_assert_cmpint (g_remove (filename), ==, 0);
}
-static GSList *
-array_as_list (const gchar **array)
-{
- gint i;
- GSList *result = NULL;
-
- for (i = 0; array[i] != NULL; i++) {
- result = g_slist_prepend (result, g_strdup(array[i]));
-
- }
-
- return result;
-}
-
-static gboolean
-string_in_list (GSList *list, const gchar *string)
-{
- GSList *it;
- for ( it = list; it != NULL; it = it->next) {
- if (strcmp (it->data, string) == 0) {
- return TRUE;
- }
- }
- return FALSE;
-}
-
-static void
-test_path_list_filter_duplicates (void)
-{
- const gchar *input_roots [] = {"/home/ivan",
- "/home",
- "/tmp",
- "/usr/",
- "/usr/share/local", NULL};
-
- GSList *input_as_list = NULL;
- GSList *result;
-
- input_as_list = array_as_list (input_roots);
-
- result = tracker_path_list_filter_duplicates (input_as_list, ".", TRUE);
- g_assert_cmpint (3, ==, g_slist_length (result));
-
- g_assert_true (string_in_list (result, "/home"));
- g_assert_true (string_in_list (result, "/tmp"));
- g_assert_true (string_in_list (result, "/usr"));
-
- g_slist_foreach (input_as_list, (GFunc) g_free, NULL);
- g_slist_foreach (result, (GFunc) g_free, NULL);
-}
-
-static void
-test_path_list_filter_duplicates_with_exceptions ()
-{
- const gchar *input_roots [] = { "/home/user/MyDocs",
- "/home/user/MyDocs/.sounds",
- "/home/user/MyDocs/visible",
- NULL};
- GSList *input_as_list = NULL, *result = NULL;
-
- input_as_list = array_as_list (input_roots);
-
- result = tracker_path_list_filter_duplicates (input_as_list, "/home/user/MyDocs", FALSE);
- g_assert_cmpint (g_slist_length (result), ==, 3);
- g_assert_true (string_in_list (result, "/home/user/MyDocs"));
- g_assert_true (string_in_list (result, "/home/user/MyDocs/.sounds"));
- g_assert_true (string_in_list (result, "/home/user/MyDocs/visible"));
- g_slist_foreach (result, (GFunc) g_free, NULL);
-
-
- result = tracker_path_list_filter_duplicates (input_as_list, "/home/user/MyDocs", TRUE);
- g_assert_cmpint (g_slist_length (result), ==, 1);
- g_assert_true (string_in_list (result, "/home/user/MyDocs"));
- g_slist_foreach (result, (GFunc) g_free, NULL);
-
- g_slist_foreach (input_as_list, (GFunc) g_free, NULL);
-}
-
-static void
-test_path_evaluate_name (void)
-{
- gchar *result, *expected, *pwd, *home;
-
-
- const gchar *test = "/one/two";
- gchar *parent_dir;
-
- home = g_strdup (g_getenv ("HOME"));
- pwd = g_get_current_dir ();
- g_setenv ("TEST_TRACKER_DIR", test, TRUE);
-
-
- result = tracker_path_evaluate_name ("/home/user/all/ok");
- g_assert_cmpstr (result, ==, "/home/user/all/ok");
- g_free (result);
-
- /* The result of this test and the next one are not consistent!
- * Must it remove the end '/' or not?
- */
- result = tracker_path_evaluate_name ("/home/user/all/dir/");
- g_assert_cmpstr (result, ==, "/home/user/all/dir");
- g_free (result);
-
-
- /*
- * TODO: In valgrind this test shows a memory leak
- */
- result = tracker_path_evaluate_name ("~/all/dir/");
- expected = g_build_path (G_DIR_SEPARATOR_S, home, "/all/dir/", NULL);
- g_assert_cmpstr (result, ==, expected);
- g_free (result);
- g_free (expected);
-
- result = tracker_path_evaluate_name ("just-a-filename");
- g_assert_cmpstr (result, ==, "just-a-filename");
- g_free (result);
-
- result = tracker_path_evaluate_name ("$HOME/all/dir/");
- expected = g_build_path (G_DIR_SEPARATOR_S, home, "/all/dir", NULL);
- g_assert_cmpstr (result, ==, expected);
- g_free (result);
- g_free (expected);
-
- result = tracker_path_evaluate_name ("${HOME}/all/dir/");
- expected = g_build_path (G_DIR_SEPARATOR_S, home, "/all/dir", NULL);
- g_assert_cmpstr (result, ==, expected);
- g_free (result);
- g_free (expected);
-
- result = tracker_path_evaluate_name ("./test/current/dir");
- expected = g_build_path (G_DIR_SEPARATOR_S, pwd, "/test/current/dir", NULL);
- g_assert_cmpstr (result, ==, expected);
- g_free (result);
- g_free (expected);
-
- result = tracker_path_evaluate_name ("$TEST_TRACKER_DIR/test/dir");
- expected = g_build_path (G_DIR_SEPARATOR_S, test, "/test/dir", NULL);
- g_assert_cmpstr (result, ==, expected);
- g_free (result);
- g_free (expected);
-
- result = tracker_path_evaluate_name ("../test/dir");
- parent_dir = g_path_get_dirname (pwd);
- expected = g_build_path (G_DIR_SEPARATOR_S, parent_dir, "/test/dir", NULL);
- g_assert_cmpstr (result, ==, expected);
- g_free (result);
- g_free (parent_dir);
- g_free (expected);
-
- result = tracker_path_evaluate_name ("");
- g_assert_true (!result);
- g_free (result);
-
- result = tracker_path_evaluate_name (NULL);
- g_assert_true (!result);
- g_free (result);
-
- g_setenv ("HOME", "", TRUE);
- result = tracker_path_evaluate_name ("~/but-no-home.txt");
- g_assert_true (!result);
- g_free (result);
- g_setenv ("HOME", home, TRUE);
-
- result = tracker_path_evaluate_name ("$UNDEFINED/something");
- g_assert_cmpstr (result, ==, "/something");
- g_free (result);
-
- result = tracker_path_evaluate_name (tracker_test_helpers_get_nonutf8 ());
- g_assert_cmpstr (result, ==, tracker_test_helpers_get_nonutf8 ());
- g_free (result);
-
- g_free (home);
- g_free (pwd);
- g_unsetenv ("TEST_TRACKER_DIR");
-}
-
-
-static void
-test_file_get_mime_type (void)
-{
- gchar *result;
- GFile *f;
-
- f = g_file_new_for_path (TEST_FILENAME);
- result = tracker_file_get_mime_type (f);
- g_assert_true (g_strcmp0 (result, "text/plain") == 0 ||
- g_strcmp0 (result, "application/x-zerosize") == 0);
-
- g_object_unref (f);
- g_free (result);
-
- f = g_file_new_for_path ("./file-does-NOT-exist");
- result = tracker_file_get_mime_type (f);
- g_assert_cmpstr (result, ==, "unknown");
-
- g_object_unref (f);
- g_free (result);
-
-}
-
-#define assert_filename_match(a, b) { \
- g_assert_cmpint (tracker_filename_casecmp_without_extension (a, b), ==, TRUE); \
- g_assert_cmpint (tracker_filename_casecmp_without_extension (b, a), ==, TRUE); }
-
-#define assert_no_filename_match(a, b) { \
- g_assert_cmpint (tracker_filename_casecmp_without_extension (a, b), ==, FALSE); \
- g_assert_cmpint (tracker_filename_casecmp_without_extension (b, a), ==, FALSE); }
-
-static void
-test_case_match_filename_without_extension ()
-{
- assert_filename_match ("test.mp3", "test.mp3");
- assert_filename_match ("test.mp3", "test.wav");
- assert_filename_match ("test.mp3", "test.mp");
- assert_filename_match ("test.mp3", "test.");
- assert_filename_match ("test.mp3", "test");
- assert_filename_match ("01 - Song 1 (Remix).wav", "01 - Song 1 (Remix).flac");
-
- assert_no_filename_match ("test.mp3", "bacon.mp3");
-
- /* Pathological cases, mainly testing that nothing crashes */
- assert_no_filename_match (".", "\n");
- assert_no_filename_match ("as", "as..");
- assert_no_filename_match ("...as", "...as..");
- assert_no_filename_match (".", "test.");
- assert_filename_match ("", ".");
-}
-
-static void
-test_file_utils_open_close ()
-{
- FILE *f;
-
- f = tracker_file_open (TEST_FILENAME);
- g_assert_true (f);
- tracker_file_close (f, TRUE);
-
- f = tracker_file_open (TEST_FILENAME);
- g_assert_true (f);
- tracker_file_close (f, FALSE);
-
- f = tracker_file_open ("./file-does-NOT-exist");
- g_assert_null (f);
-}
-
static void
test_file_utils_get_size ()
{
@@ -313,58 +68,6 @@ test_file_utils_get_size ()
}
static void
-test_file_utils_get_mtime ()
-{
- guint64 mtime;
- struct stat st;
- gchar *pwd, *uri;
-
- mtime = tracker_file_get_mtime (TEST_FILENAME);
- g_assert_cmpint (mtime, >, 0);
-
- g_assert_cmpint (stat (TEST_FILENAME, &st), ==, 0);
- // This comparison could lead a problem in 32/64 bits?
- g_assert_cmpint (mtime, ==, st.st_mtime);
-
- pwd = g_get_current_dir ();
- uri = g_strdup_printf ("file://%s/%s", pwd, TEST_FILENAME);
- mtime = tracker_file_get_mtime_uri (uri);
- // This comparison could lead a problem in 32/64 bits?
- g_assert_cmpint (mtime, ==, st.st_mtime);
-
- g_free (pwd);
- g_free (uri);
-
- mtime = tracker_file_get_mtime_uri ("./file-does-NOT-exist");
- g_assert_cmpint (mtime, ==, 0);
-}
-
-static void
-test_file_system_get_remaining_space ()
-{
- guint64 space;
-
- space = tracker_file_system_get_remaining_space ("/home");
- g_assert_cmpint (space, >, 0);
-
- // This is a critical (aborts the process)
- //space = tracker_file_system_get_remaining_space ("/unlikely/to/have/this/folder");
-}
-
-static void
-test_file_system_get_remaining_space_percentage ()
-{
- gdouble space;
-
- space = tracker_file_system_get_remaining_space_percentage ("/home");
- g_assert_cmpfloat (space, >=, 0);
- g_assert_cmpfloat (space, <=, 100);
-
- // This is a critical (aborts the process)
- //space = tracker_file_system_get_remaining_space_percentage ("/unlikely/to/have/this/folder");
-}
-
-static void
test_file_system_has_enough_space ()
{
/* Hopefully we will always have 1 byte free... */
@@ -375,37 +78,6 @@ test_file_system_has_enough_space ()
//g_assert_true (!tracker_file_system_has_enough_space ("/home", G_MAXULONG, FALSE));
}
-static void
-test_file_utils_is_hidden ()
-{
- GFile *f;
-
- ensure_file_exists ("./non-hidden-test-file");
-
- f = g_file_new_for_path (TEST_HIDDEN_FILENAME);
- g_assert_true (tracker_file_is_hidden (f));
- g_object_unref (f);
-
- f = g_file_new_for_path ("./non-hidden-test-file");
- g_assert_true (!tracker_file_is_hidden (f));
- g_object_unref (f);
-
- remove_file ("./non-hidden-test-file");
-}
-
-static void
-test_file_utils_cmp ()
-{
- GFile *one, *two, *three;
-
- one = g_file_new_for_path (TEST_FILENAME);
- two = g_file_new_for_path (TEST_FILENAME);
- three = g_file_new_for_path (TEST_HIDDEN_FILENAME);
-
- g_assert_true (!tracker_file_cmp (one, two));
- g_assert_true (tracker_file_cmp (two, three));
-}
-
int
main (int argc, char **argv)
{
@@ -418,33 +90,10 @@ main (int argc, char **argv)
ensure_file_exists (TEST_FILENAME);
ensure_file_exists (TEST_HIDDEN_FILENAME);
- g_test_add_func ("/libtracker-common/file-utils/path_evaluate_name",
- test_path_evaluate_name);
- g_test_add_func ("/libtracker-common/file-utils/path_list_filter_duplicates",
- test_path_list_filter_duplicates);
- g_test_add_func ("/libtracker-common/file-utils/path_list_filter_duplicates_with_exceptions",
- test_path_list_filter_duplicates_with_exceptions);
- g_test_add_func ("/libtracker-common/file-utils/file_get_mime_type",
- test_file_get_mime_type);
- g_test_add_func ("/libtracker-common/file-utils/case_match_filename_without_extension",
- test_case_match_filename_without_extension);
-
- g_test_add_func ("/libtracker-common/file-utils/open_close",
- test_file_utils_open_close);
g_test_add_func ("/libtracker-common/file-utils/get_size",
test_file_utils_get_size);
- g_test_add_func ("/libtracker-common/file-utils/get_mtime",
- test_file_utils_get_mtime);
- g_test_add_func ("/libtracker-common/file-utils/get_remaining_space",
- test_file_system_get_remaining_space);
- g_test_add_func ("/libtracker-common/file-utils/get_remaining_space_percentage",
- test_file_system_get_remaining_space_percentage);
g_test_add_func ("/libtracker-common/file-utils/has_enough_space",
test_file_system_has_enough_space);
- g_test_add_func ("/libtracker-common/file-utils/is_hidden",
- test_file_utils_is_hidden);
- g_test_add_func ("/libtracker-common/file-utils/cmp",
- test_file_utils_cmp);
result = g_test_run ();
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 <ivan.frade@nokia.com>
- *
- * 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 <time.h>
-#include <string.h>
-
-#include <glib-object.h>
-
-#include <libtracker-common/tracker-type-utils.h>
-
-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;
-}
diff --git a/tests/libtracker-common/tracker-utils-test.c b/tests/libtracker-common/tracker-utils-test.c
index c98b45083..086c27185 100644
--- a/tests/libtracker-common/tracker-utils-test.c
+++ b/tests/libtracker-common/tracker-utils-test.c
@@ -27,90 +27,6 @@
#include <locale.h>
static void
-test_seconds_to_string ()
-{
- gchar *result;
-
- result = tracker_seconds_to_string (0, TRUE);
- g_assert_cmpstr (result, ==, "less than one second");
- g_free (result);
-
- result = tracker_seconds_to_string (0.1, TRUE);
- g_assert_cmpstr (result, ==, "less than one second");
- g_free (result);
-
- result = tracker_seconds_to_string (59.9, TRUE);
- g_assert_cmpstr (result, ==, "59s");
- g_free (result);
-
- result = tracker_seconds_to_string (60, TRUE);
- g_assert_cmpstr (result, ==, "01m");
- g_free (result);
-
- result = tracker_seconds_to_string (100.12, TRUE);
- g_assert_cmpstr (result, ==, "01m 40s");
- g_free (result);
-
- result = tracker_seconds_to_string (100, FALSE);
- g_assert_cmpstr (result, ==, "01 minute 40 seconds");
- g_free (result);
-
- result = tracker_seconds_to_string (1000000, TRUE);
- g_assert_cmpstr (result, ==, "11d 13h 46m 40s");
- g_free (result);
-
- result = tracker_seconds_to_string (1000000000, TRUE);
- g_assert_cmpstr (result, ==, "11574d 01h 46m 40s");
- g_free (result);
-
-}
-
-static void
-test_seconds_estimate_to_string ()
-{
- gchar *result;
-
- result = tracker_seconds_estimate_to_string (60, TRUE, 60, 120);
- g_assert_cmpstr (result, ==, "02m");
- g_free (result);
-}
-
-static void
-test_is_empty_string ()
-{
- g_assert_true (tracker_is_empty_string (NULL));
- g_assert_true (tracker_is_empty_string (""));
- g_assert_true (!tracker_is_empty_string ("Eeeeepa not empty"));
-}
-
-static void
-test_is_blank_string ()
-{
- g_assert_true (tracker_is_blank_string (NULL));
- g_assert_true (tracker_is_blank_string (""));
- g_assert_true (tracker_is_blank_string (" "));
- g_assert_true (tracker_is_blank_string (" "));
- g_assert_true (!tracker_is_blank_string (" - "));
- g_assert_true (!tracker_is_blank_string (" -"));
- g_assert_true (!tracker_is_blank_string ("- "));
- g_assert_true (!tracker_is_blank_string ("nonono"));
-
-}
-
-static void
-test_seconds_estimate (void)
-{
- g_assert_cmpint (tracker_seconds_estimate (10, 10, 20), ==, 20);
- g_assert_cmpint (tracker_seconds_estimate (10, 9, 20), ==, 22);
-
- g_assert_cmpint (tracker_seconds_estimate (0, 2, 2), ==, 0);
- g_assert_cmpint (tracker_seconds_estimate (-1, 2, 2), ==, 0);
- g_assert_cmpint (tracker_seconds_estimate (1, 0, 2), ==, 0);
- g_assert_cmpint (tracker_seconds_estimate (1, -1, 2), ==, 0);
- g_assert_cmpint (tracker_seconds_estimate (1, 1, 0), ==, 0);
-}
-
-static void
test_strhex (void)
{
gchar *result;
@@ -142,21 +58,6 @@ main (int argc, char **argv)
setlocale (LC_ALL, "");
- g_test_add_func ("/libtracker-common/tracker-utils/seconds_to_string",
- test_seconds_to_string);
-
- g_test_add_func ("/libtracker-common/tracker-utils/seconds_estimate_to_string",
- test_seconds_estimate_to_string);
-
- g_test_add_func ("/libtracker-common/tracker-utils/seconds_estimate",
- test_seconds_estimate);
-
- g_test_add_func ("/libtracker-common/tracker-utils/empty_string",
- test_is_empty_string);
-
- g_test_add_func ("/libtracker-common/tracker-utils/blank_string",
- test_is_blank_string);
-
g_test_add_func ("/libtracker-common/tracker-utils/strhex",
test_strhex);