tracker-0.16.2/tests/libtracker-common/tracker-utils-test.c

No issues found

  1 /*
  2  * Copyright (C) 2010, Nokia <ivan.frade@nokia.com>
  3  *
  4  * This program is free software; you can redistribute it and/or
  5  * modify it under the terms of the GNU General Public
  6  * License as published by the Free Software Foundation; either
  7  * version 2 of the License, or (at your option) any later version.
  8  *
  9  * This program is distributed in the hope that it will be useful,
 10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 12  * General Public License for more details.
 13  *
 14  * You should have received a copy of the GNU General Public
 15  * License along with this program; if not, write to the
 16  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 17  * Boston, MA  02110-1301, USA.
 18  *
 19  */
 20 
 21 #include "config.h"
 22 
 23 #include <glib-object.h>
 24 #include <libtracker-common/tracker-file-utils.h>
 25 #include <libtracker-common/tracker-utils.h>
 26 #include <libtracker-common/tracker-locale.h>
 27 
 28 static void
 29 test_seconds_to_string ()
 30 {
 31 	gchar *result;
 32 
 33 	result = tracker_seconds_to_string (0, TRUE);
 34 	g_assert_cmpstr (result, ==, "less than one second");
 35 	g_free (result);
 36 
 37 	result = tracker_seconds_to_string (0.1, TRUE);
 38 	g_assert_cmpstr (result, ==, "less than one second");
 39 	g_free (result);
 40 
 41 	result = tracker_seconds_to_string (59.9, TRUE);
 42 	g_assert_cmpstr (result, ==, "59s");
 43 	g_free (result);
 44 
 45 	result = tracker_seconds_to_string (60, TRUE);
 46 	g_assert_cmpstr (result, ==, "01m");
 47 	g_free (result);
 48 
 49 	result = tracker_seconds_to_string (100.12, TRUE);
 50 	g_assert_cmpstr (result, ==, "01m 40s");
 51 	g_free (result);
 52 
 53 	result = tracker_seconds_to_string (100, FALSE);
 54 	g_assert_cmpstr (result, ==, "01 minute 40 seconds");
 55 	g_free (result);
 56 
 57 	result = tracker_seconds_to_string (1000000, TRUE);
 58 	g_assert_cmpstr (result, ==, "11d 13h 46m 40s");
 59 	g_free (result);
 60 
 61 	result = tracker_seconds_to_string (1000000000, TRUE);
 62 	g_assert_cmpstr (result, ==, "11574d 01h 46m 40s");
 63 	g_free (result);
 64 
 65 }
 66 
 67 static void
 68 test_seconds_estimate_to_string ()
 69 {
 70 	gchar *result;
 71 
 72 	result = tracker_seconds_estimate_to_string (60, TRUE, 60, 120);
 73 	g_assert_cmpstr (result, ==, "02m");
 74 	g_free (result);
 75 }
 76 
 77 static void
 78 test_is_empty_string ()
 79 {
 80         g_assert (tracker_is_empty_string (NULL));
 81         g_assert (tracker_is_empty_string (""));
 82         g_assert (!tracker_is_empty_string ("Eeeeepa not empty"));
 83 }
 84 
 85 static void
 86 test_is_blank_string ()
 87 {
 88         g_assert (tracker_is_blank_string (NULL));
 89         g_assert (tracker_is_blank_string (""));
 90         g_assert (tracker_is_blank_string (" "));
 91         g_assert (tracker_is_blank_string ("       "));
 92         g_assert (!tracker_is_blank_string ("   -    "));
 93         g_assert (!tracker_is_blank_string ("   -"));
 94         g_assert (!tracker_is_blank_string ("-   "));
 95         g_assert (!tracker_is_blank_string ("nonono"));
 96 
 97 }
 98 
 99 static void
100 test_seconds_estimate (void)
101 {
102         g_assert_cmpint (tracker_seconds_estimate (10, 10, 20), ==, 20);
103         g_assert_cmpint (tracker_seconds_estimate (10, 9, 20), ==, 22);
104 
105         g_assert_cmpint (tracker_seconds_estimate (0, 2, 2), ==, 0);
106         g_assert_cmpint (tracker_seconds_estimate (-1, 2, 2), ==, 0);
107         g_assert_cmpint (tracker_seconds_estimate (1, 0, 2), ==, 0);
108         g_assert_cmpint (tracker_seconds_estimate (1, -1, 2), ==, 0);
109         g_assert_cmpint (tracker_seconds_estimate (1, 1, 0), ==, 0);
110 }
111 
112 static void
113 test_strhex (void)
114 {
115         gchar *result;
116 
117         result = tracker_strhex ((const guint8 *)"a", 1, '|');
118         g_assert_cmpstr (result, ==, "61");
119         g_free (result);
120 
121         result = tracker_strhex ((const guint8 *)"ab", 2, '@');
122         g_assert_cmpstr (result, ==, "61@62");
123         g_free (result);
124 
125         result = tracker_strhex ((const guint8 *)"a b", 3, '@');
126         g_assert_cmpstr (result, ==, "61@20@62");
127         g_free (result);
128 
129         result = tracker_strhex ((const guint8 *)"abc", 1, '@');
130         g_assert_cmpstr (result, ==, "61");
131         g_free (result);
132 
133 }
134 
135 int
136 main (int argc, char **argv)
137 {
138 	gboolean ret;
139 
140 	g_test_init (&argc, &argv, NULL);
141 
142 	tracker_locale_init ();
143 
144 	g_test_add_func ("/libtracker-common/tracker-utils/seconds_to_string",
145 	                 test_seconds_to_string);
146 
147 	g_test_add_func ("/libtracker-common/tracker-utils/seconds_estimate_to_string",
148 	                 test_seconds_estimate_to_string);
149         
150         g_test_add_func ("/libtracker-common/tracker-utils/seconds_estimate",
151                          test_seconds_estimate);
152 
153         g_test_add_func ("/libtracker-common/tracker-utils/empty_string",
154                          test_is_empty_string);
155 
156         g_test_add_func ("/libtracker-common/tracker-utils/blank_string",
157                          test_is_blank_string);
158 
159         g_test_add_func ("/libtracker-common/tracker-utils/strhex",
160                          test_strhex);
161 
162 	ret = g_test_run ();
163 
164 	tracker_locale_shutdown ();
165 
166 	return ret;
167 }