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 $common_checker = "$xmllint --noout --nonet";
57 my $checker = $common_checker . ($schema ?
" --relaxng $schema" : "");
58 my $checker_ext = $common_checker . ($schema_ext ?
" --relaxng $schema_ext" : "");
59 my $manifest_checker = $common_checker . ($schema_manifest ?
" --relaxng $schema_manifest" : "");
60 my %checkers = ( 0 => $checker,
62 2 => $manifest_checker);
64 my @sources = &GnumericTest
::corpus
();
65 # xmllint hangs on these files. (Well, amath finishes but takes too
67 @sources = grep { !m{(^|/)(amath|crlibm|gamma|numtheory)\.gnumeric$} } @sources;
73 foreach my $src (@sources) {
79 for (my $ext = 0; $ext <= 1; $ext++) {
80 print STDERR
"Checking $src (", ($ext ?
"extended" : "strict"), " conformance)\n";
85 &GnumericTest
::junkfile
($tmp);
86 my $cmd = "$ssconvert -T " . ($ext ?
$format_ext : $format) . " $src $tmp";
87 print STDERR
"# $cmd\n" if $GnumericTest::verbose
;
90 print STDERR
"ssconvert failed to produce $tmp\n";
95 foreach (`$unzip -v $tmp`) {
96 next unless /^----/ ... /^----/;
97 next unless m{^\s*\d.*\s(\S+)$};
99 if (exists $members{$member}) {
100 print STDERR
"Duplicate member $member\n";
103 $members{$member} = 1;
106 my @check_members = (['content.xml',$ext],
108 ['META-INF/manifest.xml',2],
109 ['settings.xml',$ext],
111 foreach my $member (sort keys %members) {
112 push @check_members, [$member,$ext] if $member =~ m{^Graph\d+/content.xml$};
115 for (@check_members) {
116 my ($member,$typ) = @
$_;
117 my $this_checker = $checkers{$typ};
118 my $cmd = "$unzip -p $tmp $member | $this_checker --noout -";
119 print STDERR
"# $cmd\n" if $GnumericTest::verbose
;
120 my $out = `$cmd 2>&1`;
121 if ($out ne '' && $out !~ /^- validates$/) {
122 print STDERR
"While checking $member from $tmp:\n";
123 &GnumericTest
::dump_indented
($out);
130 &GnumericTest
::removejunk
($tmp);
134 &GnumericTest
::report_skip
("No source files present") if $nbad + $ngood == 0;
137 print STDERR
"$nskipped files skipped.\n";
143 print STDERR
"Pass\n";
146 # -----------------------------------------------------------------------------
149 my $src = "http://docs.oasis-open.org/office/v1.2/os";
151 if (!-d
$schemadir) {
153 die "$0: Cannot create directory $schemadir\n";
156 my $curl = &GnumericTest
::find_program
("curl");
157 my $sha1sum = &GnumericTest
::find_program
("sha1sum");
159 foreach ([scalar &File
::Basename
::fileparse
($schema),
160 "adc746cbb415ac3a17199442a15b38a5858fc7ef"],
161 [scalar &File
::Basename
::fileparse
($schema_manifest),
162 "661ab5bc695f9a8266e89cdf2747d8d76eacfedf"],
166 my $fn = "$schemadir/$b";
167 my $tmpfn = "$fn.tmp";
169 my $had_it = (-r
$fn);
171 print STDERR
"We already have $b\n";
173 print STDERR
"Downloading $b...\n";
176 my $cmd = "$curl -s -S -o $tmpfn $src/$b";
177 print STDERR
"# $cmd\n";
178 my $code = system ("$cmd 2>&1 | sed -e 's/^/| /' ");
179 &GnumericTest
::system_failure
($curl, $code) if $code;
182 my $cmd = &GnumericTest
::quotearg
($sha1sum, ($had_it ?
$fn : $tmpfn));
183 my $out = `$cmd 2>&1`;
184 die "$0: Unexpected output from $sha1sum\n" unless ($out =~ /^([a-f0-9]{40})\b/i);
188 rename ($tmpfn, $fn) or
189 die "$0: Cannot rename temporary file into place: $!\n";
190 print STDERR
"Download ok.\n";
193 print STDERR
"NOTE: Expected checksum $sum, got $act.\n";
196 print STDERR
"ERROR: Download failure.\n";
202 &make_schema_ext
() unless -e
$schema_ext;
205 # -----------------------------------------------------------------------------
207 sub make_schema_ext
{
208 my $dir = "$topsrc/test";
209 my $o = length ($dir) + 1;
211 if (-e
$schema_ext) {
212 print STDERR
"ERROR: Extended schema already exists.\n";
213 print STDERR
"If you really want to update it, remove it first.\n";
217 if (!-r
$schema || !-r
$schema_ext_patch) {
218 print STDERR
"ERROR: Making extended schema requires both $schema and $schema_ext_patch\n";
222 my $cmd = &GnumericTest
::quotearg
("cp", $schema, $schema_ext);
223 print STDERR
"# $cmd\n";
227 "(cd " . &GnumericTest
::quotearg
($dir) .
229 &GnumericTest
::quotearg
("patch", "-i", substr($schema_ext_patch,$o), substr($schema_ext,$o)) .
231 print STDERR
"# $cmd\n";
235 # -----------------------------------------------------------------------------
237 sub make_schema_patch
{
238 my $dir = "$topsrc/test";
239 my $o = length ($dir) + 1;
241 if (!-r
$schema || !-r
$schema_ext) {
242 print STDERR
"ERROR: Making patch requires both $schema and $schema_ext\n";
247 "(cd " . &GnumericTest
::quotearg
($dir) .
249 &GnumericTest
::quotearg
("diff", "-u", substr($schema,$o), substr($schema_ext,$o)) .
250 " >" . &GnumericTest
::quotearg
(substr($schema_ext_patch,$o)) .
252 print STDERR
"# $cmd\n";
256 # -----------------------------------------------------------------------------