1 'encoding UTF-8 Do not remove or change this line!
2 '**************************************************************************
3 '* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 '* Copyright 2008 by Sun Microsystems, Inc.
7 '* OpenOffice.org - a multi-platform office productivity suite
9 '* $RCSfile: f_xml_save_ms_ole.inc,v $
13 '* last change: $Author: rt $ $Date: 2008-07-11 07:31:08 $
15 '* This file is part of OpenOffice.org.
17 '* OpenOffice.org is free software: you can redistribute it and/or modify
18 '* it under the terms of the GNU Lesser General Public License version 3
19 '* only, as published by the Free Software Foundation.
21 '* OpenOffice.org is distributed in the hope that it will be useful,
22 '* but WITHOUT ANY WARRANTY; without even the implied warranty of
23 '* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 '* GNU Lesser General Public License version 3 for more details
25 '* (a copy is included in the LICENSE file that accompanied this code).
27 '* You should have received a copy of the GNU Lesser General Public License
28 '* version 3 along with OpenOffice.org. If not, see
29 '* <http://www.openoffice.org/license.html>
30 '* for a copy of the LGPLv3 License.
32 '/************************************************************************
34 '* owner : oliver.craemer@sun.com
36 '* short description : Conversion of Microsoft OLE objects in dependency of settings in Tools::Options::Load/Save::MS_Office
38 '************************************************************************
40 ' #1 ms_ole ' Initial routine
41 ' #1 tXML_OLE_Conversion
42 ' #1 subSetConversionMicrosoftOLE
44 '\************************************************************************
46 testcase tXML_OLE_Conversion ( sCurrentTestDocument as STRING )
48 dim sInputFile as STRING
49 sInputFile = convertpath ( gTesttoolpath & "xml/optional/input/framework/ms_ole/" & sCurrentTestDocument )
50 dim sSplitCurrentTestDocument() as STRING
51 sSplitCurrentTestDocument() = split ( sCurrentTestDocument , "." )
52 dim sCurrentFileName as STRING
53 sCurrentFileName = sSplitCurrentTestDocument ( 0 )
54 dim sCurrentExtension as STRING
55 sCurrentExtension = sSplitCurrentTestDocument ( 1 )
56 dim sCurrentOLE as STRING
57 sCurrentOLE = left ( sCurrentTestDocument , 3 )
58 dim sExtNames( 5 ) AS String
59 dim sCurrentExtensionOasis as STRING
60 select case sCurrentExtension
61 case ( "doc" ) : sExtNames() = hGetFilternameExtension ( "writer8" )
62 case ( "xls" ) : sExtNames() = hGetFilternameExtension ( "calc8" )
63 case ( "ppt" ) : sExtNames() = hGetFilternameExtension ( "impress8" )
65 sCurrentExtensionOasis = " (." & sExtNames(0) & ")"
66 dim sCurrentFilter as STRING
67 select case sCurrentExtension
68 case ( "doc" ) : sCurrentFilter = "writer8"
69 case ( "xls" ) : sCurrentFilter = "calc8"
70 case ( "ppt" ) : sCurrentFilter = "impress8"
72 dim sConversionSettings as STRING
73 dim sStorageName as STRING
74 sStorageName = ( gOfficePath & ConvertPath("user\work\xml_") & sCurrentFileName )
75 dim sOutputFile as STRING
76 dim sUnpackedStorageDir as STRING
77 dim sContentXML as STRING
78 dim sContentXMLObject as STRING
79 dim bContentXMLObjectExists as BOOLEAN
80 dim sRelativePathToObject as STRING
82 printlog "Set desired conversion options in Tools::Options::Load/Save::MS Office"
84 case 1 : sConversionSettings = "RESET"
85 case 2 : sConversionSettings = "SAVE"
86 case 3 : sConversionSettings = "LOAD"
87 case 4 : sConversionSettings = "ALL"
89 call subSetConversionMicrosoftOLE ( sConversionSettings )
91 sOutputFile = sStorageName & "_" & sConversionSettings & "." & sExtNames(0)
92 sUnpackedStorageDir = sOutputFile & "_unpacked"
93 'Erase storage dirctory if exists
94 if (dir ( sUnpackedStorageDir ) <> "" ) then
95 rmDir ( sUnpackedStorageDir )
96 if (dir ( sUnpackedStorageDir ) <> "" ) then
97 warnlog "Removing directory failed. Exiting test."
101 sContentXML = sUnpackedStorageDir & ConvertPath( "\content.xml" )
102 printlog "Open test document (MS format)"
103 call hFileOpen(sInputFile)
104 printlog Chr(13) & "Loading: " & sInputFile
106 printlog "Save document in OpenDocument format"
107 if hFileSaveAsWithFilterKill ( sOutputFile , sCurrentFilter ) = FALSE then
108 warnlog "Saving the testdocument failed!"
111 printlog "Close document"
114 printlog "Unpack storage to obtain the XML files"
116 UnpackStorage( sOutputFile , sUnpackedStorageDir )
118 qaErrorLog "#i52632# - Unpacking XML storage failed -> we quit this iteration"
119 goto skipThisIteration 'Quit only current Iteration (not testcase) on error
121 printlog "Read DOM of content.xml"
122 SAXReadFile( sContentXML )
124 printlog "Set the DOM pointer on element 'office:body'"
125 SAXSeekElement( "/" )
126 SAXSeekElement( "office:document-content" )
127 SAXSeekElement( "office:body" )
128 printlog "Use recursion to find XML element 'draw:object-ole' or'draw:object'"
129 select case sConversionSettings
130 case "RESET" , "SAVE"
131 if hXMLSeekElementInTree ( "draw:object-ole" ) = FALSE then
132 warnlog "Not finding the node 'draw:object-ole' is unexpected -> Check this out!"
134 goto skipThisIteration 'Quit only current Iteration (not testcase) on error
137 if hXMLSeekElementInTree ( "draw:object" ) = FALSE then
138 warnlog "Not finding the node 'draw:object' is unexpected -> Check this out!"
140 goto skipThisIteration 'Quit only current Iteration (not testcase) on error
143 sRelativePathToObject = SAXGetAttributeValue( "xlink:href" )
144 sRelativePathToObject = Right ( sRelativePathToObject , Len ( sRelativePathToObject ) - 1 )
145 sContentXMLObject = sUnpackedStorageDir & ConvertPath ( sRelativePathToObject & "\content.xml" )
146 printlog "Check existence of objects 'content.xml' in dependency of settings in Tools::Options::Load/Save::MS_Office"
147 printlog "Lookup if objects 'content.xml' exists - TRUE for OASIS OLE, FALSE for MS OLE"
148 if (dir ( sContentXMLObject ) <> "" ) then
149 bContentXMLObjectExists = TRUE
151 bContentXMLObjectExists = FALSE
153 printlog "Verify result against expectations for existence of objects 'content.xml'"
154 select case sConversionSettings
155 case "RESET" , "SAVE"
156 if bContentXMLObjectExists then
157 warnlog "+ OOPS, 'content.xml' shouldn't exist in MS OLE directory -> Check this out!"
160 if bContentXMLObjectExists = FALSE then
161 warnlog "+ OOPS, 'content.xml' must exist in OASIS OLE directory -> Check this out!"
164 printlog "Release documents DOM"
166 if bContentXMLObjectExists then
167 printlog "Read the OLE object DOM."
168 SAXReadFile( sContentXMLObject )
170 printlog "Check if expected OLE object was found in 'content.xml'"
171 SAXSeekElement( "/" )
172 select case sCurrentOLE
175 if SAXGetElementName() <> "math:math" then
176 warnlog "A Math object was expected here -> Check this out!"
179 SAXSeekElement( "office:document-content" )
180 SAXSeekElement( "office:body" )
182 select case sCurrentOLE
184 if SAXGetElementName() <> "office:spreadsheet" then
185 warnlog "+ OOPS, this OLE seems to be no spreadsheet -> Check this out!"
188 if SAXGetElementName() <> "office:presentation" then
189 warnlog "+ OOPS, this OLE seems to be no presentation -> Check this out!"
192 if SAXGetElementName() <> "office:text" then
193 warnlog "+ OOPS, this OLE seems to be no text -> Check this out!"
203 '-----------------------------------------------------------------------------
205 sub subSetConversionMicrosoftOLE ( OPTIONAL sConversionType as STRING )
206 'Routine to adjust the behaviour of Tools::Options::Load/Save::Microsoft Office
207 'Possible Keys for 'sConversionType' are:
208 'RESET (or omitted): Uncheck all boxes (default in a freshly installed OOo))
209 'ALL: Check all boxes
210 'LOAD: Check all boxes for loading MS OLE objects (left side), uncheck all boxes for saving
211 'SAVE: Check all boxes for saving MS OLE objects (right side), uncheck all boxes for loading
212 'For other values the subroutine will exit
214 if IsMissing ( sConversionType ) then
215 sConversionType = "RESET"
217 dim iPosInAuswahl as INTEGER
218 dim iExtraToggle as INTEGER
220 'Determine value of 'iExtraToggle' for known keys
221 select case sConversionType
222 case "RESET" : iExtraToggle = 1
223 case "ALL" : iExtraToggle = 2
224 case "LOAD" : iExtraToggle = 3
225 case "SAVE" : iExtraToggle = 4
227 warnlog "Unknown keyword for paramter -> Exit the subroutine"
228 qaErrorLog "Valid keywords are RESET, ALL, LOAD and SAVE!"
232 printlog "Invoke Tools::Options"
234 printlog "Go to tabpage Load/Save::Microsoft Office"
235 call hToolsOptions ( "LOADSAVE" , "MICROSOFTOFFICE" )
236 printlog "Go to top entry in listbox"
237 Auswahl.TypeKeys( "<PageUp>" )
238 printlog "Toggle (in a tricky way) to a defined state of checkboxes"
239 for iPosInAuswahl = 1 to 4
240 Auswahl.TypeKeys ( "<RIGHT>" , 2 )
241 while NOT Auswahl.IsChecked
242 Auswahl.TypeKeys ( "<Space>" )
244 while Auswahl.IsChecked
245 Auswahl.TypeKeys ( "<Space>" )
247 printlog "Toggle to desired state of boxes"
248 Auswahl.TypeKeys ( "<Space>" , iExtraToggle )
249 printlog "Go one entry down in list box"
250 Auswahl.TypeKeys ( "<Down>" )
251 printlog "Loop for all lines"
253 printlog "Quit dialog"
254 Kontext "OptionenDLG"