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 ifc.ucb;
25 
26 import lib.MultiMethodTest;
27 
28 import com.sun.star.lang.XMultiServiceFactory;
29 import com.sun.star.ucb.XDataContainer;
30 
31 /**
32 * Testing <code>com.sun.star.ucb.XDataContainer</code>
33 * interface methods :
34 * <ul>
35 *  <li><code> getContentType()</code></li>
36 *  <li><code> setContentType()</code></li>
37 *  <li><code> getData()</code></li>
38 *  <li><code> setData()</code></li>
39 *  <li><code> getDataURL()</code></li>
40 *  <li><code> setDataURL()</code></li>
41 * </ul> <p>
42 * Test is <b> NOT </b> multithread compilant. <p>
43 * @see com.sun.star.ucb.XDataContainer
44 */
45 public class _XDataContainer extends MultiMethodTest {
46 
47     public static XDataContainer oObj = null;        // oObj filled by MultiMethodTest
48     private byte[] data = new byte[] {34, 35, 36} ;
49     private String dataURL = null;
50 
51     /**
52     * Sets the content type to some value. <p>
53     * Has <b>OK</b> status if no runtime exseptions occured.
54     */
_setContentType()55     public void _setContentType() {
56         oObj.setContentType("image/jpeg") ;
57         tRes.tested("setContentType()", true) ;
58     }
59 
60     /**
61     * Check if values 'set' and 'get' are equal. <p>
62     * Has <b>OK</b> status if they are equal. <p>
63     * The following method tests are to be completed successfully before :
64     * <ul>
65     *  <li> <code> setContentType() </code>  </li>
66     * </ul>
67     */
_getContentType()68     public void _getContentType() {
69         requiredMethod("setContentType()") ;
70 
71         String type = oObj.getContentType() ;
72         tRes.tested("getContentType()", "image/jpeg".equals(type)) ;
73     }
74 
75     /**
76     * Sets the data to some byte array. <p>
77     * Has <b>OK</b> status if no runtime exseptions occured.
78     */
_setData()79     public void _setData() {
80         oObj.setData(data) ;
81         tRes.tested("setData()", true) ;
82     }
83 
84     /**
85     * Check if arrays 'set' and 'get' are equal. <p>
86     * Has <b>OK</b> status if they are equal. <p>
87     * The following method tests are to be completed successfully before :
88     * <ul>
89     *  <li> <code> setData() </code>  </li>
90     * </ul>
91     */
_getData()92     public void _getData() {
93         requiredMethod("setData()") ;
94 
95         byte[] gData = oObj.getData() ;
96         boolean res = true ;
97         if (res = (gData != null && gData.length == data.length)) {
98             for (int i = 0; i < data.length; i++) {
99                 res &= data[i] == gData[i] ;
100             }
101         }
102 
103         tRes.tested("getData()", res) ;
104     }
105 
106     /**
107     * Sets the data URL to some URL. <p>
108     * Has <b>OK</b> status if no runtime exseptions occured.
109     */
_setDataURL()110     public void _setDataURL() {
111         dataURL = util.utils.getOfficeTemp((XMultiServiceFactory)tParam.getMSF()) ;
112         oObj.setDataURL(dataURL) ;
113         tRes.tested("setDataURL()", true) ;
114     }
115 
116     /**
117     * Check if URLs 'set' and 'get' are equal. <p>
118     * Has <b>OK</b> status if they are equal. <p>
119     * The following method tests are to be completed successfully before :
120     * <ul>
121     *  <li> <code> setDataURL() </code>  </li>
122     * </ul>
123     */
_getDataURL()124     public void _getDataURL() {
125         requiredMethod("setDataURL()") ;
126 
127         String gURL = oObj.getDataURL() ;
128         tRes.tested("getDataURL()", dataURL.equals(gURL)) ;
129     }
130 }
131 
132 
133