[gnome-logs/wip/test] Add test for timestamp comparison



commit 10305a1ff7683c5eacdef8ce8d2d697b70fe2761
Author: Ekaterina Gerasimova <kittykat3756 gmail com>
Date:   Mon Feb 9 14:30:04 2015 +0000

    Add test for timestamp comparison

 Makefile.am          |   27 ++++++++++++++++++
 tests/test-gl-util.c |   73 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 100 insertions(+), 0 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 6bbeeec..ec9deda 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -112,7 +112,34 @@ test-desktop-file-validate.sh: Makefile
 check_SCRIPTS = \
        test-desktop-file-validate.sh
 
+# Tests:
+TESTS_ENVIRONMENT = \
+       LANG=C \
+       MALLOC_CHECK_=2 \
+       MALLOC_PERTURB_=$$(($${RANDOM:-256} % 256)) \
+       G_SLICE=debug-blocks
+
+tests_test_gl_util_CPPFLAGS = \
+       -DLOCALEDIR=\""$(localedir)"\" \
+       -I$(top_builddir) \
+       -I$(top_builddir)/src \
+       $(WARN_CFLAGS)
+
+tests_test_gl_util_CFLAGS = \
+       $(LOGS_CFLAGS)
+
+tests_test_gl_util_LDADD = \
+       $(LOGS_LIBS)
+
+tests_test_gl_util_SOURCES = \
+       tests/test-gl-util.c \
+       src/gl-util.c
+
+check_PROGRAMS = \
+       tests/test-gl-util
+
 TESTS = \
+       $(check_PROGRAMS) \
        $(check_SCRIPTS)
 endif
 
diff --git a/tests/test-gl-util.c b/tests/test-gl-util.c
new file mode 100644
index 0000000..5fac6d9
--- /dev/null
+++ b/tests/test-gl-util.c
@@ -0,0 +1,73 @@
+/*
+ *  GNOME Logs - View and search logs
+ *  Copyright (C) 2015 Ekaterina Gerasimova
+ *
+ *  This program 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 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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 program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "gl-util.h"
+
+static void
+util_timestamp_to_display (void)
+{
+    gsize i;
+    GDateTime *now;
+
+    static const struct
+    {
+        guint64 microsecs;
+        GlUtilClockFormat format;
+        const gchar *time;
+    } times[] =
+    {
+        /* Test three cases for each format (same day, same year, different
+           year */
+        { G_GUINT64_CONSTANT (1423486800000000), GL_UTIL_CLOCK_FORMAT_12HR,
+          " 1:00 PM" },
+        { G_GUINT64_CONSTANT (1423402200000000), GL_UTIL_CLOCK_FORMAT_12HR,
+          "Feb  8  1:30 PM" },
+        { G_GUINT64_CONSTANT (1391952600000000), GL_UTIL_CLOCK_FORMAT_12HR,
+          "Feb  9 2014  1:30 PM" },
+        { G_GUINT64_CONSTANT (1423486800000000), GL_UTIL_CLOCK_FORMAT_24HR,
+          "13:00" },
+        { G_GUINT64_CONSTANT (1423402200000000), GL_UTIL_CLOCK_FORMAT_24HR,
+          "Feb  8 13:30" },
+        { G_GUINT64_CONSTANT (1391952600000000), GL_UTIL_CLOCK_FORMAT_24HR,
+          "Feb  9 2014 13:30" }
+    };
+
+    now = g_date_time_new_utc (2015, 2, 9, 13, 30, 42);
+
+    for (i = 0; i < G_N_ELEMENTS (times); i++)
+    {
+        gchar *compare;
+
+        compare = gl_util_timestamp_to_display (times[i].microsecs, now,
+                                                times[i].format);
+        g_assert_cmpstr (compare, ==, times[i].time);
+        g_free (compare);
+    }
+
+    g_date_time_unref (now);
+}
+
+int
+main (int argc, char** argv)
+{
+    g_test_init (&argc, &argv, NULL);
+
+    g_test_add_func ("/util/timestamp_to_display", util_timestamp_to_display);
+
+    return g_test_run ();
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]