1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package mod._xmloff.Chart;
25 
26 import java.io.PrintWriter;
27 
28 import lib.StatusException;
29 import lib.TestCase;
30 import lib.TestEnvironment;
31 import lib.TestParameters;
32 import util.SOfficeFactory;
33 import util.XMLTools;
34 
35 import com.sun.star.chart.XChartDocument;
36 import com.sun.star.document.XExporter;
37 import com.sun.star.lang.XMultiServiceFactory;
38 import com.sun.star.uno.Any;
39 import com.sun.star.uno.Exception;
40 import com.sun.star.uno.Type;
41 import com.sun.star.uno.UnoRuntime;
42 import com.sun.star.uno.XInterface;
43 import com.sun.star.xml.sax.XDocumentHandler;
44 
45 /**
46  * Test for object which is represented by service
47  * <code>com.sun.star.comp.Chart.XMLStylesExporter</code>. <p>
48  * Object implements the following interfaces :
49  * <ul>
50  *  <li><code>com::sun::star::lang::XInitialization</code></li>
51  *  <li><code>com::sun::star::document::ExportFilter</code></li>
52  *  <li><code>com::sun::star::document::XFilter</code></li>
53  *  <li><code>com::sun::star::document::XExporter</code></li>
54  *  <li><code>com::sun::star::beans::XPropertySet</code></li>
55  * </ul>
56  * @see com.sun.star.lang.XInitialization
57  * @see com.sun.star.document.ExportFilter
58  * @see com.sun.star.document.XFilter
59  * @see com.sun.star.document.XExporter
60  * @see com.sun.star.beans.XPropertySet
61  * @see ifc.lang._XInitialization
62  * @see ifc.document._ExportFilter
63  * @see ifc.document._XFilter
64  * @see ifc.document._XExporter
65  * @see ifc.beans._XPropertySet
66  */
67 public class XMLStylesExporter extends TestCase {
68     XChartDocument xChartDoc = null;
69 
70     /**
71      * New text document created.
72      */
initialize( TestParameters tParam, PrintWriter log )73     protected void initialize( TestParameters tParam, PrintWriter log ) {
74 
75         // get a soffice factory object
76         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
77 
78         try {
79             log.println( "creating a chartdocument" );
80             xChartDoc = SOF.createChartDoc(null);
81         } catch ( Exception e ) {
82             // Some exception occures.FAILED
83             e.printStackTrace( log );
84             throw new StatusException( "Couldn't create document", e );
85         }
86     }
87 
88     /**
89      * Close document
90      */
cleanup( TestParameters tParam, PrintWriter log )91     protected void cleanup( TestParameters tParam, PrintWriter log ) {
92         if( xChartDoc!=null ) {
93             log.println( "    closing xChartDoc" );
94             util.DesktopTools.closeDoc(xChartDoc);
95             xChartDoc = null;
96         }
97     }
98 
99     /**
100     * Creating a Testenvironment for the interfaces to be tested.
101     * Creates an instance of the service
102     * <code>com.sun.star.comp.Chart.XMLStylesExporter</code> with
103     * argument which is an implementation of <code>XDocumentHandler</code>
104     * and which can check if required tags and character data is
105     * exported. <p>
106     *   Existing of some tags checked in XML data exported.
107     *     Object relations created :
108     * <ul>
109     *  <li> <code>'MediaDescriptor'</code> for
110     *      {@link ifc.document._XFilter} interface </li>
111     *  <li> <code>'XFilter.Checker'</code> for
112     *      {@link ifc.document._XFilter} interface </li>
113     *  <li> <code>'SourceDocument'</code> for
114     *      {@link ifc.document._XExporter} interface </li>
115     * </ul>
116     */
createTestEnvironment(TestParameters tParam, PrintWriter log)117     public synchronized TestEnvironment createTestEnvironment
118             (TestParameters tParam, PrintWriter log) {
119 
120         XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF() ;
121         XInterface oObj = null;
122 
123         FilterChecker filter = new FilterChecker(log);
124         Any arg = new Any(new Type(XDocumentHandler.class),filter);
125 
126         try {
127             oObj = (XInterface) xMSF.createInstanceWithArguments(
128                 "com.sun.star.comp.Chart.XMLStylesExporter",
129                 new Object[] {arg});
130             XExporter xEx = (XExporter)
131                 UnoRuntime.queryInterface(XExporter.class,oObj);
132             xEx.setSourceDocument(xChartDoc);
133 
134         } catch (com.sun.star.uno.Exception e) {
135             e.printStackTrace(log) ;
136             throw new StatusException("Can't create component.", e) ;
137         }
138 
139 
140         filter.addTag(new XMLTools.Tag("office:document-styles")) ;
141         filter.addTagEnclosed(new XMLTools.Tag("office:styles"),
142             new XMLTools.Tag("office:document-styles"));
143 
144         // create testobject here
145         log.println( "creating a new environment" );
146         TestEnvironment tEnv = new TestEnvironment( oObj );
147 
148         tEnv.addObjRelation("MediaDescriptor", XMLTools.createMediaDescriptor(
149             new String[] {"FilterName"},
150             new Object[] {"schart: StarOffice XML (Chart)"}));
151         tEnv.addObjRelation("SourceDocument",xChartDoc);
152         tEnv.addObjRelation("XFilter.Checker", filter) ;
153         log.println("Implementation Name: "+util.utils.getImplName(oObj));
154 
155         return tEnv;
156 
157     }
158 
159     /**
160      * This class checks the XML for tags and data required and returns
161      * checking result to <code>XFilter</code> interface test. All
162      * the information about errors occured in XML data is written
163      * to log specified.
164      * @see ifc.document._XFilter
165      */
166     protected class FilterChecker extends XMLTools.XMLChecker
167         implements ifc.document._XFilter.FilterChecker {
168 
169         /**
170          * Creates a class which will write information
171          * into log specified.
172          */
FilterChecker(PrintWriter log)173         public FilterChecker(PrintWriter log) {
174             super(log, true) ;
175         }
176         /**
177          * <code>_XFilter.FilterChecker</code> interface method
178          * which returns the result of XML checking.
179          * @return <code>true</code> if the XML data exported was
180          * valid (i.e. all necessary tags and character data exists),
181          * <code>false</code> if some errors occured.
182          */
checkFilter()183         public boolean checkFilter() {
184             return check() ;
185         }
186     }
187 }
188