[gnumeric] ssconvert: fix sheet selection for csv.



commit 147590f9b21180e2a2c3378daa4b2686428b0909
Author: Morten Welinder <terra gnome org>
Date:   Mon Jan 4 20:20:03 2021 -0500

    ssconvert: fix sheet selection for csv.
    
    And add test for that kind of thing.

 NEWS                          |  2 ++
 src/ssconvert.c               |  6 +++++-
 src/stf.c                     | 13 +++++++++----
 test/Makefile.am              |  1 +
 test/t9007-ssconvert-sheet.pl | 36 ++++++++++++++++++++++++++++++++++++
 5 files changed, 53 insertions(+), 5 deletions(-)
---
diff --git a/NEWS b/NEWS
index 1e00744a1..2c34e1a82 100644
--- a/NEWS
+++ b/NEWS
@@ -17,6 +17,8 @@ Morten:
        * Plug ssconvert leak.  [#546]
        * Fix bogus time match for "3.a".  [#545]
        * Use 1us resolution for NOW.  [#549]
+       * Fix ssconvert sheet selection for csv.  [#555]
+       * Test suite improvements.
 
 --------------------------------------------------------------------------
 Gnumeric 1.12.48
diff --git a/src/ssconvert.c b/src/ssconvert.c
index f11ae1502..763bef197 100644
--- a/src/ssconvert.c
+++ b/src/ssconvert.c
@@ -1131,6 +1131,7 @@ convert (char const *inarg, char const *outarg, char const *mergeargs[],
        GOFileSaveScope fsscope;
        GPtrArray *sheet_sel = NULL;
        GnmRangeRef const *range = NULL;
+       gboolean user_selected_sheets;
 
        if (ssconvert_object_export) {
                if (ssconvert_export_id)
@@ -1302,8 +1303,11 @@ convert (char const *inarg, char const *outarg, char const *mergeargs[],
                                     wb,
                                     ssconvert_range);
 
+       user_selected_sheets =
+               !!g_object_get_data (G_OBJECT (wb), SSCONVERT_SHEET_SET_KEY);
+
        if (ssconvert_one_file_per_sheet ||
-           fsscope == GO_FILE_SAVE_SHEET ||
+           (fsscope == GO_FILE_SAVE_SHEET && !user_selected_sheets) ||
            range) {
                Sheet *def_sheet = NULL;
 
diff --git a/src/stf.c b/src/stf.c
index 41206f371..036723e51 100644
--- a/src/stf.c
+++ b/src/stf.c
@@ -487,7 +487,7 @@ static void
 stf_write_csv (GOFileSaver const *fs, GOIOContext *context,
               GoView const *view, GsfOutput *output)
 {
-       Sheet *sheet;
+       GPtrArray *sheets;
        WorkbookView *wbv = GNM_WORKBOOK_VIEW (view);
 
        GnmStfExport *config = g_object_new
@@ -496,9 +496,14 @@ stf_write_csv (GOFileSaver const *fs, GOIOContext *context,
                 "quoting-triggers", ", \t\n\"",
                 NULL);
 
-       sheet = gnm_file_saver_get_sheet (fs, wbv);
-       if (sheet)
-               gnm_stf_export_options_sheet_list_add (config, sheet);
+       sheets = gnm_file_saver_get_sheets (fs, wbv, FALSE);
+       if (sheets) {
+               unsigned ui;
+               for (ui = 0; ui < sheets->len; ui++) {
+                       Sheet *sheet = g_ptr_array_index (sheets, ui);
+                       gnm_stf_export_options_sheet_list_add (config, sheet);
+               }
+       }
 
        if (gnm_stf_export (config) == FALSE)
                go_cmd_context_error_import (GO_CMD_CONTEXT (context),
diff --git a/test/Makefile.am b/test/Makefile.am
index 22f6a1fc6..ce0d61de4 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -179,6 +179,7 @@ TESTS =     t1000-statfuns.pl                       \
        t9004-ssdiff-highlight.pl               \
        t9005-ssconvert-merge.pl                \
        t9006-ssconvert-split.pl                \
+       t9007-ssconvert-sheet.pl                \
        t9010-ssgrep.pl                         \
        t9100-number-match.pl                   \
        t9999-epilogue.pl
diff --git a/test/t9007-ssconvert-sheet.pl b/test/t9007-ssconvert-sheet.pl
new file mode 100755
index 000000000..ed9a87be8
--- /dev/null
+++ b/test/t9007-ssconvert-sheet.pl
@@ -0,0 +1,36 @@
+#!/usr/bin/perl -w
+# -----------------------------------------------------------------------------
+
+use strict;
+use lib ($0 =~ m|^(.*/)| ? $1 : ".");
+use GnumericTest;
+
+my $src = "$samples/formats.xls";
+&report_skip ("file $src does not exist") unless -r $src;
+
+# Text formats
+for (['csv', 'Gnumeric_stf:stf_csv'],
+     ['txt', 'Gnumeric_stf:stf_assistant']) {
+    my ($fmt,$exporter) = @$_;
+
+    next unless &subtest ($fmt);
+    &message ("Checking ssconvert sheet selection for $fmt");
+
+    my $cmd = "$ssconvert -O 'sheet=General' -T $exporter $src fd://1";
+    print STDERR "# $cmd\n" if $GnumericTest::verbose;
+    my $out = `$cmd 2>&1`;
+    my $err = $?;
+    if ($err) {
+       &dump_indented ($out);
+       die "Failed command: $cmd\n";
+    }
+
+    if ($out =~ /Generalxx/ && $out !~ /Goffice configuration/) {
+       print STDERR "Pass\n";
+    } else {
+       die "Fail\n";
+    }
+}
+
+
+# Ought to check print formats here


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