update dev300-m58
[ooovba.git] / testautomation / writer / optional / includes / loadsave / w_loadsave.inc
blobad2c3122da6353a89f0c2d9e27c4918a7abfee37
1 'encoding UTF-8  Do not remove or change this line!
2 '**************************************************************************
3 '* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 '* 
5 '* Copyright 2008 by Sun Microsystems, Inc.
6 '*
7 '* OpenOffice.org - a multi-platform office productivity suite
8 '*
9 '* $RCSfile: w_loadsave.inc,v $
11 '* $Revision: 1.1.4.3 $
13 '* last change: $Author: fredrikh $ $Date: 2008/10/06 18:36:45 $
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 : helge.delfs@sun.com
36 '* short description : Checks the export to all available Filters from 
38 '***********************************************************************
40 ' #1 tExportAllReadableFormatsIntoODF
41 ' #1 tExportAllReadableFormatsIntoThemselves
42 ' #1 tExportTop5FormatsIntoTop5
44 '\***********************************************************************
46 testcase tExportAllReadableFormatsIntoODF
48         if iSprache <> 1 then
49                 QAErrorlog "#100970#test only support english language"
50                 goto endsub
51         end if
53     Dim AvailableFilters( 35 ) as String
54     Dim TemplateFilterFile as String
55     Dim ImportFileList ( 300 ) as String
56     Dim ExportFileList ( 300 ) as String
57     Dim WorkDirectory as String
58     Dim ImportDir as String
59     Dim SavedCorrectly as Boolean
60         Dim sExportFilter as string
61         Dim sExportFile as string
62     Dim i as Integer
64     TemplateFilterFile = ConvertPath ( gTesttoolPath + "writer\optional\input\filterlist.txt")
65     WorkDirectory = ( ConvertPath ( gOfficePath + "user\work\" + gPlatgroup + "\export\"))
66     ImportDir = ConvertPath ( gTesttoolPath + "writer\optional\input\import\")
68     if gSamePC = TRUE then ' delete export directory
69         GetFileList ( WorkDirectory, "*.*", ExportFileList() )
70         if KillFileList ( ExportFileList() ) <> TRUE then
71             Warnlog "Couldn't delete all Files in Output-Directory, the followings are still there:"
72             for i=1 to FehlerListe(0)
73                 printlog "  <> " & FehlerListe(i)
74             next i
75                         goto endsub
76         end if
77     end if
78     app.Mkdir WorkDirectory
80     Printlog "- Read the directory with files we wish to import."
81     GetFileList ( ImportDir, "*.*", ImportFileList() )
82     printlog "-  Done."
84     printlog "- Start loading files in list"
85         For i = 1 to listCount(ImportFileList())
86                 printlog "- " & i & ". load: " & ImportFileList(i)
87         Call hFileOpen ( ImportFileList(i) )
88                 printlog "-  done"
90                 Kontext "TextImport"
91                 if TextImport.Exists then
92                         TextImport.Ok
93                         printlog "-  Text import dialog passed"
94                 end if
96                 Kontext "Filterauswahl"
97                 if Filterauswahl.Exists then
98                         Filterauswahl.Cancel
99                         printlog "-  Filterdialog passed"
100                 end if
102                 Kontext "AsciiFilterOptionen"
103                 if AsciiFilterOptionen.Exists then
104                         AsciiFilterOptionen.Ok
105                         printlog "-  ASCII-Filter dialog passed"
106                 end if
108                 Kontext "SecurityWarning"
109                 if SecurityWarning.Exists(3) then
110                         SecurityWarning.Ok
111                         printlog "-  Security warning passed"
112                 end if
114                 Kontext "DocumentWriter"
115                 if DocumentWriter.Exists(3) then
116                         Do until DocumentWriter.StatusIsProgress = false
117                                 wait 500
118                         Loop
119                 else
120                         Kontext "DocumentCalc"
121                         if DocumentCalc.Exists(3) then
122                                 Do until DocumentCalc.StatusIsProgress = false
123                                         wait 500
124                                 Loop
125                         else
126                                 Warnlog "Neither DocumentWriter or DocumentCalc existed? Some other dialogue in focus?"
127                         end if
128                 end if
130                 ' Check for macro alert
131                 Kontext "SecurityWarning"
132                 if SecurityWarning.Exists then
133                         if inStr(ImportFileList(i),"sw40") = false then
134                                 QAErrorlog "Macro-Security Warning is up though document should have no macro! Macro disabled"
135                         end if
136                         SecurityWarning.Cancel
137                 end if
138                 Sleep 1
140                 Kontext "AlienWarning"
141                 if AlienWarning.Exists then
142                         AlienWarning.Ok
143                         printlog "-  Alien warning passed"
144                 end if
146                 ' HTML-File can't be exported as odf this way
147                 if GetExtention(ImportFileList(i)) <> "html" then               
148                 
149                         sExportFile = WorkDirectory & "ExportedFile" & i & ".odf"
150                         Printlog "-  Save as : " & ConvertPath ( sExportFile )
151                         if hFileSaveAsWithFilterKill (sExportFile, "writer8") = true then
152                                 printlog "-  done"
153                                 printlog "-  close file"
154                                 Call hCloseDocument
155         
156                                 Printlog "-  Open previous saved file"
157                                 Call hFileOpenWithFilter (sExportFile, "writer8")
158                                 printlog "-  done"
159                                 ' Check for macro alert
160                                 Kontext "SecurityWarning"
161                                 if SecurityWarning.Exists then
162                                         if inStr(ImportFileList(i),"sw40")  = false then
163                                                 QAErrorlog "Macro-Security Warning is up though document should have no macro! Macro disabled"
164                                         end if
165                                         SecurityWarning.Cancel
166                                 end if
167                                 Sleep 1
168                         else
169                                 Warnlog "Unable to save file: " & sExportFile
170                         end if
171                 else
172                         printlog "-  HTML-file is not exported this way"
173                 end if
175                 printlog "-  Close all open files."
176                 Do Until GetDocumentCount = 0
177                         Call hCloseDocument
178                 Loop
179     next i 'File
181 endcase
183 '---------------------------------------------------------------------------------------------------------------------
185 testcase tExportAllReadableFormatsIntoThemselves
187         if iSprache <> 1 then
188                 QAErrorlog "#100970#test only support english language"
189                 goto endsub
190         end if
191         
192     Dim AvailableFilters( 35 ) as String
193     Dim TemplateFilterFile as String
194     Dim SavedCorrectly as Boolean
195     Dim ImportFileList ( 300 ) as String
196     Dim ExportFileList ( 300 ) as String
197     'Used - below
198     Dim sLoadFile as String
199     Dim sSaveFile as String
200     Dim sCurrentFile as String
201     Dim sCurrentFilter as String
202     Dim sWorkDirectory as String
203     Dim sImportDir as String
204     Dim iCurrentFileIndex as Integer
205     Dim iCounter as integer
206     Dim DocumentCount as integer
208     TemplateFilterFile = ConvertPath ( gTesttoolPath + "writer\optional\input\filterlist.txt")
209     sWorkDirectory = ( ConvertPath ( gOfficePath + "user\work\" + gPlatgroup + "\export\"))
210     sImportDir = ConvertPath ( gTesttoolPath + "writer\optional\input\import\")
212     if gSamePC = TRUE then ' delete export directory
213         GetFileList ( sWorkDirectory, "*.*", ExportFileList() )
214         if KillFileList ( ExportFileList() ) <> TRUE then
215             Warnlog "Couldn't delete all Files in Output-Directory, the followings are still there:"
216             for iCounter=1 to FileList(0)
217                 printlog "  <> " & FileList(i)
218             next iCounter
219         end if
220     end if
221     app.Mkdir sWorkDirectory
223         QAErrorlog "#i102221#Pocketword-filter seems broken."
225     For iCurrentFileIndex = 1 to 16
226         select case iCurrentFileIndex
227                     case 1 :   sCurrentFile = "xml2.odt"
228                                     sCurrentFilter = "writer8"
229                     case 2 :    sCurrentFile = "wpsfile.wps"
230                                     sCurrentFilter = "Text (encoded)"
231                     case 3 :    sCurrentFile = "dostext.txt"
232                                     sCurrentFilter = "Text (encoded)"
233                     case 4 :   sCurrentFile = "sw30.sdw"
234                                      sCurrentFilter = "StarWriter 3.0"
235                     case 5 :   sCurrentFile = "sw50.vor"
236                                      sCurrentFilter = "StarWriter 5.0 Vorlage/Template"
237                     case 6 :   sCurrentFile = "sw31.sdw"
238                                      sCurrentFilter = "StarWriter 3.0"
239                     case 7 :   sCurrentFile = "sw31.vor"
240                                      sCurrentFilter = "StarWriter 3.0 Vorlage/Template"
241                     case 8 :   sCurrentFile = "sw40.sdw"
242                                      sCurrentFilter = "StarWriter 4.0"
243                     case 9 :   sCurrentFile = "sw40_sp2.vor"
244                                      sCurrentFilter = "StarWriter 4.0 Vorlage/Template"
245                     case 10 : sCurrentFile = "sw50.sdw"
246                                      sCurrentFilter = "StarWriter 5.0"
247                     case 11 : sCurrentFile = "html.html"
248                                      sCurrentFilter = "HTML (StarWriter)"
249                     case 12 : sCurrentFile = "rtf.rtf"
250                                      sCurrentFilter = "Rich Text Format"
251                     case 13 : sCurrentFile = "sw60.sxw"
252                                      sCurrentFilter = "StarOffice XML (Writer)"
253                     case 14 : sCurrentFile = "winw97.doc"
254                                      sCurrentFilter = "MS Word 97"
255                     case 15 : sCurrentFile = "winword6.doc"
256                                      sCurrentFilter = "MS Word 95"
257                     case 16 : sCurrentFile = "wintext.txt"
258                                      sCurrentFilter = "Text (encoded)"
259 '                    case 17 : sCurrentFile = "pocketword.psw"
260 '                                     sCurrentFilter = "PocketWord File"
263 'TODO: 18-23 not applyable. Can be opened, but saving in the format is not supported.
265 '                    case 18 : sCurrentFile = "unixtext.txt"
266 '                                     sCurrentFilter = "Text"
267 '                    case 19 : sCurrentFile = "sw2.sdw"
268 '                                     sCurrentFilter = "StarWriter 2.0"
269 '                    case 20 : sCurrentFile = "amipro3.sam"
270 '                                     sCurrentFilter = "Ami Pro 1.x-3.1 (W4W)"
271 '                    case 21 : sCurrentFile = "mactext.txt"
272 '                                     sCurrentFilter = "Mac Write 4.x 5.0 (W4W)"
273 '                    case 22 : sCurrentFile = "sw1.sdw"
274 '                                     sCurrentFilter = "StarWriter 1.0"
275 '                    case 23 : sCurrentFile = "swdoc.txt"
276 '                                     sCurrentFilter = "Text (encoded) (StarWriter/GlobalDocument)"
277 '                    case 24 : sCurrentFile = "hangul.hwp"
278 '                                     sCurrentFilter = "writer_MIZI_Hwp_97"
279         end select
281         printlog " - Export of File nr " + iCurrentFileIndex + " started."
282         
283         sLoadFile = sImportDir & sCurrentFile
284         sSaveFile = sWorkDirectory & "filenr_" & iCurrentFileIndex
286         try 
288             ' Load In-file
289             Call hFileOpenWithFilter(sLoadFile, sCurrentFilter, false)
291             kontext "active"
292             if active.exists(2) then 
293                 active.ok
294                 warnlog "Error with file " + sLoadFile + " as " + sSaveFile + "."
295             end if
297                 Kontext "TextImport"
298                 if TextImport.Exists then
299                     TextImport.Ok
300                 end if
302                 Kontext "Filterauswahl"
303                 if Filterauswahl.Exists then
304                     Filterauswahl.Cancel
305                 end if
307                 Kontext "AsciiFilterOptionen"
308                 if AsciiFilterOptionen.Exists then AsciiFilterOptionen.Ok
309                 Kontext "SecurityWarning"
310                 if SecurityWarning.Exists(3) then SecurityWarning.Ok
311                 Kontext "DocumentWriter"
312                 if DocumentWriter.Exists(3) then
313                     Do until DocumentWriter.StatusIsProgress = false
314                         wait 500
315                     Loop
316                 else
317                     Kontext "DocumentCalc"
318                     if DocumentCalc.Exists(3) then
319                         Do until DocumentCalc.StatusIsProgress = false
320                             wait 500
321                         Loop
322                     else
323                         Warnlog "Neither DocumentWriter or DocumentCalc existed? Some other dialogue in focus?"
324                     end if
325                 end if
327                 ' Check for macro alert
328                 Kontext "SecurityWarning"
329                 if SecurityWarning.Exists then
330                     if inStr(currentfile,"sw40") = false then
331                         QAErrorlog "Macro-Security Warning is up though document should have no macro! Macro disabled"
332                     end if
333                     SecurityWarning.Cancel
334                 end if
335                 Sleep 1
337                 Kontext "AlienWarning"
338                 if AlienWarning.Exists then AlienWarning.Ok
340             ' Save Out-file
341             Call hFileSaveAsWithFilterKill(sSaveFile, sCurrentFilter)
343             kontext "active"
344             if active.exists(2) then 
345                 active.ok
346                 warnlog "Error saving file " + sLoadFile + " as " + sSaveFile + "."
347                 goto Cleanup
348             end if
350             ' Load Out-file again
351             Call hFileOpenWithFilter(sSaveFile, sCurrentFilter, false)
353             ' Check for macro alert
354             Kontext "SecurityWarning"
355             if SecurityWarning.Exists then
356                 if inStr(currentfile,"sw40") > 0 then
357                     QAErrorlog "Macro-Security Warning is up though document should have no macro! Macro disabled"
358                 end if
359                 SecurityWarning.Cancel
360             end if
361             Sleep 1
363         catch
364             Warnlog "Error with file: " + sLoadFile
365         endcatch
367         Cleanup:
368         kontext "active"
369         if active.exists(2) then 
370             active.ok
371             warnlog "Error with file " + sLoadFile + " as " + sSaveFile + "."
372         end if
374         printlog "   Close all open files."
375         Do Until GetDocumentCount = 0
376             Call hCloseDocument
377         Loop
379         printlog " - File nr " + iCurrentFileIndex + " completed."
380     Next iCurrentFileIndex
382 endcase
384 '---------------------------------------------------------------------------------------------------------------------
386 testcase tExportTop5FormatsIntoTop5
388         if iSprache <> 1 then
389                 QAErrorlog "#100970#test only support english language"
390                 goto endsub
391         end if
393     Dim ExportFileList(300) as String
394     Dim sWorkDirectory as String
395     Dim sImportDir as String
396     Dim iCurrentLoadFileIndex as Integer
397     Dim sCurrentLoadFile as String
398     Dim sCurrentLoadFilter as String
399     Dim iCurrentSaveFileIndex as Integer
400     Dim sCurrentSaveFile as String
401     Dim sCurrentSaveFilter as String
402     Dim iCounter as Integer
403     Dim DocumentCount as Integer
404     Dim FileList as String
406     sWorkDirectory = ( ConvertPath ( gOfficePath + "user\work\" + gPlatgroup + "\loadsavetop5\"))
407     sImportDir = ConvertPath ( gTesttoolPath + "writer\optional\input\import\")
409     if gSamePC = TRUE then ' delete export directory
410         GetFileList ( sWorkDirectory, "*.*", ExportFileList() )
411         if KillFileList ( ExportFileList() ) <> TRUE then
412             Warnlog "Couldn't delete all Files in Output-Directory, the followings are still there:"
413             for iCounter=1 to FileList(0)
414                 printlog "  <> " & FileList(i)
415             next iCounter
416         end if
417     end if
418     app.Mkdir sWorkDirectory
420     '// Start of the LOAD-Loop
421     For iCurrentLoadFileIndex = 1 to 4
422         Select case iCurrentLoadFileIndex
423                     case 1 :  sCurrentLoadFile = "xml2.odt"
424                                     sCurrentLoadFilter = "writer8"
425                     case 2 :  sCurrentLoadFile = "sw60.sxw"
426                                     sCurrentLoadFilter = "StarOffice XML (Writer)"
427                     case 3 :  sCurrentLoadFile = "winw97.doc"
428                                     sCurrentLoadFilter = "MS Word 97"
429                     case 4 :  sCurrentLoadFile = "rtf.rtf"
430                                     sCurrentLoadFilter = "Rich Text Format"
431                     case 5 :  sCurrentLoadFile = "html.html"
432                                     sCurrentLoadFilter = "HTML (StarWriter)"
433         End select
435         printlog " - Export of File nr " + iCurrentLoadFileIndex + " started."
437         call fLoadTheFile((sImportDir & sCurrentLoadFile), sCurrentLoadFilter)
439         '///  Here comes the SAVE-Loop
440         For iCurrentSaveFileIndex = 1 to 5
441                 Select case iCurrentSaveFileIndex
442                             case 1 : sCurrentSaveFile = "SavedFile_l" + iCurrentLoadFileIndex + "_s1.odt"
443                                            sCurrentSaveFilter = "writer8"
444                             case 2 : sCurrentSaveFile = "SavedFile_l" + iCurrentLoadFileIndex + "_s2.sxw"
445                                            sCurrentSaveFilter = "StarOffice XML (Writer)"
446                             case 3 : sCurrentSaveFile = "SavedFile_l" + iCurrentLoadFileIndex + "_s3.doc"
447                                            sCurrentSaveFilter = "MS Word 97"
448                             case 4 : sCurrentSaveFile = "SavedFile_l" + iCurrentLoadFileIndex + "_s4.rtf"  
449                                            sCurrentSaveFilter = "Rich Text Format"
450                             case 5 : sCurrentSaveFile = "SavedFile_l" + iCurrentLoadFileIndex + "_s5.html"
451                                            sCurrentSaveFilter = "HTML (StarWriter)"
452                 End select
454                 Call hFileSaveAsWithFilterKill((sWorkDirectory & sCurrentSaveFile), sCurrentSaveFilter)
456                 if hFileExists (sWorkDirectory & sCurrentSaveFile) then
458                     'Check if the saved file can be loaded
459                     call fLoadTheFile((sWorkDirectory & sCurrentSaveFile), sCurrentSaveFilter)
461                     'Close the opened file
462                     Do Until GetDocumentCount = 1
463                         Call hCloseDocument
464                     Loop
465                 end if
467         Next iCurrentSaveFileIndex
468         '///  Here ends the Save-Loop
470         Cleanup:
471         kontext "active"
472         if active.exists(2) then
473             active.ok
474             warnlog "Error. Last file processed: " + sCurrentLoadFile + " as " + sCurrentSaveFile + "."
475         end if
477         printlog "   Close all open files."
479         Do Until GetDocumentCount = 0
480             Call hCloseDocument
481         Loop
483         printlog " - File nr " + iCurrentLoadFileIndex + " completed."
484     Next iCurrentLoadFileIndex
485     '// End of the LOAD-Loop.
486 endcase
488 '---------------------------------------------------------------------------------------------------------------------
490 function fLoadTheFile(sLoadFile as string, sCurrentFilter as string)
492         try
493             ' Load In-file
494             Call hFileOpenWithFilter(sLoadFile, sCurrentFilter, false)
496             kontext "active"
497             if active.exists(2) then 
498                 active.ok
499                 warnlog "Error with file " + sLoadFile + " as " + sSaveFile + "."
500             end if
502                 Kontext "TextImport"
503                 if TextImport.Exists then
504                     TextImport.Ok
505                 end if
507                 Kontext "Filterauswahl"
508                 if Filterauswahl.Exists then
509                     Filterauswahl.Cancel
510                 end if
512                 Kontext "AsciiFilterOptionen"
513                 if AsciiFilterOptionen.Exists then AsciiFilterOptionen.Ok
514                 Kontext "SecurityWarning"
515                 if SecurityWarning.Exists(3) then SecurityWarning.Ok
516                 Kontext "DocumentWriter"
517                 if DocumentWriter.Exists(3) then
518                     Do until DocumentWriter.StatusIsProgress = false
519                         wait 500
520                     Loop
521                 else
522                     Kontext "DocumentCalc"
523                     if DocumentCalc.Exists(3) then
524                         Do until DocumentCalc.StatusIsProgress = false
525                             wait 500
526                         Loop
527                     else
528                         Warnlog "Neither DocumentWriter or DocumentCalc existed? Some other dialogue in focus?"
529                     end if
530                 end if
532                 ' Check for macro alert
533                 Kontext "SecurityWarning"
534                 if SecurityWarning.Exists then
535                     if inStr(currentfile,"sw40") > 0 then
536                         QAErrorlog "Macro-Security Warning is up though document should have no macro! Macro disabled"
537                     end if
538                     SecurityWarning.Cancel
539                 end if
540                 Sleep 1
542                 Kontext "AlienWarning"
543                 if AlienWarning.Exists then AlienWarning.Ok
545         catch
546             Warnlog "Error with file: " + sLoadFile
547         endcatch
548 end function 'fLoadTheFile
550 '------------------------------------------------------------------------------------------------------------------------------------------------