[tracker] tests/libtracker-common: Testing tracker-date-time functions
- From: Ivan Frade <ifrade src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker] tests/libtracker-common: Testing tracker-date-time functions
- Date: Fri, 28 Oct 2011 15:08:49 +0000 (UTC)
commit 78dae461d93ed80ad90c5aa0d55b49f3d39e7621
Author: Ivan Frade <ivan frade gmail com>
Date: Fri Oct 28 18:05:00 2011 +0300
tests/libtracker-common: Testing tracker-date-time functions
tests/libtracker-common/tracker-date-time-test.c | 119 ++++++++++++++++++++++
1 files changed, 119 insertions(+), 0 deletions(-)
---
diff --git a/tests/libtracker-common/tracker-date-time-test.c b/tests/libtracker-common/tracker-date-time-test.c
index d9ba51e..24b13f2 100644
--- a/tests/libtracker-common/tracker-date-time-test.c
+++ b/tests/libtracker-common/tracker-date-time-test.c
@@ -25,6 +25,13 @@
#include <libtracker-common/tracker-date-time.h>
+/* This define was committed in glib 18.07.2011
+ * https://bugzilla.gnome.org/show_bug.cgi?id=577231
+ */
+#ifndef G_VALUE_INIT
+#define G_VALUE_INIT { 0, { { 0 } } }
+#endif
+
static void
test_string_to_date (void)
{
@@ -81,6 +88,10 @@ test_string_to_date (void)
result_time_t = tracker_string_to_date ("2008-06-32T04:23:10+0000", NULL);
g_assert_cmpint (result_time_t, ==, -1);
*/
+
+ /* More cases of string->date are tested in tracker_date_time_from_string...
+ * it is more convinient to test them there
+ */
}
static void
@@ -110,6 +121,105 @@ test_date_to_string (void)
g_assert (result != NULL && strncmp (result, "2008-06-16T23:53:10Z", 19) == 0);
}
+static void
+test_date_time_get_set ()
+{
+ GValue value = G_VALUE_INIT;
+ GValue copy = G_VALUE_INIT;
+
+ g_value_init (&value, TRACKER_TYPE_DATE_TIME);
+ g_value_init (©, TRACKER_TYPE_DATE_TIME);
+
+ tracker_date_time_set (&value, 123456789, 3600);
+
+ g_assert_cmpint (tracker_date_time_get_time (&value), ==, 123456789);
+ g_assert_cmpint (tracker_date_time_get_offset (&value), ==, 3600);
+
+ g_value_copy (&value, ©);
+
+ g_assert_cmpint (tracker_date_time_get_time (©), ==, 123456789);
+ g_assert_cmpint (tracker_date_time_get_offset (©), ==, 3600);
+}
+
+static void
+test_date_time_from_string ()
+{
+ 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 (!error);
+ g_assert_cmpint (tracker_date_time_get_time (&value), ==, 1319812980);
+ g_assert_cmpint (tracker_date_time_get_offset (&value), ==, 10800);
+
+
+ /* Negative offset */
+ tracker_date_time_set_from_string (&value, "2011-10-28T17:43:00-03:00", &error);
+ g_assert (!error);
+ g_assert_cmpint (tracker_date_time_get_time (&value), ==, 1319834580);
+ g_assert_cmpint (tracker_date_time_get_offset (&value), ==, -10800);
+
+ /* No offset */
+ tracker_date_time_set_from_string (&value, "2011-10-28T17:43:00", &error);
+ g_assert (!error);
+ g_assert_cmpint (tracker_date_time_get_time (&value), ==, 1319823780);
+ g_assert_cmpint (tracker_date_time_get_offset (&value), ==, 0);
+
+ /* Invalid format */
+ tracker_date_time_set_from_string (&value, "2011-10-28T17:43:00Z0900", &error);
+ g_assert (error);
+ g_error_free (error);
+ error = NULL;
+
+ /* There are no 28 months... */
+ tracker_date_time_set_from_string (&value, "2011-28-10T17:43:00Z0900", &error);
+ g_assert (error);
+ g_error_free (error);
+ error = NULL;
+
+ /* ... nor more than +-12 offsets */
+ tracker_date_time_set_from_string (&value, "2011-28-10T17:43:00+17:00", &error);
+ g_assert (error);
+ g_error_free (error);
+ error = NULL;
+
+ /* ... the same for the glory of the branch % */
+ tracker_date_time_set_from_string (&value, "2011-28-10T17:43:00-17:00", &error);
+ g_assert (error);
+ g_error_free (error);
+ error = NULL;
+}
+
+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 (!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 (!error);
+
+ g_assert_cmpint (tracker_date_time_get_local_time (&value), ==, 63780);
+}
+
gint
main (gint argc, gchar **argv)
{
@@ -120,5 +230,14 @@ main (gint argc, gchar **argv)
test_date_to_string);
g_test_add_func ("/libtracker-common/date-time/string_to_date",
test_string_to_date);
+ g_test_add_func ("/libtracker-common/date-time/get_set",
+ 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);
+
return g_test_run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]