Commit bf090287 authored by Ivan Frade's avatar Ivan Frade

tests: Use g_assert_cmpstr instead of our own implementation

tracker_test_helpers_cmpstr_equals was written when g_assert_cmpstr
didn't exist but both had the same intention.
parent 78ca6c2e
......@@ -20,28 +20,6 @@
static gchar *nonutf8_str = NULL;
gboolean
tracker_test_helpers_cmpstr_equal (const gchar *obtained,
const gchar *expected)
{
gboolean result;
if (expected == obtained) {
return TRUE;
}
if (expected && obtained) {
result = !g_utf8_collate (expected, obtained);
if (!result) {
g_warning ("Expected %s - obtained %s", expected, obtained);
}
return result;
} else {
g_warning ("\n Only one of the strings is NULL\n");
return FALSE;
}
}
const gchar *
tracker_test_helpers_get_nonutf8 (void)
{
......
......@@ -23,8 +23,6 @@
G_BEGIN_DECLS
gboolean tracker_test_helpers_cmpstr_equal (const gchar *obtained,
const gchar *expected);
const gchar *tracker_test_helpers_get_nonutf8 (void);
void tracker_test_helpers_free_nonutf8 (void);
......
......@@ -88,14 +88,14 @@ test_path_evaluate_name (void)
result = tracker_path_evaluate_name ("/home/user/all/ok");
tracker_test_helpers_cmpstr_equal (result, "/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/");
tracker_test_helpers_cmpstr_equal (result, "/home/user/all/dir");
g_assert_cmpstr (result, ==, "/home/user/all/dir");
g_free (result);
......@@ -104,35 +104,35 @@ test_path_evaluate_name (void)
*/
result = tracker_path_evaluate_name ("~/all/dir/");
expected = g_build_path (G_DIR_SEPARATOR_S, home, "/all/dir/", NULL);
tracker_test_helpers_cmpstr_equal (result, expected);
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);
tracker_test_helpers_cmpstr_equal (result, expected);
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);
tracker_test_helpers_cmpstr_equal (result, expected);
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);
tracker_test_helpers_cmpstr_equal (result, expected);
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);
tracker_test_helpers_cmpstr_equal (result, expected);
g_assert_cmpstr (result, ==, expected);
g_free (result);
g_free (expected);
......@@ -140,7 +140,7 @@ test_path_evaluate_name (void)
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);
tracker_test_helpers_cmpstr_equal (result, expected);
g_assert_cmpstr (result, ==, expected);
g_free (result);
g_free (parent_dir);
......@@ -153,8 +153,7 @@ test_path_evaluate_name (void)
g_assert (!result);
result = tracker_path_evaluate_name (tracker_test_helpers_get_nonutf8 ());
tracker_test_helpers_cmpstr_equal (result,
tracker_test_helpers_get_nonutf8 ());
g_assert_cmpstr (result, ==, tracker_test_helpers_get_nonutf8 ());
g_unsetenv ("TEST_TRACKER_DIR");
}
......@@ -173,7 +172,7 @@ test_file_get_mime_type (void)
result = tracker_file_get_mime_type (dir);
g_assert (tracker_test_helpers_cmpstr_equal (result, "inode/directory"));
g_assert_cmpstr (result, ==, "inode/directory");
/* Remove test directory */
g_file_delete (dir, NULL, NULL);
......
......@@ -25,8 +25,6 @@
#include <libtracker-common/tracker-date-time.h>
#include <libtracker-common/tracker-type-utils.h>
#include <tracker-test-helpers.h>
static void
test_string_to_date (void)
......@@ -121,12 +119,12 @@ test_long_to_string (void)
n = 10050;
result = tracker_glong_to_string (n);
g_assert (tracker_test_helpers_cmpstr_equal (result, "10050"));
g_assert_cmpstr (result, ==, "10050");
g_free (result);
n = -9950;
result = tracker_glong_to_string (n);
g_assert (tracker_test_helpers_cmpstr_equal (result, "-9950"));
g_assert_cmpstr (result, ==, "-9950");
g_free (result);
}
......@@ -138,12 +136,12 @@ test_int_to_string (void)
n = 654;
result = tracker_gint_to_string (n);
g_assert (tracker_test_helpers_cmpstr_equal (result, "654"));
g_assert_cmpstr (result, ==, "654");
g_free (result);
n = -963;
result = tracker_gint_to_string (n);
g_assert (tracker_test_helpers_cmpstr_equal (result, "-963"));
g_assert_cmpstr (result, ==, "-963");
g_free (result);
}
......@@ -156,7 +154,7 @@ test_uint_to_string (void)
n = 100;
result = tracker_guint_to_string (n);
g_assert (tracker_test_helpers_cmpstr_equal (result, "100"));
g_assert_cmpstr (result, ==, "100");
g_free (result);
}
......@@ -168,12 +166,12 @@ test_gint32_to_string (void)
n = 100;
result = tracker_gint32_to_string (n);
g_assert (tracker_test_helpers_cmpstr_equal (result, "100"));
g_assert_cmpstr (result, ==, "100");
g_free (result);
n = -96;
result = tracker_gint32_to_string (n);
g_assert (tracker_test_helpers_cmpstr_equal (result, "-96"));
g_assert_cmpstr (result, ==, "-96");
g_free (result);
}
......@@ -186,7 +184,7 @@ test_guint32_to_string (void)
n = 100;
result = tracker_guint32_to_string (n);
g_assert (tracker_test_helpers_cmpstr_equal (result, "100"));
g_assert_cmpstr (result, ==, "100");
g_free (result);
}
......@@ -280,10 +278,10 @@ test_gslist_to_string_list (void)
result = tracker_gslist_to_string_list (input);
g_assert (tracker_test_helpers_cmpstr_equal (result[0], "one") &&
tracker_test_helpers_cmpstr_equal (result[1], "two") &&
tracker_test_helpers_cmpstr_equal (result[2], "three") &&
tracker_test_helpers_cmpstr_equal (result[3], "four"));
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);
......@@ -335,11 +333,11 @@ test_string_list_to_string (void)
pieces = g_strsplit (input, " ", 4);
result = tracker_string_list_to_string (pieces, 4, ' ');
g_assert (tracker_test_helpers_cmpstr_equal (input, result));
g_assert_cmpstr (input, ==, result);
g_free (result);
result = tracker_string_list_to_string (pieces, 3, '_');
g_assert (tracker_test_helpers_cmpstr_equal ("one_two_three", result));
g_assert_cmpstr ("one_two_three", ==, result);
g_free (result);
......@@ -350,11 +348,11 @@ test_string_list_to_string (void)
g_test_trap_assert_failed ();
result = tracker_string_list_to_string (pieces, -1, ' ');
g_assert (tracker_test_helpers_cmpstr_equal (input, result));
g_assert_cmpstr (input, ==, result);
g_free (result);
result = tracker_string_list_to_string (pieces, 6, ' ');
g_assert (tracker_test_helpers_cmpstr_equal (input, result));
g_assert_cmpstr (input, ==, result);
g_free (result);
g_strfreev (pieces);
......@@ -378,42 +376,42 @@ test_boolean_as_text_to_number (void)
/* Correct true values */
result = tracker_string_boolean_to_string_gint ("True");
g_assert (tracker_test_helpers_cmpstr_equal (result, "1"));
g_assert_cmpstr (result, ==, "1");
g_free (result);
result = tracker_string_boolean_to_string_gint ("TRUE");
g_assert (tracker_test_helpers_cmpstr_equal (result, "1"));
g_assert_cmpstr (result, ==, "1");
g_free (result);
result = tracker_string_boolean_to_string_gint ("true");
g_assert (tracker_test_helpers_cmpstr_equal (result, "1"));
g_assert_cmpstr (result, ==, "1");
g_free (result);
/* Correct false values */
result = tracker_string_boolean_to_string_gint ("False");
g_assert (tracker_test_helpers_cmpstr_equal (result, "0"));
g_assert_cmpstr (result, ==, "0");
g_free (result);
result = tracker_string_boolean_to_string_gint ("FALSE");
g_assert (tracker_test_helpers_cmpstr_equal (result, "0"));
g_assert_cmpstr (result, ==, "0");
g_free (result);
result = tracker_string_boolean_to_string_gint ("false");
g_assert (tracker_test_helpers_cmpstr_equal (result, "0"));
g_assert_cmpstr (result, ==, "0");
g_free (result);
/* Invalid values */
result = tracker_string_boolean_to_string_gint ("Thrue");
g_assert (tracker_test_helpers_cmpstr_equal (result, "Thrue"));
g_assert_cmpstr (result, ==, "Thrue");
g_free (result);
result = tracker_string_boolean_to_string_gint ("Falsez");
g_assert (tracker_test_helpers_cmpstr_equal (result, "Falsez"));
g_assert_cmpstr (result, ==, "Falsez");
g_free (result);
result = tracker_string_boolean_to_string_gint ("Other invalid value");
g_assert (tracker_test_helpers_cmpstr_equal (result, "Other invalid value"));
g_assert_cmpstr (result, ==, "Other invalid value");
g_free (result);
......
......@@ -28,8 +28,6 @@
#include <libtracker-extract/tracker-extract.h>
#include <tracker-test-helpers.h>
static void
test_guess_date (void)
{
......@@ -39,27 +37,27 @@ test_guess_date (void)
g_assert (result == NULL);
result = tracker_date_guess ("2008-06-14");
g_assert (tracker_test_helpers_cmpstr_equal (result, "2008-06-14T00:00:00"));
g_assert_cmpstr (result, ==, "2008-06-14T00:00:00");
g_free (result);
result = tracker_date_guess ("20080614000000");
g_assert (tracker_test_helpers_cmpstr_equal (result, "2008-06-14T00:00:00"));
g_assert_cmpstr (result, ==, "2008-06-14T00:00:00");
g_free (result);
result = tracker_date_guess ("20080614000000Z");
g_assert (tracker_test_helpers_cmpstr_equal (result, "2008-06-14T00:00:00Z"));
g_assert_cmpstr (result, ==, "2008-06-14T00:00:00Z");
g_free (result);
result = tracker_date_guess ("Mon Jun 14 04:20:20 2008"); /* MS Office */
g_assert (tracker_test_helpers_cmpstr_equal (result, "2008-06-14T04:20:20"));
g_assert_cmpstr (result, ==, "2008-06-14T04:20:20");
g_free (result);
result = tracker_date_guess ("2008:06:14 04:20:20"); /* Exif style */
g_assert (tracker_test_helpers_cmpstr_equal (result, "2008-06-14T04:20:20"));
g_assert_cmpstr (result, ==, "2008-06-14T04:20:20");
g_free (result);
result = tracker_date_guess ("2010");
g_assert (tracker_test_helpers_cmpstr_equal (result, "2010-01-01T00:00:00Z"));
g_assert_cmpstr (result, ==, "2010-01-01T00:00:00Z");
g_free (result);
result = tracker_date_guess ("201a");
......@@ -70,16 +68,16 @@ test_guess_date (void)
/* Guessing from the code */
result = tracker_date_guess ("20100318010203-00:03Z");
g_assert (tracker_test_helpers_cmpstr_equal (result, "2010-03-18T01:02:03-00:03"));
g_assert_cmpstr (result, ==, "2010-03-18T01:02:03-00:03");
g_free (result);
result = tracker_date_guess ("20100318010203+00:03Z");
g_assert (tracker_test_helpers_cmpstr_equal (result, "2010-03-18T01:02:03+00:03"));
g_assert_cmpstr (result, ==, "2010-03-18T01:02:03+00:03");
g_free (result);
/* "YYYY-MM-DDThh:mm:ss.ff+zz:zz" */
result = tracker_date_guess ("2010-03-18T01:02:03.10-00:03");
g_assert (tracker_test_helpers_cmpstr_equal (result, "2010-03-18T01:02:03-00:03"));
g_assert_cmpstr (result, ==, "2010-03-18T01:02:03-00:03");
g_free (result);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment