xref: /trunk/test/aoo-test/tests/smoke/test_office.py (revision 2cb6d6f119bbe2f78742f1c5c8538cb0d4e72ede)
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################################################################
21
22"""Against a real office (AOO_OFFICE or --office). Starts one private-profile office per ODF mode."""
23import pytest
24
25from aootest.client import WorkerCrash, WorkerHang
26from aootest.odfversion import MODES, odf_versions
27from aootest.proc import kill_tree
28
29pytestmark = pytest.mark.smoke
30
31APPS = {"writer": ("writer8", "odt", "com.sun.star.text.TextDocument"),
32        "calc": ("calc8", "ods", "com.sun.star.sheet.SpreadsheetDocument"),
33        "impress": ("impress8", "odp", "com.sun.star.presentation.PresentationDocument"),
34        "draw": ("draw8", "odg", "com.sun.star.drawing.DrawingDocument")}
35
36
37def test_product_info_matches_the_install(aoo_offices, aoo_layout):
38    info = aoo_offices.get(4).call("product_info")
39    assert info["ooSetupVersion"] == aoo_layout.version.package
40    assert info["ooName"] == "OpenOffice"
41
42
43@pytest.mark.parametrize("name", [v[0] for v in APPS.values()])
44def test_native_filters_import_and_export(aoo_offices, name):
45    f = aoo_offices.get(4).call("filters", {"names": [name]})[name]
46    assert f is not None and f["import"] and f["export"]
47
48
49@pytest.mark.parametrize("mode", MODES)
50def test_mode_is_applied_by_the_profile(aoo_offices, mode):
51    value = aoo_offices.get(mode).call("config_value", {"path": "/org.openoffice.Office.Common/Save/ODF", "name": "DefaultVersion"})
52    assert value == mode
53
54
55@pytest.mark.parametrize("app", APPS)
56@pytest.mark.parametrize("mode", MODES)
57def test_new_store_version_reload(aoo_offices, need_mode, tmp_path, app, mode):
58    need_mode(mode)
59    filter_name, ext, service = APPS[app]
60    dst = tmp_path / ("new." + ext)
61    s = aoo_offices.get(mode)
62    s.call("new_and_store", {"app": app, "dst": str(dst), "filter": filter_name}, timeout=120)
63    assert odf_versions(dst) == (MODES[mode], MODES[mode])
64    info = s.call("load_info", {"path": str(dst)}, timeout=120)
65    assert info["loaded"] and service in info["services"]
66
67
68def test_default_mode_writes_some_known_version(aoo_offices, tmp_path):
69    dst = tmp_path / "new.odt"
70    aoo_offices.get(None).call("new_and_store", {"app": "writer", "dst": str(dst), "filter": "writer8"}, timeout=120)
71    content, manifest = odf_versions(dst)
72    assert content == manifest and content in ("1.2", "1.3")
73
74
75def test_hang_is_reported_and_the_next_call_works(aoo_offices):
76    s = aoo_offices.get(4)
77    with pytest.raises(WorkerHang):
78        s.call("sleep", {"seconds": 60}, timeout=3)
79    assert s.call("ping", timeout=120) == {"pong": True}
80
81
82def test_worker_crash_is_reported_and_the_next_call_works(aoo_offices):
83    s = aoo_offices.get(4)
84    with pytest.raises(WorkerCrash):
85        s.call("die", timeout=30)
86    assert s.call("ping", timeout=120) == {"pong": True}
87
88
89def test_office_killed_mid_session_is_recovered(aoo_offices):
90    s = aoo_offices.get(5)
91    s.call("ping", timeout=120)
92    kill_tree(s.office._proc)
93    with pytest.raises((WorkerCrash, WorkerHang)):
94        s.call("filters", {"names": ["writer8"]}, timeout=30)
95    assert s.call("filters", {"names": ["writer8"]}, timeout=120)["writer8"]["export"]
96