tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / qadevOOo / tests / java / ifc / frame / _XDocumentTemplates.java
blob0a7f7f8bbab06add26352b9e1f4fa7621c5405c0
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package ifc.frame;
21 import lib.MultiMethodTest;
22 import util.utils;
24 import com.sun.star.beans.Property;
25 import com.sun.star.frame.XDocumentTemplates;
26 import com.sun.star.frame.XStorable;
27 import com.sun.star.sdbc.XResultSet;
28 import com.sun.star.sdbc.XRow;
29 import com.sun.star.ucb.Command;
30 import com.sun.star.ucb.OpenCommandArgument2;
31 import com.sun.star.ucb.XCommandProcessor;
32 import com.sun.star.ucb.XContent;
33 import com.sun.star.ucb.XContentAccess;
34 import com.sun.star.ucb.XDynamicResultSet;
35 import com.sun.star.uno.AnyConverter;
36 import com.sun.star.uno.Type;
37 import com.sun.star.uno.UnoRuntime;
38 /**
39 * Testing <code>com.sun.star.frame.XDesktop</code>
40 * interface methods:
41 * <ul>
42 * <li><code> getContent() </code></li>
43 * <li><code> storeTemplate() </code></li>
44 * <li><code> addTemplate() </code></li>
45 * <li><code> removeTemplate() </code></li>
46 * <li><code> renameTemplate() </code></li>
47 * <li><code> addGroup() </code></li>
48 * <li><code> removeGroup() </code></li>
49 * <li><code> renameGroup() </code></li>
50 * <li><code> update() </code></li>
51 * </ul><p>
53 public class _XDocumentTemplates extends MultiMethodTest {
54 public XDocumentTemplates oObj = null; // oObj filled by MultiMethodTest
55 protected XContent content = null;
56 /**
57 * Test calls the method and prints contents list to log.<p>
58 * Has <b> OK </b> status if the XContent isn't empty.
60 public void _getContent() {
61 content = oObj.getContent();
62 log.println("Content list:" + getContentList(content));
63 tRes.tested("getContent()", content != null);
66 /**
67 * Test calls the method and checks that new group was added. <p>
68 * Has <b> OK </b> status if method returns true and new group was added.
70 public void _addGroup() {
71 requiredMethod("getContent()");
72 if (getSubContent(content, "XDocumentTemplatesTemp") != null ) {
73 oObj.removeGroup("XDocumentTemplatesTemp");
75 if (getSubContent(content, "XDocumentTemplates") != null ) {
76 oObj.removeGroup("XDocumentTemplates");
78 boolean res = oObj.addGroup("XDocumentTemplatesTemp");
79 log.println("Method returned: " + res);
80 res &= getSubContent(content, "XDocumentTemplatesTemp") != null;
81 tRes.tested("addGroup()", res);
84 XContent groupContent = null;
85 /**
86 * Test calls the method and checks that content has no group with old name
87 * and that content has group with new name. <p>
88 * Has <b> OK </b> status if method returns true, content has no group with
89 * old name and content has group with new name.<p>
91 public void _renameGroup() {
92 requiredMethod("addGroup()");
93 boolean res = oObj.renameGroup("XDocumentTemplatesTemp",
94 "XDocumentTemplates");
95 log.println("Method returned: " + res);
96 groupContent = getSubContent(content, "XDocumentTemplates");
97 res &= getSubContent(content, "XDocumentTemplatesTemp") == null;
98 res &= groupContent != null;
99 tRes.tested("renameGroup()", res);
103 * Test calls the method and checks that group content has new template. <p>
104 * Has <b> OK </b> status if method returns true and group content has new
105 * template.<p>
107 public void _addTemplate() {
108 requiredMethod("renameGroup()");
109 String testDoc = utils.getFullTestURL("report.stw");
110 log.println("Adding template from " + testDoc);
111 boolean res = oObj.addTemplate("XDocumentTemplates",
112 "ANewTemplateTemp",testDoc);
113 log.println("Method returned: " + res);
114 res &= getSubContent(groupContent, "ANewTemplateTemp") != null;
115 tRes.tested("addTemplate()", res);
119 * Test calls the method and checks that group content has no template with
120 * old name and that group content has template with new name. <p>
121 * Has <b> OK </b> status if method returns true, group content has no
122 * template with old name and group content has template with new name.<p>
124 public void _renameTemplate() {
125 requiredMethod("addTemplate()");
126 boolean res = oObj.renameTemplate("XDocumentTemplates",
127 "ANewTemplateTemp",
128 "ANewTemplate");
129 log.println("Method returned: " + res);
130 res &= getSubContent(groupContent, "ANewTemplateTemp") == null;
131 res &= getSubContent(groupContent, "ANewTemplate") != null;
133 tRes.tested("renameTemplate()", res);
137 * Test calls the method and checks that group content has new template. <p>
138 * Has <b> OK </b> status if method returns true and new template was created.<p>
140 public void _storeTemplate() {
141 requiredMethod("renameGroup()");
142 XStorable store = (XStorable) tEnv.getObjRelation("Store");
143 boolean res = oObj.storeTemplate("XDocumentTemplates",
144 "NewStoreTemplate",
145 store);
146 log.println("Method returned: " + res);
147 res &= getSubContent(groupContent, "NewStoreTemplate") != null;
148 tRes.tested("storeTemplate()", res);
152 * Test calls the method and checks that group content has no deleted template. <p>
153 * Has <b> OK </b> status if method returns true and group content has no
154 * deleted template.<p>
156 public void _removeTemplate() {
157 requiredMethod("renameTemplate()");
158 boolean res = oObj.removeTemplate("XDocumentTemplates", "ANewTemplate");
159 log.println("Method returned: " + res);
160 res &= getSubContent(groupContent, "ANewTemplate") == null;
161 tRes.tested("removeTemplate()", res);
165 * Test calls the method and checks that content has no deleted group. <p>
166 * Has <b> OK </b> status if method returns true and content has no deleted
167 * group.<p>
169 public void _removeGroup() {
170 requiredMethod("renameGroup()");
171 executeMethod("renameTemplate()");
172 boolean res = oObj.removeGroup("XDocumentTemplates");
173 log.println("Method returned: " + res);
174 res &= getSubContent(content, "XDocumentTemplates") == null;
175 tRes.tested("removeGroup()", res);
179 * Test calls the method. <p>
180 * Has <b> OK </b> status if no exception occurs.<p>
182 public void _update() {
183 oObj.update();
184 tRes.tested("update()",true);
188 * Returns the string representation of content passed as parameter.
190 protected String getContentList(XContent content) {
191 StringBuilder ret = new StringBuilder();
192 XResultSet statRes = getStatResultSet(content);
193 if (statRes != null) {
194 try {
195 statRes.first();
196 XRow row = UnoRuntime.queryInterface(XRow.class, statRes);
197 while(! statRes.isAfterLast()) {
198 ret.append("\n ").append(row.getString(1));
199 statRes.next();
201 } catch (com.sun.star.sdbc.SQLException e) {
202 log.println("Exception occurred:" + e);
205 return ret.toString();
208 protected XResultSet getStatResultSet(XContent content) {
209 XResultSet statResSet = null;
210 try {
211 statResSet = getDynaResultSet(content).getStaticResultSet();
212 } catch(com.sun.star.ucb.ListenerAlreadySetException e) {
213 log.println("Exception occurred:" + e);
215 return statResSet;
218 protected XDynamicResultSet getDynaResultSet(XContent content) {
219 Command command = new Command();
220 OpenCommandArgument2 comArg = new OpenCommandArgument2();
221 Property[] comProps = new Property[1];
222 comArg.Mode = com.sun.star.ucb.OpenMode.ALL;
223 comProps[0] = new Property();
224 comProps[0].Name = "Title";
225 comArg.Properties = comProps;
227 command.Name = "open";
228 command.Handle = -1;
229 command.Argument = comArg;
231 XCommandProcessor comProc = UnoRuntime.queryInterface(XCommandProcessor.class, content);
233 XDynamicResultSet DynResSet = null;
234 try {
235 DynResSet = (XDynamicResultSet) AnyConverter.toObject(
236 new Type(XDynamicResultSet.class),comProc.execute(command, 0, null));
237 } catch(com.sun.star.ucb.CommandAbortedException e) {
238 log.println("Couldn't execute command:" + e);
239 } catch(com.sun.star.uno.Exception e) {
240 log.println("Couldn't execute command:" + e);
243 return DynResSet;
246 protected XContent getSubContent(XContent content, String subName) {
247 XResultSet statRes = getStatResultSet(content);
248 XRow row = UnoRuntime.queryInterface(XRow.class, statRes);
249 XContentAccess contAcc = UnoRuntime.queryInterface(XContentAccess.class, statRes);
250 XContent subContent = null;
251 if (statRes != null) {
252 try {
253 statRes.first();
254 while(!statRes.isAfterLast()) {
255 if ( subName.equals(row.getString(1)) ) {
256 subContent = contAcc.queryContent();
258 statRes.next();
260 } catch(com.sun.star.sdbc.SQLException e) {
261 log.println("Exception occurred:" + e);
264 return subContent;