Update ooo320-m1
[ooovba.git] / qadevOOo / tests / java / ifc / frame / _XDocumentTemplates.java
blob0d68c52f3cc69c75a37f27da452bddd1025bfc42
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XDocumentTemplates.java,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package ifc.frame;
33 import lib.MultiMethodTest;
34 import util.utils;
36 import com.sun.star.beans.Property;
37 import com.sun.star.frame.XDocumentTemplates;
38 import com.sun.star.frame.XStorable;
39 import com.sun.star.sdbc.XResultSet;
40 import com.sun.star.sdbc.XRow;
41 import com.sun.star.ucb.Command;
42 import com.sun.star.ucb.OpenCommandArgument2;
43 import com.sun.star.ucb.XCommandProcessor;
44 import com.sun.star.ucb.XContent;
45 import com.sun.star.ucb.XContentAccess;
46 import com.sun.star.ucb.XDynamicResultSet;
47 import com.sun.star.uno.AnyConverter;
48 import com.sun.star.uno.Type;
49 import com.sun.star.uno.UnoRuntime;
50 /**
51 * Testing <code>com.sun.star.frame.XDesktop</code>
52 * interface methods:
53 * <ul>
54 * <li><code> getContent() </code></li>
55 * <li><code> storeTemplate() </code></li>
56 * <li><code> addTemplate() </code></li>
57 * <li><code> removeTemplate() </code></li>
58 * <li><code> renameTemplate() </code></li>
59 * <li><code> addGroup() </code></li>
60 * <li><code> removeGroup() </code></li>
61 * <li><code> renameGroup() </code></li>
62 * <li><code> update() </code></li>
63 * </ul><p>
65 public class _XDocumentTemplates extends MultiMethodTest {
66 public XDocumentTemplates oObj = null; // oObj filled by MultiMethodTest
67 protected XContent content = null;
68 /**
69 * Test calls the method and prints contents list to log.<p>
70 * Has <b> OK </b> status if the XContent isn't empty.
72 public void _getContent() {
73 content = oObj.getContent();
74 log.println("Content list:" + getContentList(content));
75 tRes.tested("getContent()", content != null);
78 /**
79 * Test calls the method and checks that new group was added. <p>
80 * Has <b> OK </b> status if method returns true and new group was added.
82 public void _addGroup() {
83 requiredMethod("getContent()");
84 if (getSubContent(content, "XDocumentTemplatesTemp") != null ) {
85 oObj.removeGroup("XDocumentTemplatesTemp");
87 if (getSubContent(content, "XDocumentTemplates") != null ) {
88 oObj.removeGroup("XDocumentTemplates");
90 boolean res = oObj.addGroup("XDocumentTemplatesTemp");
91 log.println("Method returned: " + res);
92 res &= getSubContent(content, "XDocumentTemplatesTemp") != null;
93 tRes.tested("addGroup()", res);
96 XContent groupContent = null;
97 /**
98 * Test calls the method and checks that content has no group with old name
99 * and that content has group with new name. <p>
100 * Has <b> OK </b> status if method returns true, content has no group with
101 * old name and content has group with new name.<p>
103 public void _renameGroup() {
104 requiredMethod("addGroup()");
105 boolean res = oObj.renameGroup("XDocumentTemplatesTemp",
106 "XDocumentTemplates");
107 log.println("Method returned: " + res);
108 groupContent = getSubContent(content, "XDocumentTemplates");
109 res &= getSubContent(content, "XDocumentTemplatesTemp") == null;
110 res &= groupContent != null;
111 tRes.tested("renameGroup()", res);
115 * Test calls the method and checks that group content has new template. <p>
116 * Has <b> OK </b> status if method returns true and group content has new
117 * template.<p>
119 public void _addTemplate() {
120 requiredMethod("renameGroup()");
121 String testDoc = utils.getFullTestURL("report.stw");
122 log.println("Adding template from " + testDoc);
123 boolean res = oObj.addTemplate("XDocumentTemplates",
124 "ANewTemplateTemp",testDoc);
125 log.println("Method returned: " + res);
126 res &= getSubContent(groupContent, "ANewTemplateTemp") != null;
127 tRes.tested("addTemplate()", res);
131 * Test calls the method and checks that group content has no template with
132 * old name and that group content has template with new name. <p>
133 * Has <b> OK </b> status if method returns true, group content has no
134 * template with old name and group content has template with new name.<p>
136 public void _renameTemplate() {
137 requiredMethod("addTemplate()");
138 boolean res = oObj.renameTemplate("XDocumentTemplates",
139 "ANewTemplateTemp",
140 "ANewTemplate");
141 log.println("Method returned: " + res);
142 res &= getSubContent(groupContent, "ANewTemplateTemp") == null;
143 res &= getSubContent(groupContent, "ANewTemplate") != null;
145 tRes.tested("renameTemplate()", res);
149 * Test calls the method and checks that group content has new template. <p>
150 * Has <b> OK </b> status if method returns true and new template was created.<p>
152 public void _storeTemplate() {
153 requiredMethod("renameGroup()");
154 XStorable store = (XStorable) tEnv.getObjRelation("Store");
155 boolean res = oObj.storeTemplate("XDocumentTemplates",
156 "NewStoreTemplate",
157 store);
158 log.println("Method returned: " + res);
159 res &= getSubContent(groupContent, "NewStoreTemplate") != null;
160 tRes.tested("storeTemplate()", res);
164 * Test calls the method and checks that group content has no deleted template. <p>
165 * Has <b> OK </b> status if method returns true and group content has no
166 * deleted template.<p>
168 public void _removeTemplate() {
169 requiredMethod("renameTemplate()");
170 boolean res = oObj.removeTemplate("XDocumentTemplates", "ANewTemplate");
171 log.println("Method returned: " + res);
172 res &= getSubContent(groupContent, "ANewTemplate") == null;
173 tRes.tested("removeTemplate()", res);
177 * Test calls the method and checks that content has no deleted group. <p>
178 * Has <b> OK </b> status if method returns true and content has no deleted
179 * group.<p>
181 public void _removeGroup() {
182 requiredMethod("renameGroup()");
183 executeMethod("renameTemplate()");
184 boolean res = oObj.removeGroup("XDocumentTemplates");
185 log.println("Method returned: " + res);
186 res &= getSubContent(content, "XDocumentTemplates") == null;
187 tRes.tested("removeGroup()", res);
191 * Test calls the method. <p>
192 * Has <b> OK </b> status if no exception occurs.<p>
194 public void _update() {
195 oObj.update();
196 tRes.tested("update()",true);
200 * Returns the string representation of content passed as parameter.
202 protected String getContentList(XContent content) {
203 XResultSet statRes = getStatResultSet(content);
204 String ret = "";
205 try {
206 statRes.first();
207 XRow row = (XRow)UnoRuntime.queryInterface(XRow.class, statRes);
208 while(! statRes.isAfterLast()) {
209 ret += "\n " + row.getString(1);
210 statRes.next();
212 } catch (com.sun.star.sdbc.SQLException e) {
213 log.println("Exception occured:" + e);
216 return ret;
219 protected XResultSet getStatResultSet(XContent content) {
220 XResultSet statResSet = null;
221 try {
222 statResSet = getDynaResultSet(content).getStaticResultSet();
223 } catch(com.sun.star.ucb.ListenerAlreadySetException e) {
224 log.println("Exception occured:" + e);
226 return statResSet;
229 protected XDynamicResultSet getDynaResultSet(XContent content) {
230 Command command = new Command();
231 OpenCommandArgument2 comArg = new OpenCommandArgument2();
232 Property[] comProps = new Property[1];
233 comArg.Mode = com.sun.star.ucb.OpenMode.ALL;
234 comProps[0] = new Property();
235 comProps[0].Name = "Title";
236 comArg.Properties = comProps;
238 command.Name = "open";
239 command.Handle = -1;
240 command.Argument = comArg;
242 XCommandProcessor comProc = (XCommandProcessor)
243 UnoRuntime.queryInterface(XCommandProcessor.class, content);
245 XDynamicResultSet DynResSet = null;
246 try {
247 DynResSet = (XDynamicResultSet) AnyConverter.toObject(
248 new Type(XDynamicResultSet.class),comProc.execute(command, 0, null));
249 } catch(com.sun.star.ucb.CommandAbortedException e) {
250 log.println("Couldn't execute command:" + e);
251 } catch(com.sun.star.uno.Exception e) {
252 log.println("Couldn't execute command:" + e);
255 return DynResSet;
258 protected XContent getSubContent(XContent content, String subName) {
259 XResultSet statRes = getStatResultSet(content);
260 XRow row = (XRow)UnoRuntime.queryInterface(XRow.class, statRes);
261 XContentAccess contAcc = (XContentAccess)
262 UnoRuntime.queryInterface(XContentAccess.class, statRes);
263 XContent subContent = null;
264 try {
265 statRes.first();
266 while(!statRes.isAfterLast()) {
267 if ( subName.equals(row.getString(1)) ) {
268 subContent = contAcc.queryContent();
270 statRes.next();
272 } catch(com.sun.star.sdbc.SQLException e) {
273 log.println("Exception occured:" + e);
276 return subContent;