'************************************************************************* ' ' Licensed to the Apache Software Foundation (ASF) under one ' or more contributor license agreements. See the NOTICE file ' distributed with this work for additional information ' regarding copyright ownership. The ASF licenses this file ' to you under the Apache License, Version 2.0 (the ' "License"); you may not use this file except in compliance ' with the License. You may obtain a copy of the License at ' ' http://www.apache.org/licenses/LICENSE-2.0 ' ' Unless required by applicable law or agreed to in writing, ' software distributed under the License is distributed on an ' "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ' KIND, either express or implied. See the License for the ' specific language governing permissions and limitations ' under the License. ' '************************************************************************* ' Be sure that all variables are dimensioned: option explicit '************************************************************************* ' This Interface/Service test depends on the following GLOBAL variables, ' which must be specified in the object creation: ' - Global oStore As Object '************************************************************************* Sub RunTest() '************************************************************************* ' INTERFACE: ' com.sun.star.frame.XDocumentTemplates '************************************************************************* On Error Goto ErrHndl Dim bOK As Boolean Dim content As Object, groupContent As Object Dim result as Object, statRes As Object Dim res As Boolean Test.StartMethod("getContent()") bOK = true content = oObj.getContent() Out.Log("Content list :") Out.Log(getContentList(content)) bOK = bOK AND NOT isNull(content) Test.MethodTested("getContent()", bOK) Test.StartMethod("addGroup()") bOK = true res = oObj.addGroup("XDocumentTemplatesTemp") Out.Log("Method returned: " + res) bOK = bOK AND res AND NOT isNull(getSubContent(content, "XDocumentTemplatesTemp")) Test.MethodTested("addGroup()", bOK) Test.StartMethod("renameGroup()") bOK = true res = oObj.renameGroup("XDocumentTemplatesTemp", "XDocumentTemplates") Out.Log("Method returned: " + res) groupContent = getSubContent(content, "XDocumentTemplates") bOK = bOK AND res AND isNull(getSubContent(content, "XDocumentTemplatesTemp")) _ AND NOT isNull(groupContent) Test.MethodTested("renameGroup()", bOK) Test.StartMethod("addTemplate()") Dim testDoc As String testDoc = utils.Path2URL(cTestDocsDir) + "report.stw" Out.Log("Adding template from " + testDoc bOK = true res = oObj.addTemplate("XDocumentTemplates", "ANewTemplateTemp", testDoc) Out.Log("Method returned: " + res) bOK = bOK AND res AND NOT isNull(getSubContent(groupContent, "ANewTemplateTemp")) Test.MethodTested("addTemplate()", bOK) Test.StartMethod("renameTemplate()") bOK = true res = oObj.renameTemplate("XDocumentTemplates", "ANewTemplateTemp", "ANewTemplate") Out.Log("Method returned: " + res) bOK = bOK AND res AND isNull(getSubContent(groupContent, "ANewTemplateTemp")) _ AND NOT isNull(getSubContent(groupContent, "ANewTemplate")) Test.MethodTested("renameTemplate()", bOK) Test.StartMethod("storeTemplate()") bOK = true res = oObj.storeTemplate("XDocumentTemplates", "NewStoreTemplate", oStore) Out.Log("Method returned: " + res) bOK = bOK AND res AND NOT isNull(getSubContent(groupContent, "NewStoreTemplate")) Test.MethodTested("storeTemplate()", bOK) Test.StartMethod("removeTemplate()") bOK = true res = oObj.removeTemplate("XDocumentTemplates", "ANewTemplate") Out.Log("Method returned: " + res) bOK = bOK AND res AND isNull(getSubContent(groupContent, "ANewTemplate") Test.MethodTested("removeTemplate()", bOK) Test.StartMethod("removeGroup()") bOK = true res = oObj.removeGroup("XDocumentTemplates") Out.Log("Method returned: " + res) bOK = bOK AND res AND isNull(getSubContent(content, "XDocumentTemplatesTemp") Test.MethodTested("removeGroup()", bOK) Test.StartMethod("update()") bOK = true oObj.update() Test.MethodTested("update()", bOK) Exit Sub ErrHndl: Test.Exception() bOK = false resume next End Sub Function getDynaResultSet(content As Object) As Object Dim command as new com.sun.star.ucb.Command Dim comArg as new com.sun.star.ucb.OpenCommandArgument2 Dim comProps(0) as new com.sun.star.beans.Property Dim result as Object, statRes As Object comArg.Mode = com.sun.star.ucb.OpenMode.ALL comProps(0).Name = "Title" comArg.Properties = comProps() command.Name = "open" command.Handle = -1 command.Argument = comArg getDynaResultSet = content.execute(command, 0, NULL_OBJECT) End Function Function getStatResultSet(content As Object) As Object getStatResultSet = getDynaResultSet(content).getStaticResultSet() End Function Function getContentList(content As Object) As String Dim statRes As Object Dim ret As String statRes = getStatResultSet(content) statRes.first() ret = "" while NOT statRes.isAfterLast() ret = ret + " " + statRes.getString(1) + chr(13) statRes.next() wend getContentList = ret End Function Function getSubContent(content As Object, subName As String) As Object Dim statRes As Object Dim ret As Object statRes = getStatResultSet(content) statRes.first() while NOT statRes.isAfterLast() if subName = statRes.getString(1) then ret = statRes.queryContent() endif statRes.next() wend getSubContent = ret End Function