Name Date Size #Lines LOC

..--

baseline/H--3,1473,139

fixtures/H--21,22018,451

tools13/H--440330

.gitignoreH A D05-Nov-2026128 109

README.mdH A D19-Nov-202613 KiB219170

calcval-cases.tsvH A D30-Oct-202626.5 KiB268267

calcval-cases14.tsvH A D19-Nov-202687.1 KiB485483

calcval.pyH A D19-Nov-202611.5 KiB293224

cmp7.pyH A D06-Nov-202616.3 KiB231211

compare.pyH A D30-Oct-20261.6 KiB3713

consumer_smoke.pyH A D03-Nov-20264.3 KiB8452

convert.pyH A D30-Oct-20262.3 KiB5732

cov_corpus.pyH A D30-Oct-20263.6 KiB9559

cov_report.pyH A D30-Oct-20264.6 KiB10358

cov_schema.pyH A D30-Oct-20268.1 KiB221177

cov_source.pyH A D30-Oct-202627.6 KiB654569

crosscheck.pyH A D30-Oct-20267.7 KiB140101

decrypt.pyH A D30-Oct-202616 KiB402328

diff7.pyH A D30-Oct-20261.7 KiB2926

doctypecheck.pyH A D30-Oct-20268.4 KiB190143

drive.shH A D03-Nov-20262.8 KiB5126

dump14.pyH A D03-Nov-20268 KiB211159

dump7.pyH A D30-Oct-202616.7 KiB261251

env.shH A D30-Oct-20261.4 KiB317

fetch-odfvalidator.shH A D30-Oct-20261.5 KiB317

fetch-schemas.shH A D30-Oct-20262.7 KiB4520

foreign.pyH A D30-Oct-20266.6 KiB151109

formula-cases.tsvH A D30-Oct-20268.4 KiB173172

formulacheck.pyH A D30-Oct-202620.4 KiB586501

gate-fixtures.tsvH A D30-Oct-20263.8 KiB8887

gate-volatile.tsvH A D03-Nov-20261.5 KiB1716

gate.pyH A D03-Nov-202624.5 KiB461378

idcheck.pyH A D30-Oct-20263.6 KiB8550

isoweeknum_rt.pyH A D19-Nov-20263.9 KiB9957

make-controls.pyH A D03-Nov-20268.1 KiB10057

make-doctype-controls.pyH A D30-Oct-20265.7 KiB9257

make-jobs.shH A D30-Oct-20261.6 KiB329

make-pkg-controls.pyH A D30-Oct-20266.6 KiB10265

pkgcheck.pyH A D30-Oct-20269.7 KiB187145

refresh-app.shH A D30-Oct-20261.6 KiB339

report.pyH A D03-Nov-20262.1 KiB4518

roundtrip.pyH A D30-Oct-20262.3 KiB5829

runpy.shH A D30-Oct-20261.2 KiB274

selftest.pyH A D03-Nov-202618.6 KiB214191

setup-app.shH A D30-Oct-20261.6 KiB3713

smoke13-known.tsvH A D30-Oct-2026483 54

smoke13.pyH A D30-Oct-20267.3 KiB142101

start.shH A D30-Oct-20261.4 KiB307

unohelp.pyH A D30-Oct-20262.3 KiB6027

validate.pyH A D03-Nov-20265.9 KiB11377

README.md

1<!--
2 Licensed to the Apache Software Foundation (ASF) under one
3 or more contributor license agreements.  See the NOTICE file
4 distributed with this work for additional information
5 regarding copyright ownership.  The ASF licenses this file
6 to you under the Apache License, Version 2.0 (the
7 "License"); you may not use this file except in compliance
8 with the License.  You may obtain a copy of the License at
9
10   http://www.apache.org/licenses/LICENSE-2.0
11
12 Unless required by applicable law or agreed to in writing,
13 software distributed under the License is distributed on an
14 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 KIND, either express or implied.  See the License for the
16 specific language governing permissions and limitations
17 under the License.
18-->
19
20# ODF validation harness
21
22This harness has OpenOffice save a corpus of documents as ODF, checks every
23saved package against the OASIS ODF 1.2, ODF 1.3 and ODF 1.4 RELAX NG schemas with
24jing, and reports the errors grouped by kind. Comparing those reports against
25a baseline shows whether an export change fixed errors or introduced new ones.
26
27It runs on macOS only (zsh scripts, `hdiutil`, `.app` layout).
28
29## Requirements
30
31- An AOO macOS build (`.dmg`).
32- The Python that the office's pyuno links against. Check with
33  `otool -L <app>/Contents/program/libpyuno.dylib`, then set `ODFV_PYTHON`.
34- `jing.jar` (set `ODFV_JING`) and `java`; `ODFV_ODFVALIDATOR` and `ODFV_JAVA` for `crosscheck.py`.
35- `gtimeout` (GNU coreutils), used by `drive.sh`.
36
37Defaults for `ODFV_APP`, `ODFV_PYTHON`, `ODFV_JING` and `ODFV_SOLVER` are in
38`env.sh`.
39
40## Setup
41
42    ./fetch-schemas.sh                 # OASIS schemas, checksum-verified, into schema/
43    ./setup-app.sh <path-to-AOO.dmg>   # copies OpenOffice.app into app/
44    ./fetch-odfvalidator.sh            # optional: odfvalidator for crosscheck.py
45    python3 -I selftest.py             # validator negative controls
46
47The schemas are not committed because they carry OASIS copyright terms.
48
49## Running a corpus
50
51    ./make-jobs.sh runs/base_strict/out > runs/base_strict/jobs.tsv
52    ./drive.sh strict 2013 runs/base_strict/jobs.tsv runs/base_strict/done.tsv
53    python3 -I validate.py runs/base_strict/out runs/base_strict/val.json
54    python3 -I report.py runs/base_strict/val.json baseline/strict.kinds.json 12
55
56The steps:
57
58- `make-jobs.sh` collects the test documents under `main/` (doc, docx, rtf,
59  xls, ppt, sx*, od*).
60- `drive.sh <ext|strict> <port> <jobs> <done>` saves them in ODF
61  1.2 Extended (`DefaultVersion=3`) or strict ODF 1.2 (`DefaultVersion=4`).
62  - It runs a headless office on the given port, using a profile under `runs/`.
63  - It resumes where it left off, kills a hung office and continues, and
64    stops at the first crash.
65- `validate.py` checks content, styles, meta, settings and manifest streams
66  against 1.2 as written, against 1.3 (`13`) and 1.4 (`14`) with
67  `office:version` rewritten, and against 1.2 and 1.3 as extended documents
68  (`12x`, `13x`): `foreign.py` first removes
69  foreign elements and attributes as Part 1 §2.2.2 B.1 and §3.17 describe (the
70  manifest is left as written). Use `report.py <val.json> <kinds.json> 12x` to
71  measure what is wrong apart from foreign content.
72  Embedded objects whose `content.xml` is MathML are skipped (ODF 1.2 Part 1
73  §2.2.1 B.4).
74- `report.py` groups the errors by normalized message.
75- `pkgcheck.py <outdir> <pkg.json>` checks the ODF 1.2 Part 3 package rules
76  (§2.2.1, 3.2, 3.3, 3.4.1): zip methods, `mimetype` first / stored / no extra
77  field / equal to the `/` media type, one manifest entry per file, META-INF
78  contents, `manifest:size` and STORED on encrypted entries, and signature
79  files (well-formed, root, `OpenDocument-v1.2-os-dsig-schema.rng`). Findings
80  are `shall:` or `should:`; only `shall` findings are non-conformances.
81- `doctypecheck.py <outdir> <dt.json>` checks Part 1 §2.2.1 A.2/E and
82  §2.2.3-2.2.10: the `mimetype` file (or `office:mimetype` of a flat file), the
83  root element and the `office:body` child must agree on one document type.
84  Embedded sub documents are compared with their manifest media type
85  (`should:` findings). Two deviations from the literal text of §2.2.5: it
86  spells the drawing values `application.vnd.oasis.opendocument.graphics` and
87  `...graphic-template`; the registered `...graphics` and `...graphics-template`
88  of Part 1 appendix C are accepted. `...text-web` and `...formula-template`
89  are registered but no §2.2.x allows them, so they are reported.
90- `formulacheck.py <outdir> <formulas.json>` parses the `style:condition`,
91  `table:condition`, `table:expression`, `table:formula` and `text:formula`
92  values (Part 1 §2.2.1 D.3, §2.2.4 D/E) with the OpenFormula grammar (Part 2
93  chapter 5) and the condition syntaxes of Part 1 §19.468 and §19.596.
94  - Syntax only; no semantics, function arity or type checking.
95  - A prefix bound to another namespace is out of Part 2's reach: `should:` in
96    general, `shall:` for `table:formula` inside `office:spreadsheet` (§2.2.4 D).
97  - Non-ASCII name characters use Unicode categories instead of the XML 1.0
98    4th edition tables; an IRI is checked by character class, not the full
99    RFC 3987 grammar; `openformula-functions.txt` holds the Part 2 function
100    names.
101  - The condition syntaxes follow the prose of Part 1, which has no grammar:
102    `,` between arguments, lowercase ` and `, `!=` as the relational operator.
103  - `formula-cases.tsv` is the table of good and bad values that `selftest.py`
104    runs.
105- `crosscheck.py <outdir> <val.json> <cross.json>` runs the Apache ODF Toolkit
106  `odfvalidator` 1.1.8 (`fetch-odfvalidator.sh`; MSV instead of jing, the same
107  OASIS schemas) in conformance mode (`-c`) and extended mode (`-e`) and
108  compares each stream with the `12` and `12x` results of `validate.py`.
109  - Error counts differ between engines; it compares whether a stream has
110    any error and, in `-c` mode, where its first error is.
111  - It exits if odfvalidator stops before finishing every package. Its
112    failures are silent (an invalid schema prints "Validation aborted"; a
113    crash on one package aborts the run): crashes are skipped and listed.
114  - odfvalidator's own schema lookup fails on current JDKs, so the schemas are
115    passed explicitly; its jar has no MathML 2 schema, so a schema that accepts
116    anything stands in (as `validate.py` skips MathML).
117  - Known leniencies: it truncates a `draw:points` over 2048 characters and
118    adapts old OOo namespaces. It is stricter than Part 3 §3.2 in wanting
119    `META-INF/documentsignatures.xml` listed in the manifest. It checks ID
120    uniqueness, which `jing -i` does not.
121- `fixtures/doctypes/` (`run.sh`, `make.py`, `derive-chart.py`), `fixtures/encrypted/`, `fixtures/signed/`, `fixtures/base/`: documents
122  of the kinds the corpus lacks (templates, master, Writer/Web, Impress as Draw, Math, chart, encrypted, signed, Base), saved
123  in strict and extended mode under `runs/task12/gen-*`. `decrypt.py <in-dir> <out-dir> <password>` writes plain copies of
124  encrypted packages for the schema checkers; `pkgcheck.py` must still run on the real ones. Signing needs a visible
125  (`-invisible`) office because `-headless` cancels the dialog: see the header of `fixtures/signed/make.py`.
126- `fixtures/{writer,calc,draw,chart,styles-text,styles-gfx,leak}/make.py`, run with `fixtures/gen-run.sh <area> <strict|ext> <port> <abs-outdir>`:
127  documents built through UNO to exercise the elements, attributes and enumerated values that `cov_report.py` lists as gaps
128  (`leak` classifies the names AOO emits that the schema does not define). Use an absolute `<outdir>`.
129- `cov_schema.py`, `cov_source.py`, `cov_corpus.py`, `cov_report.py`: schema-coverage report. The schema universe
130  (ODF 1.2 elements, element/attribute pairs, enumerated values), the names the export code in `main/` can emit (static
131  C++ scan; a lower bound, table-driven names are missed) and what a corpus exercises are joined by namespace URI and
132  local name into the gaps worth generating documents for. Outputs live under `runs/`.
133- `idcheck.py <outdir> <ids.json>` parses every stream namespace-aware and
134  checks `xml:id` syntax and uniqueness per stream (ODF 1.2 Part 1 §2.2.1
135  D.1, D.2). `jing -i` does not check ID uniqueness.
136
137## The regression gate
138
139    python3 -I gate.py <tag> --prev runs/gate-<earlier tag>      # everything
140    python3 -I gate.py <tag> --build xmloff,sw --prev ...        # rebuild first
141    python3 -I gate.py smoke --limit 8 --prev ... --stages corpus,validate,dump,diff
142
143`gate.py` runs the stages below in `runs/gate-<tag>/`, records `results.json`,
144skips stages already done (`--force` reruns) and exits 0 only if everything
145that ran passed.
146
147| stage | does | passes if |
148|---|---|---|
149| `build` | `build.pl` and `deliver.pl` for the `--build` modules (environment script: `ODFV_BUILD_ENV`) | exit codes 0 |
150| `refresh` | copies `--libs` from the solver into `app/` (`refresh-app.sh`) | copies identical |
151| `corpus` | saves the job list in `ext` and `strict` mode | no crash, every job accounted for, OK/FAIL counts equal `--prev` |
152| `validate` | `validate.py`, `report.py` and the four checkers per mode | kinds not worse than `baseline/<mode>.kinds.json` or than `--prev` (checked both ways); all four checkers ran; no `shall` finding from the id, package and document-type checkers; formula findings not above `--prev`; a baseline or `--prev` exists |
153| `dump` | reloads every saved package with `dump7.py` | no office failure; hangs and crashes are listed |
154| `diff` | `diff7.py` on the dumps and `cmp7.py` on the packages against `--prev` | every difference is a document in `gate-volatile.tsv` |
155| `fixtures` | `gate-fixtures.tsv`: saves in `v00 v10 v11 ext strict`, runs the reload checks, validates | saved, checked, and unchanged against `--prev`; the same checker rules as `validate` (formula findings are compared per mode with `--prev`) |
156
157- Inputs are frozen: without `--jobs` the list of `--prev` is reused (outputs
158  are rewritten), so the same documents are saved when files under `main/`
159  change. A later run's `--prev` may be any earlier gate directory or a
160  directory with the same layout (`<mode>/out`, `<mode>/dump`).
161- The dump stage kills the office only when the dump makes no progress for
162  `--stall` seconds (default 300), then writes a `HANG` marker for that
163  document alone. A long batch that keeps progressing is never killed.
164- `gate-volatile.tsv` names the documents whose dumps differ between runs
165  without an export change (volatile Calc formulas, redline timestamps, the
166  `0238` loader order, the intermittent Basic library loss of `0048`). A new
167  entry needs a reason.
168- `baseline/` holds kinds for `ext`, `strict`, `x14` and an empty `v14`; there is none for `v13` or `x13`, so a first gate
169  with those modes needs `--prev`.
170- The first fixtures run has nothing to compare with: its mismatch pattern is
171  only recorded. By design, strict, ODF 1.0 and ODF 1.1 mode fail the 14
172  reload rows that need gradient or transparency fills.
173
174## Checking a change
175
176    python3 -I compare.py baseline/strict.kinds.json runs/new/strict.kinds.json
177
178`compare.py` exits 1 if any kind is new or any kind got worse.
179
180To test a rebuilt module without repackaging, copy its libraries from the
181solver into the app copy:
182
183    ./refresh-app.sh libxo.dylib
184
185`roundtrip.py <port> <file> <checks.json>` loads a document and compares UNO
186expressions with expected values; `--capture <out.json>` records them instead.
187
188`isoweeknum_rt.py <port> <outdir>` saves ISOWEEKNUM and WEEKNUM formulas to an
189ODS, checks the saved `table:formula` strings, reloads it and checks that each
190formula and value comes back unchanged.
191
192## Formula evaluation baseline (calcval)
193
194    ./start.sh calcval 2792
195    ./runpy.sh calcval.py 2792 calcval-cases.tsv runs/phase4/baseline.json
196    python3 -I calcval.py --compare runs/phase4/baseline.json runs/phase4/new.json
197
198`calcval.py` opens a new Calc document, writes the data area described in the
199header of `calcval-cases.tsv`, and for each case enters the formula in a fresh
200scratch cell (`cell`, `cell@N`) or range (`array:CxR`), recalculates, records
201the result type, `getError()`, `getString()`, `getValue()` and the formula as
202read back, then clears the scratch area. `expected` is the value the ODF 1.3
203Part 4 text requires (`-` records the current behaviour only); the status of
204each case is `match`, `mismatch`, `record` or `exception`. The run prints
205every mismatch, which are the current deviations from ODF 1.3. `--compare`
206lists each case whose recorded result changed (exit 1 if any). RECEIVED and
207BESSELK/BESSELY are Analysis add-ins and are entered by programmatic name.
208
209## Notes
210
211- AOO has no `-convert-to`; conversion goes over UNO (`convert.py`).
212- jing must run with `-i`, otherwise it rejects the ODF schemas themselves.
213- A jing fatal error can hide later errors. Such lines are reported as
214  `UNPARSED` kinds, and `compare.py` fails on any new `UNPARSED` kind.
215- jing stops at a fatal error (a stream that is not well-formed);
216  `validate.py` records it and carries on with the remaining files.
217- `setup-app.sh` renames an existing `app/OpenOffice.app` to
218  `OpenOffice.app.old.<timestamp>` instead of deleting it.
219