summaryrefslogtreecommitdiff
path: root/qadevOOo/tests/basic/ifc/frame/XDocumentTemplates/frame_XDocumentTemplates.xba
blob: 639af5868d02d5ea450474e476e7ad5696c82143 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="frame_XDocumentTemplates" script:language="StarBasic">


'*************************************************************************
'
' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
' 
' Copyright 2000, 2010 Oracle and/or its affiliates.
'
' OpenOffice.org - a multi-platform office productivity suite
'
' This file is part of OpenOffice.org.
'
' OpenOffice.org is free software: you can redistribute it and/or modify
' it under the terms of the GNU Lesser General Public License version 3
' only, as published by the Free Software Foundation.
'
' OpenOffice.org is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU Lesser General Public License version 3 for more details
' (a copy is included in the LICENSE file that accompanied this code).
'
' You should have received a copy of the GNU Lesser General Public License
' version 3 along with OpenOffice.org.  If not, see
' <http://www.openoffice.org/license.html>
' for a copy of the LGPLv3 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 
</script:module>