summaryrefslogtreecommitdiff
path: root/testautomation/xml/optional/includes/f_xml_save_ms_ole.inc
blob: cdf3ba6718ef1031901fc3d1ad38cb6c8537fd66 (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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
'encoding UTF-8  Do not remove or change this line!
'**************************************************************************
' 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.
'
'/************************************************************************
'*
'* owner : oliver.craemer@sun.com
'*
'* short description : Conversion of Microsoft OLE objects in dependency of settings in Tools::Options::Load/Save::MS_Office
'*
'************************************************************************
'*
' #1 ms_ole        ' Initial routine
' #1 tXML_OLE_Conversion
' #1 subSetConversionMicrosoftOLE
'*
'\************************************************************************

testcase tXML_OLE_Conversion ( sCurrentTestDocument as STRING )
    dim iIndex as INTEGER
    dim sInputFile as STRING
    sInputFile = convertpath ( gTesttoolpath & "xml/optional/input/framework/ms_ole/" & sCurrentTestDocument )    
    dim sSplitCurrentTestDocument() as STRING
    sSplitCurrentTestDocument() = split ( sCurrentTestDocument , "." )
    dim sCurrentFileName as STRING
    sCurrentFileName = sSplitCurrentTestDocument ( 0 )
    dim sCurrentExtension as STRING
    sCurrentExtension = sSplitCurrentTestDocument ( 1 )   
    dim sCurrentOLE as STRING
    sCurrentOLE = left ( sCurrentTestDocument , 3 )
    dim sExtNames( 5 ) AS String
    dim sCurrentExtensionOasis as STRING
    select case sCurrentExtension
           case ( "doc" ) : sExtNames() = hGetFilternameExtension ( "writer8" )
           case ( "xls" ) : sExtNames() = hGetFilternameExtension ( "calc8" )
           case ( "ppt" ) : sExtNames() = hGetFilternameExtension ( "impress8" )
    end select
    sCurrentExtensionOasis = " (." & sExtNames(0) & ")"
    dim sCurrentFilter as STRING
    select case sCurrentExtension
           case ( "doc" ) : sCurrentFilter = "writer8"
           case ( "xls" ) : sCurrentFilter = "calc8"
           case ( "ppt" ) : sCurrentFilter = "impress8"
    end select   
    dim sConversionSettings as STRING  
    dim sStorageName as STRING
    sStorageName = ( gOfficePath & ConvertPath("user\work\xml_") & sCurrentFileName )
    dim sOutputFile as STRING
    dim sUnpackedStorageDir as STRING
    dim sContentXML as STRING
    dim sContentXMLObject as STRING
    dim bContentXMLObjectExists as BOOLEAN
    dim sRelativePathToObject as STRING           
    for iIndex = 1 to 4        
        printlog "Set desired conversion options in Tools::Options::Load/Save::MS Office"
        select case iIndex
               case 1 : sConversionSettings = "RESET"
               case 2 : sConversionSettings = "SAVE"  
               case 3 : sConversionSettings = "LOAD"
               case 4 : sConversionSettings = "ALL"
        end select
        call subSetConversionMicrosoftOLE (  sConversionSettings  )
        sleep(2)
        sOutputFile = sStorageName & "_" & sConversionSettings & "." & sExtNames(0)
        sUnpackedStorageDir = sOutputFile & "_unpacked" 
        'Erase storage dirctory if exists
        if (dir ( sUnpackedStorageDir ) <> "" ) then
            rmDir ( sUnpackedStorageDir )
            if (dir ( sUnpackedStorageDir ) <> "" ) then
                warnlog "Removing directory failed. Exiting test."
                goto endsub
            endif
        endif
        sContentXML = sUnpackedStorageDir & ConvertPath( "\content.xml" )                
        printlog "Open test document (MS format)"
        call hFileOpen(sInputFile)
        printlog Chr(13) & "Loading: " & sInputFile
        sleep(2)        
        printlog "Save document in OpenDocument format"
        if hFileSaveAsWithFilterKill ( sOutputFile , sCurrentFilter ) = FALSE then
            warnlog "Saving the testdocument failed!"
        endif
        sleep(2)        
        printlog "Close document"
        call hCloseDocument                
        sleep(2)                
        printlog "Unpack storage to obtain the XML files"        
        try 
            UnpackStorage( sOutputFile , sUnpackedStorageDir )
        catch
            qaErrorLog "#i52632# - Unpacking XML storage failed -> we quit this iteration"
            goto skipThisIteration 'Quit only current Iteration (not testcase) on error
        endcatch                
        printlog "Read DOM of content.xml"
        SAXReadFile( sContentXML )
        sleep(2)        
        printlog "Set the DOM pointer on element 'office:body'"        
        SAXSeekElement( "/" )
        SAXSeekElement( "office:document-content" )
        SAXSeekElement( "office:body" )        
        printlog "Use recursion to find XML element 'draw:object-ole' or'draw:object'"
        select case sConversionSettings
               case "RESET" , "SAVE"
                    if hXMLSeekElementInTree ( "draw:object-ole" ) = FALSE then
                        warnlog "Not finding the node 'draw:object-ole' is unexpected -> Check this out!"
                        SAXRelease
                        goto skipThisIteration 'Quit only current Iteration (not testcase) on error
                    endif
               case "LOAD" , "ALL"
                    if hXMLSeekElementInTree ( "draw:object" ) = FALSE then
                        warnlog "Not finding the node 'draw:object' is unexpected -> Check this out!"
                        SAXRelease
                        goto skipThisIteration 'Quit only current Iteration (not testcase) on error
                    endif
        end select        
        sRelativePathToObject = SAXGetAttributeValue( "xlink:href" )
        sRelativePathToObject = Right ( sRelativePathToObject , Len ( sRelativePathToObject ) - 1 )
        sContentXMLObject = sUnpackedStorageDir & ConvertPath ( sRelativePathToObject & "\content.xml" )
        printlog "Check existence of objects 'content.xml' in dependency of settings in Tools::Options::Load/Save::MS_Office"        
        printlog "Lookup if objects 'content.xml' exists - TRUE for OASIS OLE, FALSE for MS OLE"
        if (dir ( sContentXMLObject ) <> "" ) then
            bContentXMLObjectExists = TRUE
        else
            bContentXMLObjectExists = FALSE
        endif        
        printlog "Verify result against expectations for existence of objects 'content.xml'"
        select case sConversionSettings
               case "RESET" , "SAVE"
                    if bContentXMLObjectExists then
                        warnlog "+ OOPS, 'content.xml' shouldn't exist in MS OLE directory -> Check this out!" 
                    endif
               case "LOAD" , "ALL"
                    if bContentXMLObjectExists = FALSE then
                        warnlog "+ OOPS, 'content.xml' must exist in OASIS OLE directory -> Check this out!"
                    endif
        end select        
        printlog "Release documents DOM"
        SAXRelease
        if bContentXMLObjectExists then
            printlog "Read the OLE object DOM."            
            SAXReadFile( sContentXMLObject )
            sleep(2)            
            printlog "Check if expected OLE object was found in 'content.xml'"
            SAXSeekElement( "/" )
            select case sCurrentOLE
                   case "mat"
                        SAXSeekElement( 1 )
                        if SAXGetElementName() <> "math" then
                            warnlog "A Math object was expected here -> Check this out!"
                        endif
                   case else
                        SAXSeekElement( "office:document-content" )
                        SAXSeekElement( "office:body" )
                        SAXSeekElement( 1 )
                        select case sCurrentOLE
                               case "exc"
                                    if SAXGetElementName() <> "office:spreadsheet" then
                                        warnlog "+ OOPS, this OLE seems to be no spreadsheet -> Check this out!"
                                    endif
                               case "ppt"
                                    if SAXGetElementName() <> "office:presentation" then
                                        warnlog "+ OOPS, this OLE seems to be no presentation -> Check this out!"
                                    endif
                               case "wor"
                                    if SAXGetElementName() <> "office:text" then
                                        warnlog "+ OOPS, this OLE seems to be no text -> Check this out!"
                                    endif
                        end select
            end select
            SAXRelease
        endif
     skipThisIteration:
     next iIndex
endcase
'
'-----------------------------------------------------------------------------
'
sub subSetConversionMicrosoftOLE ( OPTIONAL sConversionType as STRING )
'Routine to adjust the behaviour of Tools::Options::Load/Save::Microsoft Office
'Possible Keys for 'sConversionType' are:
'RESET (or omitted): Uncheck all boxes (default in a freshly installed OOo))
'ALL: Check all boxes 
'LOAD: Check all boxes for loading MS OLE objects (left side), uncheck all boxes for saving
'SAVE: Check all boxes for saving MS OLE objects (right side), uncheck all boxes for loading
'For other values the subroutine will exit

    if IsMissing ( sConversionType ) then
       sConversionType = "RESET"
    end if
    dim iPosInAuswahl as INTEGER
    dim iExtraToggle as INTEGER
    
    'Determine value of 'iExtraToggle' for known keys
    select case sConversionType
           case "RESET" : iExtraToggle = 1
           case "ALL"   : iExtraToggle = 2
           case "LOAD"  : iExtraToggle = 3
           case "SAVE"  : iExtraToggle = 4
           case else 
                warnlog "Unknown keyword for paramter -> Exit the subroutine"
                qaErrorLog "Valid keywords are RESET, ALL, LOAD and SAVE!"
                exit sub
    end select
    
    printlog "Invoke Tools::Options"       
    ToolsOptions
    printlog "Go to tabpage Load/Save::Microsoft Office"
    call hToolsOptions ( "LOADSAVE" , "MICROSOFTOFFICE" )    
    printlog "Go to top entry in listbox"
    Auswahl.TypeKeys( "<PageUp>" )        
    printlog "Toggle (in a tricky way) to a defined state of checkboxes"
    for iPosInAuswahl = 1 to 4
         Auswahl.TypeKeys ( "<RIGHT>" , 2 )
         while NOT Auswahl.IsChecked
             Auswahl.TypeKeys ( "<Space>" )
         wend
         while Auswahl.IsChecked
             Auswahl.TypeKeys ( "<Space>" )
         wend         
         printlog "Toggle to desired state of boxes"
         Auswahl.TypeKeys ( "<Space>" , iExtraToggle )         
         printlog "Go one entry down in list box"
         Auswahl.TypeKeys ( "<Down>" )         
         printlog "Loop for all lines"
    next iPosInAuswahl        
    printlog "Quit dialog"
    Kontext "OptionenDLG"
    OptionenDLG.Ok    
end sub