[gexiv2] test: Port python tests to C



commit 7af4b65dd0e8c9976071f1a7301028c5c2d73246
Author: Jens Georg <mail jensge org>
Date:   Sun Mar 12 12:40:55 2017 +0100

    test: Port python tests to C
    
    So they can always run on make check

 check.am                 |   10 ++++--
 test/gexiv2-regression.c |   78 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 85 insertions(+), 3 deletions(-)
---
diff --git a/check.am b/check.am
index 5076b03..59a8201 100644
--- a/check.am
+++ b/check.am
@@ -8,7 +8,11 @@ TESTS_ENVIRONMENT = \
 
 tests: check
 
-TESTS =
+TESTS = test/gexiv2-regression
+
+check_PROGRAMS = test/gexiv2-regression
+
+test_gexiv2_regression_SOURCES = test/gexiv2-regression.c
 
 if PYTHON2_PATH
 TESTS += test/python2-test
@@ -19,7 +23,7 @@ TESTS += test/python3-test
 endif
 
 if HAVE_VALAC
-check_PROGRAMS = test/gexiv2-dump
+check_PROGRAMS += test/gexiv2-dump
 test_gexiv2_dump_SOURCES = test/gexiv2-dump.vala
 endif
 
@@ -30,7 +34,7 @@ LDADD = \
        $(GLIB_LIBS) $(EXIV2_LIBS)
 AM_CFLAGS = \
        $(GLIB_CFLAGS) $(EXIV2_CFLAGS) \
-       -I $(top_srcdir)
+       -I $(top_srcdir) -DSAMPLE_PATH="\"$(abs_top_srcdir)/test\""
 
 EXTRA_DIST += \
        test/sample-author-badencoding.jpg \
diff --git a/test/gexiv2-regression.c b/test/gexiv2-regression.c
new file mode 100644
index 0000000..d339cae
--- /dev/null
+++ b/test/gexiv2-regression.c
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2017 Jens Georg <mail jensge org>
+ *
+ * This library is free software. See COPYING for details
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <glib.h>
+
+#include <gexiv2/gexiv2.h>
+
+#include <string.h>
+
+/* Check that gexiv2 correctly handles ratios with 0/0 as used by
+ * some cameras
+ */
+static void test_bgo_775249(void)
+{
+    GExiv2Metadata *meta = NULL;
+    gboolean result = FALSE;
+    gdouble lon = 0.0, lat = 0.0, alt = 0.0;
+    GError *error = NULL;
+
+    meta = gexiv2_metadata_new();
+    g_assert_nonnull(meta);
+    result = gexiv2_metadata_open_path(meta, SAMPLE_PATH "/CaorVN.jpeg", &error);
+    g_assert_no_error(error);
+    g_assert_true(result);
+    g_assert_true(gexiv2_metadata_get_gps_info(meta, &lon, &lat, &alt));
+
+    g_assert_cmpfloat(lon, ==, -1.508425);
+
+    /* Just check if it fits in there; The main issue is that it's not 0 */
+    g_assert_cmpfloat(lat, >=, 48.631806);
+    g_assert_cmpfloat(lat, <=, 48.631807);
+    g_assert_cmpfloat(alt, ==, -0.926000);
+
+    g_clear_object(&meta);
+}
+
+static const char test_bgo_730136_artist_data[] = {
+  0xc0, 0xeb, 0xe5, 0xea, 0xf1, 0xe0, 0xed, 0xe4,
+  0xf0,  ' ', 0xca, 0xee, 0xf8, 0xe5, 0xeb, 0xe5,
+  0xe2, 0x00
+};
+
+static void test_bgo_730136(void)
+{
+    GExiv2Metadata *meta = NULL;
+    gboolean result = FALSE;
+    GError *error = NULL;
+    GBytes *raw_tag = NULL;
+
+    meta = gexiv2_metadata_new ();
+    g_assert_nonnull (meta);
+    result = gexiv2_metadata_open_path (meta, SAMPLE_PATH "/sample-author-badencoding.jpg", &error);
+    g_assert_no_error(error);
+    g_assert_true(result);
+
+    raw_tag = gexiv2_metadata_get_tag_raw (meta, "Exif.Image.Artist");
+    g_assert_nonnull (raw_tag);
+    g_assert_cmpmem (g_bytes_get_data(raw_tag, NULL), g_bytes_get_size(raw_tag),
+                     test_bgo_730136_artist_data, sizeof(test_bgo_730136_artist_data));
+    g_clear_object (&meta);
+    g_clear_pointer (&raw_tag, g_bytes_unref);
+}
+
+int main(int argc, char *argv[static argc + 1])
+{
+    g_test_init(&argc, &argv, NULL);
+    g_test_add_func("/bugs/gnome/775249", test_bgo_775249);
+    g_test_add_func("/bugs/gnome/730136", test_bgo_730136);
+
+    return g_test_run();
+}


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