[gnumeric] Tests: test ods files against schema



commit 8a4b457ceca725414ddf53066922cb80fce8c588
Author: Morten Welinder <terra gnome org>
Date:   Wed Mar 5 16:53:57 2014 -0500

    Tests: test ods files against schema

 test/GnumericTest.pm     |   17 ++++++++
 test/Makefile.am         |    1 +
 test/t6150-ods-syntax.pl |   93 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 111 insertions(+), 0 deletions(-)
---
diff --git a/test/GnumericTest.pm b/test/GnumericTest.pm
index 3938356..662b470 100644
--- a/test/GnumericTest.pm
+++ b/test/GnumericTest.pm
@@ -113,6 +113,23 @@ sub dump_indented {
     print STDERR $txt;
 }
 
+sub find_program {
+    my ($p) = @_;
+
+    if ($p =~ m{/}) {
+       return $p if -x $p;
+    } else {
+       my $PATH = exists $ENV{'PATH'} ? $ENV{'PATH'} : '';
+       foreach my $dir (split (':', $PATH)) {
+           $dir = '.' if $dir eq '';
+           my $tentative = "$dir/$p";
+           return $tentative if -x $tentative;
+       }
+    }
+
+    &report_skip ("$p is missing");
+}
+
 # -----------------------------------------------------------------------------
 
 sub message {
diff --git a/test/Makefile.am b/test/Makefile.am
index 423cef3..c8ee0a3 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -71,6 +71,7 @@ TESTS =       t1000-statfuns.pl                       \
        t6102-objs-ods.pl                       \
        t6103-lookfuns-ods.pl                   \
        t6104-finfuns-ods.pl                    \
+       t6150-ods-syntax.pl                     \
        t6500-strings.pl                        \
        t6501-numbers.pl                        \
        t6502-styles.pl                         \
diff --git a/test/t6150-ods-syntax.pl b/test/t6150-ods-syntax.pl
new file mode 100755
index 0000000..6eda5d0
--- /dev/null
+++ b/test/t6150-ods-syntax.pl
@@ -0,0 +1,93 @@
+#!/usr/bin/perl -w
+# -----------------------------------------------------------------------------
+
+use strict;
+use lib ($0 =~ m|^(.*/)| ? $1 : ".");
+use GnumericTest;
+
+&message ("Check that the ods exporter produces valid files.");
+
+my $format = "Gnumeric_OpenCalc:openoffice";
+my $schema = $ENV{'HOME'} . "/Download/OpenDocument-v1.2-os-schema.rng";
+&GnumericTest::report_skip ("Cannot find schema") unless -r $schema;
+
+my $xmllint = &GnumericTest::find_program ("xmllint");
+my $unzip = &GnumericTest::find_program ("unzip");
+
+my @sources =
+    ("$samples/excel/address.xls",
+     "$samples/excel/bitwise.xls",
+     "$samples/excel/chart-tests-excel.xls",
+     "$samples/excel/datefuns.xls",
+     "$samples/excel/dbfuns.xls",
+     "$samples/excel/engfuns.xls",
+     "$samples/excel/finfuns.xls",
+     "$samples/excel/functions.xls",
+     "$samples/excel/infofuns.xls",
+     "$samples/excel/logfuns.xls",
+     "$samples/excel/lookfuns2.xls",
+     "$samples/excel/lookfuns.xls",
+     "$samples/excel/mathfuns.xls",
+     "$samples/excel/objs.xls",
+     "$samples/excel/operator.xls",
+     "$samples/excel/sort.xls",
+     "$samples/excel/statfuns.xls",
+     "$samples/excel/textfuns.xls",
+     "$samples/excel/yalta2008.xls",
+     "$samples/auto-filter-tests.gnumeric",
+     "$samples/cell-comment-tests.gnumeric",
+     "$samples/colrow-tests.gnumeric",
+     "$samples/formula-tests.gnumeric",
+     "$samples/number-tests.gnumeric",
+     "$samples/page-setup-tests.gnumeric",
+     "$samples/sheet-formatting-tests.gnumeric",
+     "$samples/split-panes-tests.gnumeric",
+     "$samples/string-tests.gnumeric",
+     "$samples/style-tests.gnumeric",
+     "$samples/validation-tests.gnumeric",
+    );
+my $nskipped = 0;
+my $ngood = 0;
+my $nbad = 0;
+
+foreach my $src (@sources) {
+    if (!-r $src) {
+       $nskipped++;
+       next;
+    }
+
+    print STDERR "Checking $src\n";
+
+    my $tmp = $src;
+    $tmp =~ s|^.*/||;
+    $tmp =~ s|\..*|.ods|;
+    &GnumericTest::junkfile ($tmp);
+    system ("$ssconvert -T $format $src $tmp");
+    if (!-r $tmp) {
+       print STDERR "ssconvert failed to produce $tmp\n";
+       die "Fail\n";
+    }
+
+    for my $member ('content.xml', 'styles.xml') {
+       my $out = `$unzip -p $tmp $member | $xmllint --noout --relaxng $schema - 2>&1`;
+       if ($out !~ /^- validates$/) {
+           print STDERR "While checking $member from $tmp:\n";
+           &GnumericTest::dump_indented ($out);
+           $nbad++;
+       } else {
+           $ngood++;
+       }
+    }
+}
+
+&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]