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 .
21 import lib
.MultiMethodTest
;
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
;
39 * Testing <code>com.sun.star.frame.XDesktop</code>
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>
53 public class _XDocumentTemplates
extends MultiMethodTest
{
54 public XDocumentTemplates oObj
= null; // oObj filled by MultiMethodTest
55 protected XContent content
= null;
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);
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;
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
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",
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",
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
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() {
184 tRes
.tested("update()",true);
188 * Returns the string representation of content passed as parameter.
190 protected String
getContentList(XContent content
) {
191 XResultSet statRes
= getStatResultSet(content
);
195 XRow row
= UnoRuntime
.queryInterface(XRow
.class, statRes
);
196 while(! statRes
.isAfterLast()) {
197 ret
+= "\n " + row
.getString(1);
200 } catch (com
.sun
.star
.sdbc
.SQLException e
) {
201 log
.println("Exception occurred:" + e
);
207 protected XResultSet
getStatResultSet(XContent content
) {
208 XResultSet statResSet
= null;
210 statResSet
= getDynaResultSet(content
).getStaticResultSet();
211 } catch(com
.sun
.star
.ucb
.ListenerAlreadySetException e
) {
212 log
.println("Exception occurred:" + e
);
217 protected XDynamicResultSet
getDynaResultSet(XContent content
) {
218 Command command
= new Command();
219 OpenCommandArgument2 comArg
= new OpenCommandArgument2();
220 Property
[] comProps
= new Property
[1];
221 comArg
.Mode
= com
.sun
.star
.ucb
.OpenMode
.ALL
;
222 comProps
[0] = new Property();
223 comProps
[0].Name
= "Title";
224 comArg
.Properties
= comProps
;
226 command
.Name
= "open";
228 command
.Argument
= comArg
;
230 XCommandProcessor comProc
= UnoRuntime
.queryInterface(XCommandProcessor
.class, content
);
232 XDynamicResultSet DynResSet
= null;
234 DynResSet
= (XDynamicResultSet
) AnyConverter
.toObject(
235 new Type(XDynamicResultSet
.class),comProc
.execute(command
, 0, null));
236 } catch(com
.sun
.star
.ucb
.CommandAbortedException e
) {
237 log
.println("Couldn't execute command:" + e
);
238 } catch(com
.sun
.star
.uno
.Exception e
) {
239 log
.println("Couldn't execute command:" + e
);
245 protected XContent
getSubContent(XContent content
, String subName
) {
246 XResultSet statRes
= getStatResultSet(content
);
247 XRow row
= UnoRuntime
.queryInterface(XRow
.class, statRes
);
248 XContentAccess contAcc
= UnoRuntime
.queryInterface(XContentAccess
.class, statRes
);
249 XContent subContent
= null;
252 while(!statRes
.isAfterLast()) {
253 if ( subName
.equals(row
.getString(1)) ) {
254 subContent
= contAcc
.queryContent();
258 } catch(com
.sun
.star
.sdbc
.SQLException e
) {
259 log
.println("Exception occurred:" + e
);