This is an automated email from the ASF dual-hosted git repository. jimjag pushed a commit to branch odf13-devel in repository https://gitbox.apache.org/repos/asf/openoffice.git
commit 6a2b4695f05f289749fa5389de1606be0871b531 Author: Jim Jagielski <[email protected]> AuthorDate: Fri Oct 30 09:58:18 2026 -0400 test/odf-validate: Add the ODF 1.3 fixtures and the v13 and x13 modes to gen-run.sh --- test/odf-validate/fixtures/gen-run.sh | 4 +- test/odf-validate/fixtures/t13/annot.odt | Bin 0 -> 8779 bytes test/odf-validate/fixtures/t13/chart.ods | Bin 0 -> 13595 bytes test/odf-validate/fixtures/t13/checks-annot.json | 36 +++++ test/odf-validate/fixtures/t13/checks-chart.json | 48 ++++++ .../odf-validate/fixtures/t13/checks-dropdown.json | 67 +++++++++ test/odf-validate/fixtures/t13/checks-scaleto.json | 52 +++++++ .../odf-validate/fixtures/t13/checks-tabcolor.json | 22 +++ test/odf-validate/fixtures/t13/dropdown.odt | Bin 0 -> 8761 bytes test/odf-validate/fixtures/t13/make.py | 165 +++++++++++++++++++++ test/odf-validate/fixtures/t13/scaleto.ods | Bin 0 -> 8172 bytes test/odf-validate/fixtures/t13/tabcolor.ods | Bin 0 -> 7837 bytes test/odf-validate/gate-fixtures.tsv | 5 + 13 files changed, 397 insertions(+), 2 deletions(-) diff --git a/test/odf-validate/fixtures/gen-run.sh b/test/odf-validate/fixtures/gen-run.sh index 08c0c83cfc..00f90a3b69 100755 --- a/test/odf-validate/fixtures/gen-run.sh +++ b/test/odf-validate/fixtures/gen-run.sh @@ -17,11 +17,11 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. -# usage: fixtures/gen-run.sh <area> <strict|ext> <port> <outdir> +# usage: fixtures/gen-run.sh <area> <strict|ext|v13|x13> <port> <outdir> # Starts a headless office saving in the given ODF mode (profile created as drive.sh does), runs fixtures/<area>/make.py <port> <outdir>, stops it. source ${0:A:h:h}/env.sh area=$1; mode=$2; port=$3; out=$4 -case $mode in ext) v=3;; strict) v=4;; *) echo "gen-run.sh: unknown mode $mode" >&2; exit 2;; esac +case $mode in ext) v=3;; strict) v=4;; v13) v=5;; x13) v=6;; *) echo "gen-run.sh: unknown mode $mode" >&2; exit 2;; esac [[ -f $D/fixtures/$area/make.py ]] || { echo "gen-run.sh: no fixtures/$area/make.py" >&2; exit 2; } prof=t12_${area}_$mode /bin/rm -rf $D/runs/profile_$prof diff --git a/test/odf-validate/fixtures/t13/annot.odt b/test/odf-validate/fixtures/t13/annot.odt new file mode 100644 index 0000000000..a2f8f3e5c2 Binary files /dev/null and b/test/odf-validate/fixtures/t13/annot.odt differ diff --git a/test/odf-validate/fixtures/t13/chart.ods b/test/odf-validate/fixtures/t13/chart.ods new file mode 100644 index 0000000000..68b1e9f50d Binary files /dev/null and b/test/odf-validate/fixtures/t13/chart.ods differ diff --git a/test/odf-validate/fixtures/t13/checks-annot.json b/test/odf-validate/fixtures/t13/checks-annot.json new file mode 100644 index 0000000000..691abcfe28 --- /dev/null +++ b/test/odf-validate/fixtures/t13/checks-annot.json @@ -0,0 +1,36 @@ +[ + { + "name": "ann_count", + "expr": "len([f for f in (lambda e: [e.nextElement() for _ in iter(e.hasMoreElements, False)])(doc.TextFields.createEnumeration()) if f.supportsService('com.sun.star.text.textfield.Annotation')])", + "expect": 2 + }, + { + "name": "ann_initials", + "expr": "[f.Initials for f in [f for f in (lambda e: [e.nextElement() for _ in iter(e.hasMoreElements, False)])(doc.TextFields.createEnumeration()) if f.supportsService('com.sun.star.text.textfield.Annotation')]]", + "expect": [ + "AB", + "" + ] + }, + { + "name": "ann_author", + "expr": "[f.Author for f in [f for f in (lambda e: [e.nextElement() for _ in iter(e.hasMoreElements, False)])(doc.TextFields.createEnumeration()) if f.supportsService('com.sun.star.text.textfield.Annotation')]]", + "expect": [ + "Ann Author", + "Bob Author" + ] + }, + { + "name": "ann_content", + "expr": "[f.Content for f in [f for f in (lambda e: [e.nextElement() for _ in iter(e.hasMoreElements, False)])(doc.TextFields.createEnumeration()) if f.supportsService('com.sun.star.text.textfield.Annotation')]]", + "expect": [ + "first note", + "second note" + ] + }, + { + "name": "ann_text", + "expr": "doc.Text.String", + "expect": "with initials \nwithout initials " + } +] diff --git a/test/odf-validate/fixtures/t13/checks-chart.json b/test/odf-validate/fixtures/t13/checks-chart.json new file mode 100644 index 0000000000..7fe2b422e3 --- /dev/null +++ b/test/odf-validate/fixtures/t13/checks-chart.json @@ -0,0 +1,48 @@ +[ + { + "name": "chart_diagram_pos", + "expr": "doc.Sheets.getByIndex(0).Charts.getByName('C1').EmbeddedObject.Diagram.calculateDiagramPositionExcludingAxes()", + "expect": { + "Height": 4500, + "Width": 6000, + "X": 1500, + "Y": 1200 + } + }, + { + "name": "chart_diagram_excluding", + "expr": "doc.Sheets.getByIndex(0).Charts.getByName('C1').EmbeddedObject.Diagram.isExcludingDiagramPositioning()", + "expect": true + }, + { + "name": "chart_diagram_auto", + "expr": "doc.Sheets.getByIndex(0).Charts.getByName('C1').EmbeddedObject.Diagram.isAutomaticDiagramPositioning()", + "expect": false + }, + { + "name": "chart_has_legend", + "expr": "doc.Sheets.getByIndex(0).Charts.getByName('C1').EmbeddedObject.HasLegend", + "expect": true + }, + { + "name": "chart_legend_expansion", + "expr": "doc.Sheets.getByIndex(0).Charts.getByName('C1').EmbeddedObject.Legend.Expansion", + "expect": "CUSTOM" + }, + { + "name": "chart_legend_size", + "expr": "(lambda z: [z.Width, z.Height])(doc.Sheets.getByIndex(0).Charts.getByName('C1').EmbeddedObject.Legend.getSize())", + "expect": [ + 2500, + 1800 + ] + }, + { + "name": "chart_legend_pos", + "expr": "(lambda p: [p.X, p.Y])(doc.Sheets.getByIndex(0).Charts.getByName('C1').EmbeddedObject.Legend.getPosition())", + "expect": [ + 8800, + 1500 + ] + } +] diff --git a/test/odf-validate/fixtures/t13/checks-dropdown.json b/test/odf-validate/fixtures/t13/checks-dropdown.json new file mode 100644 index 0000000000..19d670d01f --- /dev/null +++ b/test/odf-validate/fixtures/t13/checks-dropdown.json @@ -0,0 +1,67 @@ +[ + { + "name": "dd_count", + "expr": "len([f for f in (lambda e: [e.nextElement() for _ in iter(e.hasMoreElements, False)])(doc.TextFields.createEnumeration()) if f.supportsService('com.sun.star.text.textfield.DropDown')])", + "expect": 2 + }, + { + "name": "dd_names", + "expr": "[f.Name for f in [f for f in (lambda e: [e.nextElement() for _ in iter(e.hasMoreElements, False)])(doc.TextFields.createEnumeration()) if f.supportsService('com.sun.star.text.textfield.DropDown')]]", + "expect": [ + "dd1", + "dd2" + ] + }, + { + "name": "dd_items", + "expr": "[list(f.Items) for f in [f for f in (lambda e: [e.nextElement() for _ in iter(e.hasMoreElements, False)])(doc.TextFields.createEnumeration()) if f.supportsService('com.sun.star.text.textfield.DropDown')]]", + "expect": [ + [ + "one", + "two", + "three" + ], + [ + "a", + "b" + ] + ] + }, + { + "name": "dd_selected", + "expr": "[f.SelectedItem for f in [f for f in (lambda e: [e.nextElement() for _ in iter(e.hasMoreElements, False)])(doc.TextFields.createEnumeration()) if f.supportsService('com.sun.star.text.textfield.DropDown')]]", + "expect": [ + "two", + "" + ] + }, + { + "name": "dd_help", + "expr": "[f.Help for f in [f for f in (lambda e: [e.nextElement() for _ in iter(e.hasMoreElements, False)])(doc.TextFields.createEnumeration()) if f.supportsService('com.sun.star.text.textfield.DropDown')]]", + "expect": [ + "help one", + "help two" + ] + }, + { + "name": "dd_tooltip", + "expr": "[f.Tooltip for f in [f for f in (lambda e: [e.nextElement() for _ in iter(e.hasMoreElements, False)])(doc.TextFields.createEnumeration()) if f.supportsService('com.sun.star.text.textfield.DropDown')]]", + "expect": [ + "tip one", + "tip two" + ] + }, + { + "name": "dd_presentation", + "expr": "[f.getPresentation(False) for f in [f for f in (lambda e: [e.nextElement() for _ in iter(e.hasMoreElements, False)])(doc.TextFields.createEnumeration()) if f.supportsService('com.sun.star.text.textfield.DropDown')]]", + "expect": [ + "two", + "a" + ] + }, + { + "name": "dd_text", + "expr": "doc.Text.String", + "expect": "First: two\nSecond: a" + } +] diff --git a/test/odf-validate/fixtures/t13/checks-scaleto.json b/test/odf-validate/fixtures/t13/checks-scaleto.json new file mode 100644 index 0000000000..06488877ec --- /dev/null +++ b/test/odf-validate/fixtures/t13/checks-scaleto.json @@ -0,0 +1,52 @@ +[ + { + "name": "scale_xy", + "expr": "(lambda s: [s.ScaleToPagesX, s.ScaleToPagesY, s.ScaleToPages, s.PageScale])(doc.StyleFamilies.getByName('PageStyles').getByName('PS_xy'))", + "expect": [ + 2, + 3, + 0, + 100 + ] + }, + { + "name": "scale_x_only", + "expr": "(lambda s: [s.ScaleToPagesX, s.ScaleToPagesY, s.ScaleToPages, s.PageScale])(doc.StyleFamilies.getByName('PageStyles').getByName('PS_x'))", + "expect": [ + 2, + 0, + 0, + 100 + ] + }, + { + "name": "scale_pages", + "expr": "(lambda s: [s.ScaleToPagesX, s.ScaleToPagesY, s.ScaleToPages, s.PageScale])(doc.StyleFamilies.getByName('PageStyles').getByName('PS_pages'))", + "expect": [ + 0, + 0, + 4, + 100 + ] + }, + { + "name": "scale_percent", + "expr": "(lambda s: [s.ScaleToPagesX, s.ScaleToPagesY, s.ScaleToPages, s.PageScale])(doc.StyleFamilies.getByName('PageStyles').getByName('PS_scale'))", + "expect": [ + 0, + 0, + 0, + 80 + ] + }, + { + "name": "scale_sheet_styles", + "expr": "[doc.Sheets.getByIndex(i).PageStyle for i in range(doc.Sheets.Count)]", + "expect": [ + "PS_xy", + "PS_x", + "PS_pages", + "PS_scale" + ] + } +] diff --git a/test/odf-validate/fixtures/t13/checks-tabcolor.json b/test/odf-validate/fixtures/t13/checks-tabcolor.json new file mode 100644 index 0000000000..3211e10af6 --- /dev/null +++ b/test/odf-validate/fixtures/t13/checks-tabcolor.json @@ -0,0 +1,22 @@ +[ + { + "name": "tab_count", + "expr": "doc.Sheets.Count", + "expect": 3 + }, + { + "name": "tab_sheet0", + "expr": "doc.Sheets.getByIndex(0).TabColor", + "expect": 16711680 + }, + { + "name": "tab_sheet1", + "expr": "doc.Sheets.getByIndex(1).TabColor", + "expect": -1 + }, + { + "name": "tab_sheet2", + "expr": "doc.Sheets.getByIndex(2).TabColor", + "expect": 3368652 + } +] diff --git a/test/odf-validate/fixtures/t13/dropdown.odt b/test/odf-validate/fixtures/t13/dropdown.odt new file mode 100644 index 0000000000..2e44387531 Binary files /dev/null and b/test/odf-validate/fixtures/t13/dropdown.odt differ diff --git a/test/odf-validate/fixtures/t13/make.py b/test/odf-validate/fixtures/t13/make.py new file mode 100644 index 0000000000..70428bbfed --- /dev/null +++ b/test/odf-validate/fixtures/t13/make.py @@ -0,0 +1,165 @@ +#************************************************************** +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +#************************************************************** +# +# usage: runpy.sh fixtures/t13/make.py <port> <outdir> +# Documents for the features ODF 1.3 changes in the writer: drop-down fields, annotation initials, Calc tab colour, +# Calc page scale-to, chart inner plot position and legend size. Saves with the office's configured ODF version: run +# it with fixtures/gen-run.sh (strict, ext, v13, x13). The committed copies in this folder were generated in ext mode, +# which keeps all of the features. Everything is fixed (no dates taken from the clock, nothing random). +import sys, os, traceback, uno +from unohelp import connect, desktop, pv + +port, out = int(sys.argv[1]), os.path.abspath(sys.argv[2]) +os.makedirs(out, exist_ok=True) +desk = desktop(connect(port)) +failed = [] + + +def new(factory): + return desk.loadComponentFromURL(factory, "_blank", 0, (pv("Hidden", True),)) + + +def save(doc, name, filt): + try: + doc.storeToURL(uno.systemPathToFileUrl(os.path.join(out, name)), (pv("FilterName", filt),)) + print("saved", name, filt) + except Exception as e: + failed.append(name) + print("FAIL", name, filt, type(e).__name__, str(e)[:200], repr(e)[:200]) + + +def attempt(label, fn): + try: + fn() + except Exception as e: + failed.append(label) + print("FAIL", label, type(e).__name__, str(e)[:100], repr(e)[:200], "line", traceback.extract_tb(e.__traceback__)[-1].lineno) + + +def dt(y, mo, d, h, mi): + return uno.createUnoStruct("com.sun.star.util.DateTime", 0, 0, mi, h, d, mo, y) + + +def ensure_sheets(doc, n): + sheets = doc.Sheets + while sheets.Count > n: + sheets.removeByName(sheets.getByIndex(sheets.Count - 1).Name) + while sheets.Count < n: + sheets.insertNewByName("Sheet%d" % (sheets.Count + 1), sheets.Count) + return sheets + + +def put_text(doc, cur, s): + doc.Text.insertString(cur, s, False) + + +def put_field(doc, cur, kind, **props): + f = doc.createInstance("com.sun.star.text.TextField." + kind) + for k, v in props.items(): + setattr(f, k, v) + doc.Text.insertTextContent(cur, f, False) + return f + + +def doc_dropdown(): + doc = new("private:factory/swriter") + cur = doc.Text.createTextCursor() + put_text(doc, cur, "First: ") + put_field(doc, cur, "DropDown", Name="dd1", Items=("one", "two", "three"), SelectedItem="two", Help="help one", Tooltip="tip one") + doc.Text.insertControlCharacter(cur, 0, False) + put_text(doc, cur, "Second: ") + # SwDropDownField accepts only a listed SelectedItem: "zzz" reads back as "" (nothing selected, the field shows "a") + put_field(doc, cur, "DropDown", Name="dd2", Items=("a", "b"), SelectedItem="zzz", Help="help two", Tooltip="tip two") + save(doc, "dropdown.odt", "writer8") + doc.close(True) + + +def doc_annot(): + doc = new("private:factory/swriter") + cur = doc.Text.createTextCursor() + put_text(doc, cur, "with initials ") + put_field(doc, cur, "Annotation", Author="Ann Author", Initials="AB", Content="first note", DateTimeValue=dt(2024, 7, 8, 9, 10)) + doc.Text.insertControlCharacter(cur, 0, False) + put_text(doc, cur, "without initials ") + put_field(doc, cur, "Annotation", Author="Bob Author", Content="second note", DateTimeValue=dt(2024, 7, 9, 9, 10)) + save(doc, "annot.odt", "writer8") + doc.close(True) + + +def doc_tabcolor(): + doc = new("private:factory/scalc") + sheets = ensure_sheets(doc, 3) + for i, color in ((0, 0xFF0000), (2, 0x3366CC)): + sheets.getByIndex(i).TabColor = color + for i in range(3): + sheets.getByIndex(i).getCellByPosition(0, 0).setString("sheet %d" % i) + save(doc, "tabcolor.ods", "calc8") + doc.close(True) + + +def doc_scaleto(): + doc = new("private:factory/scalc") + ps = doc.StyleFamilies.getByName("PageStyles") + sheets = ensure_sheets(doc, 4) + # setting ScaleToPagesX/Y clears ScaleToPages and PageScale in the style (sc/source/ui/unoobj/styleuno.cxx) + for name, props in (("PS_xy", {"ScaleToPagesX": 2, "ScaleToPagesY": 3}), + ("PS_x", {"ScaleToPagesX": 2}), + ("PS_pages", {"ScaleToPages": 4}), + ("PS_scale", {"PageScale": 80})): + ps.insertByName(name, doc.createInstance("com.sun.star.style.PageStyle")) + st = ps.getByName(name) + for k, v in props.items(): + setattr(st, k, v) + for i, name in enumerate(("PS_xy", "PS_x", "PS_pages", "PS_scale")): + sh = sheets.getByIndex(i) + sh.PageStyle = name + sh.getCellByPosition(0, 0).setString(name) + save(doc, "scaleto.ods", "calc8") + doc.close(True) + + +def doc_chart(): + doc = new("private:factory/scalc") + sh = doc.Sheets.getByIndex(0) + for r in range(3): + sh.getCellByPosition(0, r).setString("c%d" % r) + sh.getCellByPosition(1, r).setValue(r + 1) + rect = uno.createUnoStruct("com.sun.star.awt.Rectangle", 1000, 1000, 12000, 9000) + sh.Charts.addNewByName("C1", rect, (sh.getCellRangeByName("A1:B3").RangeAddress,), True, True) + ch = sh.Charts.getByName("C1").EmbeddedObject + ch.HasLegend = True + dg = ch.Diagram + # inner plot position in 1/100 mm; the legend is positioned and given a custom size + dg.setDiagramPositionExcludingAxes(uno.createUnoStruct("com.sun.star.awt.Rectangle", 1500, 1200, 6000, 4500)) + lg = ch.Legend + lg.Expansion = uno.Enum("com.sun.star.chart.ChartLegendExpansion", "CUSTOM") + lg.setSize(uno.createUnoStruct("com.sun.star.awt.Size", 2500, 1800)) + lg.setPosition(uno.createUnoStruct("com.sun.star.awt.Point", 8800, 1500)) + r = dg.calculateDiagramPositionExcludingAxes() + print("diagram excl. axes", r.X, r.Y, r.Width, r.Height, "auto", dg.isAutomaticDiagramPositioning(), "excl", dg.isExcludingDiagramPositioning()) + print("legend", lg.Expansion.value, lg.getPosition().X, lg.getPosition().Y, lg.getSize().Width, lg.getSize().Height) + save(doc, "chart.ods", "calc8") + doc.close(True) + + +for n, fn in (("dropdown", doc_dropdown), ("annot", doc_annot), ("tabcolor", doc_tabcolor), ("scaleto", doc_scaleto), ("chart", doc_chart)): + attempt(n, fn) +sys.exit(1 if failed else 0) diff --git a/test/odf-validate/fixtures/t13/scaleto.ods b/test/odf-validate/fixtures/t13/scaleto.ods new file mode 100644 index 0000000000..db0ca80b9f Binary files /dev/null and b/test/odf-validate/fixtures/t13/scaleto.ods differ diff --git a/test/odf-validate/fixtures/t13/tabcolor.ods b/test/odf-validate/fixtures/t13/tabcolor.ods new file mode 100644 index 0000000000..3520c709c2 Binary files /dev/null and b/test/odf-validate/fixtures/t13/tabcolor.ods differ diff --git a/test/odf-validate/gate-fixtures.tsv b/test/odf-validate/gate-fixtures.tsv index fcb94f124b..e0e991b665 100644 --- a/test/odf-validate/gate-fixtures.tsv +++ b/test/odf-validate/gate-fixtures.tsv @@ -80,3 +80,8 @@ fill-others/others-writer.odt fill-others/writer.json fill-others/others-calc.ods fill-others/calc.json fill-others/others-draw.odg fill-others/draw.json fill-others/others-impress.odp fill-others/impress.json +t13/dropdown.odt t13/checks-dropdown.json +t13/annot.odt t13/checks-annot.json +t13/tabcolor.ods t13/checks-tabcolor.json +t13/scaleto.ods t13/checks-scaleto.json +t13/chart.ods t13/checks-chart.json
