[gnumeric] Links: add roundtrip tests for hyperlinks.



commit d45358bea1d6be7c0b3db6ba43dbd4731676225d
Author: Morten Welinder <terra gnome org>
Date:   Sat Feb 18 17:53:08 2017 -0500

    Links: add roundtrip tests for hyperlinks.
    
    And make sure xlsx write them deterministically.

 plugins/excel/ChangeLog    |    4 +++
 plugins/excel/xlsx-write.c |   30 ++++++++++++++++++++++++++-
 test/GnumericTest.pm       |    1 +
 test/Makefile.am           |    1 +
 test/t6522-hlink.pl        |   49 ++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 84 insertions(+), 1 deletions(-)
---
diff --git a/plugins/excel/ChangeLog b/plugins/excel/ChangeLog
index c83c4b3..01ba9cc 100644
--- a/plugins/excel/ChangeLog
+++ b/plugins/excel/ChangeLog
@@ -1,3 +1,7 @@
+2017-02-18  Morten Welinder  <terra gnome org>
+
+       * xlsx-write.c (xlsx_write_hlinks): Impose an ordering on links.
+
 2017-02-16  Jean Brefort  <jean brefort normalesup org>
 
        * xlsx-write-drawing.c (xlsx_write_layout), (xlsx_write_one_chart): first
diff --git a/plugins/excel/xlsx-write.c b/plugins/excel/xlsx-write.c
index 0fe90ab..b344aee 100644
--- a/plugins/excel/xlsx-write.c
+++ b/plugins/excel/xlsx-write.c
@@ -2097,6 +2097,31 @@ xlsx_write_hlink (GnmHLink const *link, GSList *ranges, XLSXClosure *info)
        }
 }
 
+static int
+by_hlink_order (gpointer link_a, G_GNUC_UNUSED gpointer val_a,
+               gpointer link_b, G_GNUC_UNUSED gpointer val_b,
+               G_GNUC_UNUSED gpointer user)
+{
+       GnmHLink const *a = link_a;
+       GnmHLink const *b = link_b;
+       int res;
+
+       res = g_strcmp0 (g_type_name (G_OBJECT_TYPE (a)), g_type_name (G_OBJECT_TYPE (b)));
+       if (res)
+               return res;
+
+       res = g_strcmp0 (gnm_hlink_get_target (a), gnm_hlink_get_target (b));
+       if (res)
+               return res;
+
+       res = g_strcmp0 (gnm_hlink_get_tip (a), gnm_hlink_get_tip (b));
+       if (res)
+               return res;
+
+       // Fallback
+       return a < b ? -1 : (a > b ? +1 : 0);
+}
+
 static void
 xlsx_write_hlinks (XLSXWriteState *state, GsfXMLOut *xml, G_GNUC_UNUSED GnmRange const *extent)
 {
@@ -2110,7 +2135,10 @@ xlsx_write_hlinks (XLSXWriteState *state, GsfXMLOut *xml, G_GNUC_UNUSED GnmRange
                        XLSX_MAX_COLS, XLSX_MAX_ROWS);
 
                gsf_xml_out_start_element (xml, "hyperlinks");
-               g_hash_table_foreach (group, (GHFunc) xlsx_write_hlink, &info);
+               gnm_hash_table_foreach_ordered
+                       (group, (GHFunc) xlsx_write_hlink,
+                        by_hlink_order,
+                        &info);
                gsf_xml_out_end_element (xml); /*  </hyperlinks> */
 
                g_hash_table_destroy (group);
diff --git a/test/GnumericTest.pm b/test/GnumericTest.pm
index f9ad5d3..f59fda4 100644
--- a/test/GnumericTest.pm
+++ b/test/GnumericTest.pm
@@ -215,6 +215,7 @@ my @full_corpus =
      "$samples/format-tests.gnumeric",
      "$samples/formula-tests.gnumeric",
      "$samples/graph-tests.gnumeric",
+     "$samples/hlink-tests.gnumeric",
      "$samples/merge-tests.gnumeric",
      "$samples/names-tests.gnumeric",
      "$samples/number-tests.gnumeric",
diff --git a/test/Makefile.am b/test/Makefile.am
index 65e7f32..4cbadc6 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -110,6 +110,7 @@ TESTS =     t1000-statfuns.pl                       \
        t6519-selection.pl                      \
        t6520-sheet-tab.pl                      \
        t6521-sheet-names.pl                    \
+       t6522-hlink.pl                          \
        t7000-goal-seek.pl                      \
        t7100-solver-blend.pl                   \
        t7101-solver-afiro.pl                   \
diff --git a/test/t6522-hlink.pl b/test/t6522-hlink.pl
new file mode 100755
index 0000000..e0c3c20
--- /dev/null
+++ b/test/t6522-hlink.pl
@@ -0,0 +1,49 @@
+#!/usr/bin/perl -w
+# -----------------------------------------------------------------------------
+
+use strict;
+use lib ($0 =~ m|^(.*/)| ? $1 : ".");
+use GnumericTest;
+
+my $file = "$samples/hlink-tests.gnumeric";
+
+if (&subtest ("gnumeric")) {
+    &message ("Check hyperlink gnumeric roundtrip.");
+    &test_roundtrip ($file,
+                    'format' => 'Gnumeric_XmlIO:sax',
+                    'ext' => "gnm");
+}
+
+if (&subtest ("ods")) {
+    &message ("Check hyperlink ods roundtrip.");
+    &test_roundtrip ($file,
+                    'format' => 'Gnumeric_OpenCalc:odf',
+                    'ext' => "ods",
+                    'filter2' => 'std:drop_generator');
+}
+
+if (&subtest ("biff7")) {
+    &message ("Check hyperlink xls/BIFF7 roundtrip.");
+    &test_roundtrip ($file,
+                    'format' => 'Gnumeric_Excel:excel_biff7',
+                    'ext' => "xls",
+                    'resize' => '16384x256',
+                    'filter2' => 'std:drop_codepage',
+                    'ignore_failure' => 1);
+}
+
+if (&subtest ("biff8")) {
+    &message ("Check hyperlink xls/BIFF8 roundtrip.");
+    &test_roundtrip ($file,
+                    'format' => 'Gnumeric_Excel:excel_biff8',
+                    'ext' => "xls",
+                    'filter2' => 'std:drop_codepage');
+}
+
+if (&subtest ("xlsx")) {
+    &message ("Check hyperlink xlsx roundtrip.");
+    &test_roundtrip ($file,
+                    'format' => 'Gnumeric_Excel:xlsx',
+                    'ext' => "xlsx",
+                    'resize' => '1048576x16384');
+}


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