[tracker/wip/carlosg/libtracker-common-cleanup: 1/6] libtracker-common: Remove unused tracker util functions
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/libtracker-common-cleanup: 1/6] libtracker-common: Remove unused tracker util functions
- Date: Wed, 16 Sep 2020 10:40:30 +0000 (UTC)
commit 6c89979733a1bd736eeb20a650c23a4f77fff174
Author: Carlos Garnacho <carlosg gnome org>
Date: Tue Sep 8 13:20:28 2020 +0200
libtracker-common: Remove unused tracker util functions
These are only exercised in tests, we can do without them.
src/libtracker-common/tracker-utils.c | 133 ---------------------------
src/libtracker-common/tracker-utils.h | 11 ---
tests/libtracker-common/tracker-utils-test.c | 99 --------------------
3 files changed, 243 deletions(-)
---
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/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
@@ -26,90 +26,6 @@
#include <libtracker-common/tracker-locale.h>
#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)
{
@@ -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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]