.gnumeric: if we see a shared array formula, fix it.
[gnumeric.git] / test / t6150-ods-syntax.pl
blob347e302d4f83f4e3bd3ee2e488ca0475ba94421e
1 #!/usr/bin/perl -w
2 # -----------------------------------------------------------------------------
4 use strict;
5 use lib ($0 =~ m|^(.*/)| ? $1 : ".");
6 use GnumericTest;
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') {
24 &download ();
25 exit 0;
26 } elsif ($cmd eq 'make-schema-patch') {
27 &make_schema_patch ();
28 exit 0;
29 } elsif ($cmd eq 'make-schema-ext') {
30 &make_schema_ext ();
31 exit 0;
34 my $suggest_download = 0;
35 if (!-r $schema) {
36 print STDERR "Cannot find strict conformance schema\n";
37 $schema = undef;
38 $suggest_download = 1;
40 if (!-r $schema_ext) {
41 print STDERR "Cannot find extended conformance schema\n";
42 $schema_ext = undef;
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"
53 if $suggest_download;
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,
59 1 => $checker_ext,
60 2 => $manifest_checker);
62 my @sources = &GnumericTest::corpus();
63 # xmllint hangs on these files. (Well, amath finishes but takes too
64 # long.)
65 @sources = grep { !m{(^|/)(amath|crlibm|gamma|numtheory)\.gnumeric$} } @sources;
67 my $nskipped = 0;
68 my $ngood = 0;
69 my $nbad = 0;
71 foreach my $src (@sources) {
72 if (!-r $src) {
73 $nskipped += 2;
74 next;
77 for (my $ext = 0; $ext <= 1; $ext++) {
78 print STDERR "Checking $src (", ($ext ? "extended" : "strict"), " conformance)\n";
80 my $tmp = $src;
81 $tmp =~ s|^.*/||;
82 $tmp =~ s|\..*|.ods|;
83 &GnumericTest::junkfile ($tmp);
84 my $cmd = "$ssconvert -T " . ($ext ? $format_ext : $format) . " $src $tmp";
85 print STDERR "# $cmd\n" if $GnumericTest::verbose;
86 system ($cmd);
87 if (!-r $tmp) {
88 print STDERR "ssconvert failed to produce $tmp\n";
89 die "Fail\n";
92 my %members;
93 foreach (`$unzip -v $tmp`) {
94 next unless /^----/ ... /^----/;
95 next unless m{^\s*\d.*\s(\S+)$};
96 my $member = $1;
97 if (exists $members{$member}) {
98 print STDERR "Duplicate member $member\n";
99 die "Fail\n";
101 $members{$member} = 1;
104 my @check_members = (['content.xml',$ext],
105 ['styles.xml',$ext],
106 ['META-INF/manifest.xml',2],
107 ['settings.xml',$ext],
108 ['meta.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);
122 $nbad++;
123 } else {
124 $ngood++;
128 &GnumericTest::removejunk ($tmp);
132 &GnumericTest::report_skip ("No source files present") if $nbad + $ngood == 0;
134 if ($nskipped > 0) {
135 print STDERR "$nskipped files skipped.\n";
138 if ($nbad > 0) {
139 die "Fail\n";
140 } else {
141 print STDERR "Pass\n";
144 # -----------------------------------------------------------------------------
146 sub download {
147 my $src = "http://docs.oasis-open.org/office/v1.2/os";
149 if (!-d $schemadir) {
150 mkdir $schemadir or
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"],
162 my ($b,$sum) = @$_;
164 my $fn = "$schemadir/$b";
165 my $tmpfn = "$fn.tmp";
167 my $had_it = (-r $fn);
168 if ($had_it) {
169 print STDERR "We already have $b\n";
170 } else {
171 print STDERR "Downloading $b...\n";
172 unlink $tmpfn;
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);
183 my $act = lc ($1);
184 if ($act eq $sum) {
185 if (!$had_it) {
186 rename ($tmpfn, $fn) or
187 die "$0: Cannot rename temporary file into place: $!\n";
188 print STDERR "Download ok.\n";
190 } else {
191 print STDERR "NOTE: Expected checksum $sum, got $act.\n";
192 if (!$had_it) {
193 unlink $tmpfn;
194 print STDERR "ERROR: Download failure.\n";
195 exit 1;
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";
212 exit 1;
215 if (!-r $schema || !-r $schema_ext_patch) {
216 print STDERR "ERROR: Making extended schema requires both $schema and $schema_ext_patch\n";
217 exit 1;
220 my $cmd = &GnumericTest::quotearg ("cp", $schema, $schema_ext);
221 print STDERR "# $cmd\n";
222 system ($cmd);
224 $cmd =
225 "(cd " . &GnumericTest::quotearg ($dir) .
226 " && " .
227 &GnumericTest::quotearg ("patch", "-i", substr($schema_ext_patch,$o), substr($schema_ext,$o)) .
228 ")";
229 print STDERR "# $cmd\n";
230 system ($cmd);
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";
241 exit 1;
244 my $cmd =
245 "(cd " . &GnumericTest::quotearg ($dir) .
246 " && " .
247 &GnumericTest::quotearg ("diff", "-u", substr($schema,$o), substr($schema_ext,$o)) .
248 " >" . &GnumericTest::quotearg (substr($schema_ext_patch,$o)) .
249 ")";
250 print STDERR "# $cmd\n";
251 system ($cmd);
254 # -----------------------------------------------------------------------------