xref: /trunk/test/odf-validate/fixtures/calc/verify.py (revision 0e16a31d78a652c56c5c0fc79c752f48b9048df9)
1#**************************************************************
2#
3#  Licensed to the Apache Software Foundation (ASF) under one
4#  or more contributor license agreements.  See the NOTICE file
5#  distributed with this work for additional information
6#  regarding copyright ownership.  The ASF licenses this file
7#  to you under the Apache License, Version 2.0 (the
8#  "License"); you may not use this file except in compliance
9#  with the License.  You may obtain a copy of the License at
10#
11#    http://www.apache.org/licenses/LICENSE-2.0
12#
13#  Unless required by applicable law or agreed to in writing,
14#  software distributed under the License is distributed on an
15#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16#  KIND, either express or implied.  See the License for the
17#  specific language governing permissions and limitations
18#  under the License.
19#
20# usage: runpy.sh fixtures/calc/verify.py <port> <outdir>
21# Reloads each document listed in <outdir>/../work/expect.json with validations and compares the Validation of every cell with what make.py read back before saving.
22import sys, os, json, uno
23from unohelp import connect, desktop, pv
24
25port, out = int(sys.argv[1]), os.path.abspath(sys.argv[2])
26work = os.path.join(os.path.dirname(out), "work")
27expect = json.load(open(os.path.join(work, "expect.json")))
28desk = desktop(connect(port))
29result = {}
30for name, rows in expect.items():
31    if not rows or "readback" not in rows[0]:
32        continue
33    path = os.path.join(out, name)
34    if not os.path.exists(path):
35        continue
36    doc = desk.loadComponentFromURL(uno.systemPathToFileUrl(path), "_blank", 0, (pv("Hidden", True), pv("MacroExecutionMode", 0), pv("ReadOnly", True)))
37    sh = doc.Sheets.getByIndex(0)
38    res = []
39    for r in rows:
40        v = sh.getCellRangeByName(r["cell"]).Validation
41        got = {"type": v.Type.value, "op": v.getOperator().value, "f1": v.getFormula1(), "f2": v.getFormula2(),
42               "alert": v.ErrorAlertStyle.value, "list": v.ShowList, "ignore": v.IgnoreBlankCells,
43               "inp": [v.InputTitle, v.InputMessage], "err": [v.ErrorTitle, v.ErrorMessage],
44               "showinp": v.ShowInputMessage, "showerr": v.ShowErrorMessage}
45        diff = {k: [r["readback"][k], got[k]] for k in got if got[k] != r["readback"][k]}
46        res.append({"cell": r["cell"], "label": r["label"], "got": got, "diff": diff})
47    doc.close(True)
48    result[name] = res
49    print(name, "cells", len(res), "with differences", sum(1 for x in res if x["diff"]))
50json.dump(result, open(os.path.join(work, "verify.json"), "w"), indent=1)
51