2 # -----------------------------------------------------------------------------
5 use lib
($0 =~ m
|^(.*/)| ?
$1 : ".");
8 &message
("Check that the ods exporter produces valid files.");
10 my $xmllint = &GnumericTest
::find_program
("xmllint");
11 my $unzip = &GnumericTest
::find_program
("unzip");
13 my $format = "Gnumeric_OpenCalc:openoffice";
14 my $format_ext = "Gnumeric_OpenCalc:odf";
16 my $schemadir = "$topsrc/test/ods-schema";
17 my $schema = "$schemadir/OpenDocument-v1.2-os-schema.rng";
18 my $schema_ext = "$schemadir/OpenDocument-v1.2-os-ext-schema.rng";
19 my $schema_manifest = "$schemadir/OpenDocument-v1.2-os-manifest-schema.rng";
20 my $schema_ext_patch = "$topsrc/test/ods-ext-schema.patch";
22 my $cmd = ($ARGV[0] || '-');
23 if ($cmd eq 'download') {
26 } elsif ($cmd eq 'make-schema-patch') {
27 &make_schema_patch
();
29 } elsif ($cmd eq 'make-schema-ext') {
34 my $suggest_download = 0;
36 print STDERR
"Cannot find strict conformance schema\n";
38 $suggest_download = 1;
40 if (!-r
$schema_ext) {
41 print STDERR
"Cannot find extended conformance schema\n";
43 # This is not a schema supplied by oasis
44 $suggest_download = 1;
46 if (!-r
$schema_manifest) {
47 print STDERR
"Cannot find manifest schema\n";
48 $schema_manifest = undef;
49 $suggest_download = 1;
52 print STDERR
"NOTE: Suggest rerunning with argument \"download\" to obtain missing schemas\n"
55 my $checker = "$xmllint --noout" . ($schema ?
" --relaxng $schema" : "");
56 my $checker_ext = "$xmllint --noout" . ($schema_ext ?
" --relaxng $schema_ext" : "");
57 my $manifest_checker = "$xmllint --noout" . ($schema_manifest ?
" --relaxng $schema_manifest" : "");
58 my %checkers = ( 0 => $checker,
60 2 => $manifest_checker);
62 my @sources = &GnumericTest
::corpus
();
63 # xmllint hangs on these files. (Well, amath finishes but takes too
65 @sources = grep { !m{(^|/)(amath|crlibm|gamma|numtheory)\.gnumeric$} } @sources;
71 foreach my $src (@sources) {
77 for (my $ext = 0; $ext <= 1; $ext++) {
78 print STDERR
"Checking $src (", ($ext ?
"extended" : "strict"), " conformance)\n";
83 &GnumericTest
::junkfile
($tmp);
84 my $cmd = "$ssconvert -T " . ($ext ?
$format_ext : $format) . " $src $tmp";
85 print STDERR
"# $cmd\n" if $GnumericTest::verbose
;
88 print STDERR
"ssconvert failed to produce $tmp\n";
93 foreach (`$unzip -v $tmp`) {
94 next unless /^----/ ... /^----/;
95 next unless m{^\s*\d.*\s(\S+)$};
97 if (exists $members{$member}) {
98 print STDERR
"Duplicate member $member\n";
101 $members{$member} = 1;
104 my @check_members = (['content.xml',$ext],
106 ['META-INF/manifest.xml',2],
107 ['settings.xml',$ext],
109 foreach my $member (sort keys %members) {
110 push @check_members, [$member,$ext] if $member =~ m{^Graph\d+/content.xml$};
113 for (@check_members) {
114 my ($member,$typ) = @
$_;
115 my $this_checker = $checkers{$typ};
116 my $cmd = "$unzip -p $tmp $member | $this_checker --noout -";
117 print STDERR
"# $cmd\n" if $GnumericTest::verbose
;
118 my $out = `$cmd 2>&1`;
119 if ($out ne '' && $out !~ /^- validates$/) {
120 print STDERR
"While checking $member from $tmp:\n";
121 &GnumericTest
::dump_indented
($out);
128 &GnumericTest
::removejunk
($tmp);
132 &GnumericTest
::report_skip
("No source files present") if $nbad + $ngood == 0;
135 print STDERR
"$nskipped files skipped.\n";
141 print STDERR
"Pass\n";
144 # -----------------------------------------------------------------------------
147 my $src = "http://docs.oasis-open.org/office/v1.2/os";
149 if (!-d
$schemadir) {
151 die "$0: Cannot create directory $schemadir\n";
154 my $curl = &GnumericTest
::find_program
("curl");
155 my $sha1sum = &GnumericTest
::find_program
("sha1sum");
157 foreach ([scalar &File
::Basename
::fileparse
($schema),
158 "adc746cbb415ac3a17199442a15b38a5858fc7ef"],
159 [scalar &File
::Basename
::fileparse
($schema_manifest),
160 "661ab5bc695f9a8266e89cdf2747d8d76eacfedf"],
164 my $fn = "$schemadir/$b";
165 my $tmpfn = "$fn.tmp";
167 my $had_it = (-r
$fn);
169 print STDERR
"We already have $b\n";
171 print STDERR
"Downloading $b...\n";
174 my $cmd = "$curl -s -S -o $tmpfn $src/$b";
175 print STDERR
"# $cmd\n";
176 my $code = system ("$cmd 2>&1 | sed -e 's/^/| /' ");
177 &GnumericTest
::system_failure
($curl, $code) if $code;
180 my $cmd = &GnumericTest
::quotearg
($sha1sum, ($had_it ?
$fn : $tmpfn));
181 my $out = `$cmd 2>&1`;
182 die "$0: Unexpected output from $sha1sum\n" unless ($out =~ /^([a-f0-9]{40})\b/i);
186 rename ($tmpfn, $fn) or
187 die "$0: Cannot rename temporary file into place: $!\n";
188 print STDERR
"Download ok.\n";
191 print STDERR
"NOTE: Expected checksum $sum, got $act.\n";
194 print STDERR
"ERROR: Download failure.\n";
200 &make_schema_ext
() unless -e
$schema_ext;
203 # -----------------------------------------------------------------------------
205 sub make_schema_ext
{
206 my $dir = "$topsrc/test";
207 my $o = length ($dir) + 1;
209 if (-e
$schema_ext) {
210 print STDERR
"ERROR: Extended schema already exists.\n";
211 print STDERR
"If you really want to update it, remove it first.\n";
215 if (!-r
$schema || !-r
$schema_ext_patch) {
216 print STDERR
"ERROR: Making extended schema requires both $schema and $schema_ext_patch\n";
220 my $cmd = &GnumericTest
::quotearg
("cp", $schema, $schema_ext);
221 print STDERR
"# $cmd\n";
225 "(cd " . &GnumericTest
::quotearg
($dir) .
227 &GnumericTest
::quotearg
("patch", "-i", substr($schema_ext_patch,$o), substr($schema_ext,$o)) .
229 print STDERR
"# $cmd\n";
233 # -----------------------------------------------------------------------------
235 sub make_schema_patch
{
236 my $dir = "$topsrc/test";
237 my $o = length ($dir) + 1;
239 if (!-r
$schema || !-r
$schema_ext) {
240 print STDERR
"ERROR: Making patch requires both $schema and $schema_ext\n";
245 "(cd " . &GnumericTest
::quotearg
($dir) .
247 &GnumericTest
::quotearg
("diff", "-u", substr($schema,$o), substr($schema_ext,$o)) .
248 " >" . &GnumericTest
::quotearg
(substr($schema_ext_patch,$o)) .
250 print STDERR
"# $cmd\n";
254 # -----------------------------------------------------------------------------