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