[gnumeric] Tests: check that xlsx files are deterministic.



commit 00b92b1764f5ac8bcd1fe29d7ed98cb32696e01b
Author: Morten Welinder <terra gnome org>
Date:   Tue Apr 14 12:53:00 2015 -0400

    Tests: check that xlsx files are deterministic.
    
    This currently fails.

 test/Makefile.am                 |    1 +
 test/t6160-ods-deterministic.pl  |    6 +-
 test/t6161-xlsx-deterministic.pl |  105 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 109 insertions(+), 3 deletions(-)
---
diff --git a/test/Makefile.am b/test/Makefile.am
index b97e416..e50244f 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -77,6 +77,7 @@ TESTS =       t1000-statfuns.pl                       \
        t6151-gnumeric-syntax.pl                \
        t6152-xlsx-syntax.pl                    \
        t6160-ods-deterministic.pl              \
+       t6161-xlsx-deterministic.pl             \
        t6500-strings.pl                        \
        t6501-numbers.pl                        \
        t6502-styles.pl                         \
diff --git a/test/t6160-ods-deterministic.pl b/test/t6160-ods-deterministic.pl
index 23492eb..8c8e9ae 100755
--- a/test/t6160-ods-deterministic.pl
+++ b/test/t6160-ods-deterministic.pl
@@ -11,7 +11,7 @@ my $format = "Gnumeric_OpenCalc:odf";
 my $unzip = &GnumericTest::find_program ("unzip");
 
 my @sources = &GnumericTest::corpus();
-# datefuns and docs-samples use NOW(); the rest takes too long.
+# datefuns and docs-samples use NOW(); the rest take too long.
 @sources = grep { !m{(^|/)(datefuns\.xls|(docs-samples|crlibm|gamma)\.gnumeric)$} } @sources;
 
 my $nskipped = 0;
@@ -68,11 +68,11 @@ foreach my $src (@sources) {
        # May contain time stamp.
        next if $member eq 'meta.xml';
 
-       my $cmd1 = "$unzip -p $tmp1 $member";
+       my $cmd1 = &GnumericTest::quotearg ($unzip, "-p", $tmp1, $member);
        print STDERR "# $cmd1\n" if $GnumericTest::verbose;
        my $data1 = `$cmd1`;
 
-       my $cmd2 = "$unzip -p $tmp2 $member";
+       my $cmd2 = &GnumericTest::quotearg ($unzip, "-p", $tmp2, $member);
        print STDERR "# $cmd2\n" if $GnumericTest::verbose;
        my $data2 = `$cmd2`;
 
diff --git a/test/t6161-xlsx-deterministic.pl b/test/t6161-xlsx-deterministic.pl
new file mode 100755
index 0000000..716b388
--- /dev/null
+++ b/test/t6161-xlsx-deterministic.pl
@@ -0,0 +1,105 @@
+#!/usr/bin/perl -w
+# -----------------------------------------------------------------------------
+
+use strict;
+use lib ($0 =~ m|^(.*/)| ? $1 : ".");
+use GnumericTest;
+
+&message ("Check that the xlsx exporter produces the same results every time.");
+
+my $format = "Gnumeric_Excel:xlsx";
+my $unzip = &GnumericTest::find_program ("unzip");
+
+my @sources = &GnumericTest::corpus();
+# datefuns and docs-samples use NOW(); the rest take too long.
+ sources = grep { !m{(^|/)(datefuns\.xls|(docs-samples|crlibm|gamma)\.gnumeric)$} } @sources;
+
+my $nskipped = 0;
+my $ngood = 0;
+my $nbad = 0;
+
+foreach my $src (@sources) {
+    if (!-r $src) {
+       $nskipped++;
+       next;
+    }
+
+    print STDERR "Checking $src\n";
+
+    my %members;
+    my @tmp;
+    foreach my $i (1, 2) {
+       my $tmp = $src;
+       $tmp =~ s|^.*/||;
+       $tmp =~ s|\..*|-$i.xlsx|;
+       &GnumericTest::junkfile ($tmp);
+       my $cmd = "$ssconvert -T $format $src $tmp";
+       print STDERR "# $cmd\n" if $GnumericTest::verbose;
+       system ($cmd);
+       if (!-r $tmp) {
+           print STDERR "ssconvert failed to produce $tmp\n";
+           die "Fail\n";
+       }
+
+       foreach (`$unzip -v $tmp`) {
+           next unless /^----/ ... /^----/;
+           next unless m{^\s*\d.*\s(\S+)$};
+           my $member = $1;
+           if (($members{$member} || 0) & $i) {
+               print STDERR "Duplicate member $member\n";
+               die "Fail\n";
+           }
+           $members{$member} += $i;
+       }
+
+       push @tmp, $tmp;
+    }
+
+    my $tmp1 = $tmp[0];
+    my $tmp2 = $tmp[1];
+
+    foreach my $member (sort keys %members) {
+       if ($members{$member} != 3) {
+           print STDERR "Member $member is not in both files.\n";
+           $nbad++;
+           next;
+       }
+
+       # unzip trouble
+       next if $member eq '[Content_Types].xml';
+
+       # May contain timestamp
+       next if $member eq 'docProps/core.xml';
+
+       my $cmd1 = &GnumericTest::quotearg ($unzip, "-p", $tmp1, $member);
+       print STDERR "# $cmd1\n" if $GnumericTest::verbose;
+       my $data1 = `$cmd1`;
+
+       my $cmd2 = &GnumericTest::quotearg ($unzip, "-p", $tmp2, $member);
+       print STDERR "# $cmd2\n" if $GnumericTest::verbose;
+       my $data2 = `$cmd2`;
+
+       if ($data1 ne $data2) {
+           print STDERR "Member $member is different between two files.\n";
+           $nbad++;
+           next;
+       }
+
+       $ngood++;
+    }
+
+    &GnumericTest::removejunk ($tmp1);
+    &GnumericTest::removejunk ($tmp2);
+}
+
+&GnumericTest::report_skip ("No source files present") if $nbad + $ngood == 0;
+
+if ($nskipped > 0) {
+    print STDERR "$nskipped files skipped.\n";
+}
+
+if ($nbad > 0) {
+    die "Fail\n";
+} else {
+    print STDERR "Pass\n";
+}


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