1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package ifc.text;
29 
30 import lib.MultiMethodTest;
31 import util.utils;
32 
33 import com.sun.star.beans.PropertyValue;
34 import com.sun.star.lang.XMultiServiceFactory;
35 import com.sun.star.text.XPagePrintable;
36 
37 /**
38  * Testing <code>com.sun.star.text.XPagePrintable</code>
39  * interface methods :
40  * <ul>
41  *  <li><code> getPagePrintSettings()</code></li>
42  *  <li><code> setPagePrintSettings()</code></li>
43  *  <li><code> printPages()</code></li>
44  * </ul> <p>
45  * Test is <b> NOT </b> multithread compilant. <p>
46  * @see com.sun.star.text.XPagePrintable
47  */
48 public class _XPagePrintable extends MultiMethodTest {
49 
50     public static XPagePrintable oObj = null;
51     public PropertyValue[] PrintSettings = new PropertyValue[0];
52 
53     /**
54      * Types of print settings properties by order they returned by
55      * <code>getPagePrintSettings()</code>.
56      */
57     public String[] types = new String[]{"Short","Short","Integer","Integer",
58         "Integer","Integer","Integer","Integer","Boolean"};
59 
60     /**
61      * Calls the method and examines the returned array of properties. <p>
62      *
63      * Has <b>OK</b> status if all properties' types are correspond
64      * to their expected values of the <code>types</code> array.
65      *
66      * @see #types
67      */
68     public void _getPagePrintSettings() {
69         boolean res = true;
70         PrintSettings = oObj.getPagePrintSettings();
71 
72         for (int i=0;i<PrintSettings.length;i++) {
73             String the_type = PrintSettings[i].Value.getClass().toString();
74             if (!the_type.endsWith(types[i])) {
75                 log.println("Name: "+PrintSettings[i].Name);
76                 log.println("Value: "+PrintSettings[i].Value);
77                 log.println("Type"+the_type);
78                 log.println("Expected: java.lang."+types[i]);
79                 res = false;
80             }
81         }
82 
83         tRes.tested("getPagePrintSettings()",res);
84     }
85 
86     /**
87      * Changes a property 'IsLandscape' in existsing print settings,
88      * and sets these settings back. <p>
89      *
90      * Has <b>OK</b> status if settings gotten again has the changed
91      * 'IsLandscape' property value. <p>
92      *
93      * The following method tests are to be completed successfully before :
94      * <ul>
95      *  <li> <code> getPagePrintSettings() </code> : to have existing
96      *   print settings. </li>
97      * </ul>
98      */
99     public void _setPagePrintSettings() {
100         requiredMethod("getPagePrintSettings()");
101         boolean res = true;
102 
103         Boolean landscape = (Boolean) PrintSettings[8].Value;
104         Boolean newlandscape = new Boolean(!landscape.booleanValue());
105         PrintSettings[8].Value = newlandscape;
106         oObj.setPagePrintSettings(PrintSettings);
107         res = (oObj.getPagePrintSettings()[8].Value.equals(newlandscape));
108 
109         tRes.tested("setPagePrintSettings()",res);
110     }
111 
112     /**
113      * Creates print options for printing into file situated in the SOffice
114      * temporary directory. If the file already exists it is deleted.
115      * Then calls the method. <p>
116      *
117      * Has <b>OK</b> status if the file to which printing must be performed
118      * is exists.
119      */
120     public void _printPages() {
121         boolean res = true;
122 
123         try {
124             XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF();
125 
126             String printFile = utils.getOfficeTemp(xMSF) + "XPagePrintable.prt";
127             log.println("Printing to : "+ printFile);
128 
129             PropertyValue[] PrintOptions = new PropertyValue[1];
130             PropertyValue firstProp = new PropertyValue();
131             firstProp.Name = "FileName";
132 
133             firstProp.Value = printFile;
134             firstProp.State = com.sun.star.beans.PropertyState.DEFAULT_VALUE;
135             PrintOptions[0] = firstProp;
136 
137             if (! util.utils.deleteFile(xMSF, printFile)){
138                 log.println("ERROR: could not remove '" + printFile + "'");
139                 res = false;
140             }
141 
142             oObj.printPages(PrintOptions);
143 
144             util.utils.shortWait(tParam.getInt(util.PropertyName.SHORT_WAIT));
145 
146             if (! util.utils.fileExists(xMSF, printFile)){
147                 log.println("ERROR: could not find '" + printFile + "'");
148                 res = false;
149             }
150 
151         } catch (com.sun.star.lang.IllegalArgumentException ex) {
152             log.println("Exception while checking 'printPages'");
153             res = false;
154             ex.printStackTrace(log);
155         }
156 
157         tRes.tested("printPages()",res);
158     }
159 
160 }  // finish class _XPagePrintable
161 
162