[gnumeric] Tests: add test for roundtrip of vba through xls conversion.



commit 3f764ba6943bbdf652c07497523e44cb13443681
Author: Morten Welinder <terra gnome org>
Date:   Thu Feb 27 18:07:59 2014 -0500

    Tests: add test for roundtrip of vba through xls conversion.

 samples/vba-725220.xls      |  Bin 0 -> 33792 bytes
 test/Makefile.am            |    1 +
 test/t6050-vba-roundtrip.pl |   61 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 62 insertions(+), 0 deletions(-)
---
diff --git a/samples/vba-725220.xls b/samples/vba-725220.xls
new file mode 100644
index 0000000..f78de39
Binary files /dev/null and b/samples/vba-725220.xls differ
diff --git a/test/Makefile.am b/test/Makefile.am
index cfcd314..523fc73 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -66,6 +66,7 @@ TESTS =       t1000-statfuns.pl                       \
        t6002-objs.pl                           \
        t6003-lookfuns.pl                       \
        t6004-finfuns.pl                        \
+       t6050-vba-roundtrip.pl                  \
        t6100-statfuns-ods.pl                   \
        t6101-mathfuns-ods.pl                   \
        t6102-objs-ods.pl                       \
diff --git a/test/t6050-vba-roundtrip.pl b/test/t6050-vba-roundtrip.pl
new file mode 100755
index 0000000..539b217
--- /dev/null
+++ b/test/t6050-vba-roundtrip.pl
@@ -0,0 +1,61 @@
+#!/usr/bin/perl -w
+# -----------------------------------------------------------------------------
+
+use strict;
+use lib ($0 =~ m|^(.*/)| ? $1 : ".");
+use GnumericTest;
+
+&message ("Check that vba roundtrips through xls");
+
+my $src = "$samples/vba-725220.xls";
+&GnumericTest::report_skip ("file $src does not exist") unless -r $src;
+
+my $gsfhelp = `gsf help 2>&1`;
+&GnumericTest::report_skip ("gsf is not available")
+    unless ($gsfhelp || '') =~ /\bcat\b/;
+
+my $dir1 = &gsf_list ($src);
+
+my $tmp = $src;
+$tmp =~ s|^.*/||;
+$tmp =~ s|\..*|-tmp.xls|;
+&GnumericTest::junkfile ($tmp);
+system ("$ssconvert $src $tmp");
+my $dir2 = &gsf_list ($tmp);
+
+foreach my $f (sort keys %$dir1) {
+    next unless ($f eq "\001Ole" ||
+                $f eq "\001CompObj" ||
+                $f =~ m{^_VBA_PROJECT_CUR/});
+    my $fprint = $f;
+    $fprint =~ s{\001}{\\001};
+    if (!exists $dir2->{$f}) {
+       die "$0: member $fprint is missing after conversion.\n";
+    } elsif ($dir1->{$f} ne $dir2->{$f}) {
+       die "$0: member $fprint changed length during conversion.\n";
+    } else {
+       my $d1 = `gsf cat '$src' '$f'`;
+       my $d2 = `gsf cat '$tmp' '$f'`;
+       if (length ($d1) ne $dir1->{$f}) {
+           print "Member $fprint is strange\n";
+       } elsif ($d1 eq $d2) {
+           print "Member $fprint is ok\n";
+       } else {
+           die "$0: member $fprint changed contents during conversion.\n";
+       }
+    }
+}
+
+sub gsf_list {
+    my ($fn) = @_;
+
+    my $dir = {};
+    local (*FIL);
+    open (FIL, "gsf list '$fn' | ") or die "Cannot parse $fn: $!\n";
+    while (<FIL>) {
+       next unless /^f\s.*\s(\d+)\s+(.*)$/;
+       $dir->{$2} = $1;
+    }
+    close FIL;
+    return $dir;
+}


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