1*ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ef39d40dSAndrew Rist  * distributed with this work for additional information
6*ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9*ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ef39d40dSAndrew Rist  *
11*ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ef39d40dSAndrew Rist  *
13*ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15*ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18*ef39d40dSAndrew Rist  * under the License.
19*ef39d40dSAndrew Rist  *
20*ef39d40dSAndrew Rist  *************************************************************/
21*ef39d40dSAndrew Rist 
22*ef39d40dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package ifc.text;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import lib.MultiMethodTest;
27cdf0e10cSrcweir import util.utils;
28cdf0e10cSrcweir 
29cdf0e10cSrcweir import com.sun.star.beans.PropertyValue;
30cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
31cdf0e10cSrcweir import com.sun.star.text.XPagePrintable;
32cdf0e10cSrcweir 
33cdf0e10cSrcweir /**
34cdf0e10cSrcweir  * Testing <code>com.sun.star.text.XPagePrintable</code>
35cdf0e10cSrcweir  * interface methods :
36cdf0e10cSrcweir  * <ul>
37cdf0e10cSrcweir  *  <li><code> getPagePrintSettings()</code></li>
38cdf0e10cSrcweir  *  <li><code> setPagePrintSettings()</code></li>
39cdf0e10cSrcweir  *  <li><code> printPages()</code></li>
40cdf0e10cSrcweir  * </ul> <p>
41cdf0e10cSrcweir  * Test is <b> NOT </b> multithread compilant. <p>
42cdf0e10cSrcweir  * @see com.sun.star.text.XPagePrintable
43cdf0e10cSrcweir  */
44cdf0e10cSrcweir public class _XPagePrintable extends MultiMethodTest {
45cdf0e10cSrcweir 
46cdf0e10cSrcweir     public static XPagePrintable oObj = null;
47cdf0e10cSrcweir     public PropertyValue[] PrintSettings = new PropertyValue[0];
48cdf0e10cSrcweir 
49cdf0e10cSrcweir     /**
50cdf0e10cSrcweir      * Types of print settings properties by order they returned by
51cdf0e10cSrcweir      * <code>getPagePrintSettings()</code>.
52cdf0e10cSrcweir      */
53cdf0e10cSrcweir     public String[] types = new String[]{"Short","Short","Integer","Integer",
54cdf0e10cSrcweir         "Integer","Integer","Integer","Integer","Boolean"};
55cdf0e10cSrcweir 
56cdf0e10cSrcweir     /**
57cdf0e10cSrcweir      * Calls the method and examines the returned array of properties. <p>
58cdf0e10cSrcweir      *
59cdf0e10cSrcweir      * Has <b>OK</b> status if all properties' types are correspond
60cdf0e10cSrcweir      * to their expected values of the <code>types</code> array.
61cdf0e10cSrcweir      *
62cdf0e10cSrcweir      * @see #types
63cdf0e10cSrcweir      */
_getPagePrintSettings()64cdf0e10cSrcweir     public void _getPagePrintSettings() {
65cdf0e10cSrcweir         boolean res = true;
66cdf0e10cSrcweir         PrintSettings = oObj.getPagePrintSettings();
67cdf0e10cSrcweir 
68cdf0e10cSrcweir         for (int i=0;i<PrintSettings.length;i++) {
69cdf0e10cSrcweir             String the_type = PrintSettings[i].Value.getClass().toString();
70cdf0e10cSrcweir             if (!the_type.endsWith(types[i])) {
71cdf0e10cSrcweir                 log.println("Name: "+PrintSettings[i].Name);
72cdf0e10cSrcweir                 log.println("Value: "+PrintSettings[i].Value);
73cdf0e10cSrcweir                 log.println("Type"+the_type);
74cdf0e10cSrcweir                 log.println("Expected: java.lang."+types[i]);
75cdf0e10cSrcweir                 res = false;
76cdf0e10cSrcweir             }
77cdf0e10cSrcweir         }
78cdf0e10cSrcweir 
79cdf0e10cSrcweir         tRes.tested("getPagePrintSettings()",res);
80cdf0e10cSrcweir     }
81cdf0e10cSrcweir 
82cdf0e10cSrcweir     /**
83cdf0e10cSrcweir      * Changes a property 'IsLandscape' in existsing print settings,
84cdf0e10cSrcweir      * and sets these settings back. <p>
85cdf0e10cSrcweir      *
86cdf0e10cSrcweir      * Has <b>OK</b> status if settings gotten again has the changed
87cdf0e10cSrcweir      * 'IsLandscape' property value. <p>
88cdf0e10cSrcweir      *
89cdf0e10cSrcweir      * The following method tests are to be completed successfully before :
90cdf0e10cSrcweir      * <ul>
91cdf0e10cSrcweir      *  <li> <code> getPagePrintSettings() </code> : to have existing
92cdf0e10cSrcweir      *   print settings. </li>
93cdf0e10cSrcweir      * </ul>
94cdf0e10cSrcweir      */
_setPagePrintSettings()95cdf0e10cSrcweir     public void _setPagePrintSettings() {
96cdf0e10cSrcweir         requiredMethod("getPagePrintSettings()");
97cdf0e10cSrcweir         boolean res = true;
98cdf0e10cSrcweir 
99cdf0e10cSrcweir         Boolean landscape = (Boolean) PrintSettings[8].Value;
100cdf0e10cSrcweir         Boolean newlandscape = new Boolean(!landscape.booleanValue());
101cdf0e10cSrcweir         PrintSettings[8].Value = newlandscape;
102cdf0e10cSrcweir         oObj.setPagePrintSettings(PrintSettings);
103cdf0e10cSrcweir         res = (oObj.getPagePrintSettings()[8].Value.equals(newlandscape));
104cdf0e10cSrcweir 
105cdf0e10cSrcweir         tRes.tested("setPagePrintSettings()",res);
106cdf0e10cSrcweir     }
107cdf0e10cSrcweir 
108cdf0e10cSrcweir     /**
109cdf0e10cSrcweir      * Creates print options for printing into file situated in the SOffice
110cdf0e10cSrcweir      * temporary directory. If the file already exists it is deleted.
111cdf0e10cSrcweir      * Then calls the method. <p>
112cdf0e10cSrcweir      *
113cdf0e10cSrcweir      * Has <b>OK</b> status if the file to which printing must be performed
114cdf0e10cSrcweir      * is exists.
115cdf0e10cSrcweir      */
_printPages()116cdf0e10cSrcweir     public void _printPages() {
117cdf0e10cSrcweir         boolean res = true;
118cdf0e10cSrcweir 
119cdf0e10cSrcweir         try {
120cdf0e10cSrcweir             XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF();
121cdf0e10cSrcweir 
122cdf0e10cSrcweir             String printFile = utils.getOfficeTemp(xMSF) + "XPagePrintable.prt";
123cdf0e10cSrcweir             log.println("Printing to : "+ printFile);
124cdf0e10cSrcweir 
125cdf0e10cSrcweir             PropertyValue[] PrintOptions = new PropertyValue[1];
126cdf0e10cSrcweir             PropertyValue firstProp = new PropertyValue();
127cdf0e10cSrcweir             firstProp.Name = "FileName";
128cdf0e10cSrcweir 
129cdf0e10cSrcweir             firstProp.Value = printFile;
130cdf0e10cSrcweir             firstProp.State = com.sun.star.beans.PropertyState.DEFAULT_VALUE;
131cdf0e10cSrcweir             PrintOptions[0] = firstProp;
132cdf0e10cSrcweir 
133cdf0e10cSrcweir             if (! util.utils.deleteFile(xMSF, printFile)){
134cdf0e10cSrcweir                 log.println("ERROR: could not remove '" + printFile + "'");
135cdf0e10cSrcweir                 res = false;
136cdf0e10cSrcweir             }
137cdf0e10cSrcweir 
138cdf0e10cSrcweir             oObj.printPages(PrintOptions);
139cdf0e10cSrcweir 
140cdf0e10cSrcweir             util.utils.shortWait(tParam.getInt(util.PropertyName.SHORT_WAIT));
141cdf0e10cSrcweir 
142cdf0e10cSrcweir             if (! util.utils.fileExists(xMSF, printFile)){
143cdf0e10cSrcweir                 log.println("ERROR: could not find '" + printFile + "'");
144cdf0e10cSrcweir                 res = false;
145cdf0e10cSrcweir             }
146cdf0e10cSrcweir 
147cdf0e10cSrcweir         } catch (com.sun.star.lang.IllegalArgumentException ex) {
148cdf0e10cSrcweir             log.println("Exception while checking 'printPages'");
149cdf0e10cSrcweir             res = false;
150cdf0e10cSrcweir             ex.printStackTrace(log);
151cdf0e10cSrcweir         }
152cdf0e10cSrcweir 
153cdf0e10cSrcweir         tRes.tested("printPages()",res);
154cdf0e10cSrcweir     }
155cdf0e10cSrcweir 
156cdf0e10cSrcweir }  // finish class _XPagePrintable
157cdf0e10cSrcweir 
158