merge the formfield patch from ooo-build
[ooovba.git] / testautomation / xml / optional / includes / c_datapilot_pagefields.inc
blobe16d6a564e976b08cf0e502aa84f6a465a8a8238
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: c_datapilot_pagefields.inc,v $
11 '* $Revision: 1.2 $
13 '* last change: $Author: rt $ $Date: 2008-07-11 07:28:50 $
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 : Check content.xml for attribute 'table:selected-page'
38 '*************************************************************************************************
40 ' #1 subPageFields
41 ' #1 tDatapilotPagefields
43 '\*************************************************************************************************
44 sub subPageFields
45   printLog Chr(13) + "---------  datapilot pagefields  ----------"
47      printlog "Testing Page '- all -'"
48      call tDatapilotPagefields("- all -")
49      printlog "Testing Page 'Audio'"
50      call tDatapilotPagefields("Audio")
51      printlog "Testing Page 'DVD'"
52      call tDatapilotPagefields("DVD")
53      printlog "Testing Page 'Video'"
54      call tDatapilotPagefields("Video")
56 end sub
58 '************************************************************
59 testcase tDatapilotPagefields ( sCurrentPage as STRING )
60     dim bTableSelectedPageShouldExist as BOOLEAN
61     dim iIndex as INTEGER
62     dim sComfirmAttribute as STRING
63     dim sWarnAttribute as STRING
64     select case sCurrentPage
65            case ("- all -") : bTableSelectedPageShouldExist = "false"
66                               iIndex = 1
67            case ("Audio")   : bTableSelectedPageShouldExist = "true"
68                               iIndex = 2
69                               sComfirmAttribute = "OK, value for attribute 'table:selected-page' is 'Audio'"
70                               sWarnAttribute = "Unexpected value for attibute 'table:selected-page' -> Check this out!" 
71            case ("DVD")     : bTableSelectedPageShouldExist = "true"
72                               iIndex = 3
73                               sComfirmAttribute = "OK, value for attribute 'table:selected-page' is 'DVD'"
74                               sWarnAttribute = "Unexpected value for attibute 'table:selected-page' -> Check this out!" 
75            case ("Video")   : bTableSelectedPageShouldExist = "true"
76                               iIndex = 4
77                               sComfirmAttribute = "OK, value for attribute 'table:selected-page' is 'Video'"
78                               sWarnAttribute = "Unexpected value for attibute 'table:selected-page' -> Check this out!" 
79     end select
81 dim sInputFile as STRING
82     sInputFile = ( gTesttoolPath & ConvertPath( "xml\optional\input\calc\ooo10\pagefields_datapilot" & iIndex & ".sxc" ))
83     
84 dim sOutputFile as STRING
85     sOutputFile = ( gOfficePath & ConvertPath( "user\work\datapilotPagefields" ) & iIndex & ".ods" )
86     
87 dim sUnpackedStorageDir as STRING
88     sUnpackedStorageDir = ( gOfficePath & ConvertPath( "user\work\datapilotPagefields" ) & iIndex )
89     if (dir(sUnpackedStorageDir) <> "") then
90         rmDir (sUnpackedStorageDir)
91         if (dir(sUnpackedStorageDir) <> "") then
92             warnlog "Directory has not been deleted. Test ends here."
93             goto endsub
94         endif
95     endif
96     
97 dim sContentXML as STRING
98     sContentXML = ( gOfficePath & ConvertPath( "user\work\datapilotPagefields" ) & iIndex & ConvertPath( "\content.xml" ))
99     
100 dim iSaxSeekIndex as INTEGER
101     iSaxSeekIndex = 1
102     
103 dim bContinueSeek as BOOLEAN
104     bContinueSeek = TRUE
105     
106 dim iAttributeIndex as INTEGER
107     
108     printlog "Open test document"
109     call hFileOpen ( sInputFile )       
110     printlog "Save in current default application format (ODF)"
111     if hFileSaveAsWithFilterKill ( sOutputFile , "calc8" ) = FALSE then
112        warnlog "Saving " & sOutputFile & " failed! -> Exiting test!"
113        call hCloseDocument
114        goto endsub
115     else
116        printlog "CLose the document."
117        call hCloseDocument              
118        printlog "Unpack storage of test document."
119        UnpackStorage( sOutputFile , sUnpackedStorageDir )
120        printlog "Read the test documents DOM."       
121        SAXReadFile( sContentXML )
122        sleep(2)       
123        printlog "Set the DOM pointer on element 'table:data-pilot-table'"
124        printlog "|-/"
125        SAXSeekElement( "/" )
126        printlog "  |-office:document-content"
127        SAXSeekElement( "office:document-content" )
128        printlog "    |-office:body"
129        SAXSeekElement( "office:body" )
130        printlog "      |-office:spreadsheet"
131        SAXSeekElement( "office:spreadsheet" )
132        printlog "        |-table:data-pilot-tables"
133        SAXSeekElement( "table:data-pilot-tables" )
134        printlog "          |-table:data-pilot-table"
135        SAXSeekElement( "table:data-pilot-table" )              
136        printlog "Seek in (all) elements 'table:data-pilot-field'"
137        while SAXHasElement( "table:data-pilot-field" , iSaxSeekIndex ) AND bContinueSeek
138              printlog "            |-table:data-pilot-field"
139              SAXSeekElement( "table:data-pilot-field" , iSaxSeekIndex )             
140              printlog ".. for attribute 'table:selected-page'"
141              for iAttributeIndex = 1 to SAXGetAttributeCount
142                 if SaxGetAttributeName ( iAttributeIndex ) = "table:selected-page" then                
143                 printlog "When found, check if it should exist (unexpected for page selection '- all -')"
144                    bContinueSeek = FALSE
145                    if bTableSelectedPageShouldExist then
146                       printlog "Bingo, found attribute 'table:selected-page'"
147                       'Check correct index of expected node
148                       if iSaxSeekIndex <> 1 then
149                            warnlog "Found 'table:selected-page' on an unexpected Node -> Check this out!"
150                            qaErrorLog "TODO: Check if change of file format was announced!"
151                            qaErrorLog "TODO: Modify test if change of file format was intended!"
152                        endif
153                        'Check correct attribute index
154                        if iAttributeIndex <> 3 then
155                            warnlog "Found 'table:selected-page' on unexpected attribute position -> Check this out!"
156                            qaErrorLog "TODO: Check if change of file format was announced!"
157                            qaErrorLog "TODO: Modify test if change of file format was intended!"
158                        endif                       
159                        printlog "Now check for expected value of 'table:selected-page'!"
160                        if SAXGetAttributeValue( "table:selected-page" ) = sCurrentPage then
161                            printlog sComfirmAttribute
162                        else
163                            warnlog sWarnAttribute
164                        endif
165                    else
166                        warnlog "OOPS, attribute 'table:selected-page' shouldn't exist for '- all -' pages."
167                    endif
168                 endif
169              next iAttributeIndex
170              iSaxSeekIndex = iSaxSeekIndex + 1
171              SAXSeekElement( 0 )
172        wend
173     endif
174     ' Throw warning if testcase didn't succeed at all!
175     if bContinueSeek AND bTableSelectedPageShouldExist then
176         warnlog "OOPS, attribute 'table:selected-page' wasn't found though it should exist -> Check this out!"
177     endif
178    'Release DOM
179     SAXRelease
180 endcase