1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XPagePrintable.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 import lib
.MultiMethodTest
;
36 import com
.sun
.star
.beans
.PropertyValue
;
37 import com
.sun
.star
.lang
.XMultiServiceFactory
;
38 import com
.sun
.star
.text
.XPagePrintable
;
41 * Testing <code>com.sun.star.text.XPagePrintable</code>
44 * <li><code> getPagePrintSettings()</code></li>
45 * <li><code> setPagePrintSettings()</code></li>
46 * <li><code> printPages()</code></li>
48 * Test is <b> NOT </b> multithread compilant. <p>
49 * @see com.sun.star.text.XPagePrintable
51 public class _XPagePrintable
extends MultiMethodTest
{
53 public static XPagePrintable oObj
= null;
54 public PropertyValue
[] PrintSettings
= new PropertyValue
[0];
57 * Types of print settings properties by order they returned by
58 * <code>getPagePrintSettings()</code>.
60 public String
[] types
= new String
[]{"Short","Short","Integer","Integer",
61 "Integer","Integer","Integer","Integer","Boolean"};
64 * Calls the method and examines the returned array of properties. <p>
66 * Has <b>OK</b> status if all properties' types are correspond
67 * to their expected values of the <code>types</code> array.
71 public void _getPagePrintSettings() {
73 PrintSettings
= oObj
.getPagePrintSettings();
75 for (int i
=0;i
<PrintSettings
.length
;i
++) {
76 String the_type
= PrintSettings
[i
].Value
.getClass().toString();
77 if (!the_type
.endsWith(types
[i
])) {
78 log
.println("Name: "+PrintSettings
[i
].Name
);
79 log
.println("Value: "+PrintSettings
[i
].Value
);
80 log
.println("Type"+the_type
);
81 log
.println("Expected: java.lang."+types
[i
]);
86 tRes
.tested("getPagePrintSettings()",res
);
90 * Changes a property 'IsLandscape' in existsing print settings,
91 * and sets these settings back. <p>
93 * Has <b>OK</b> status if settings gotten again has the changed
94 * 'IsLandscape' property value. <p>
96 * The following method tests are to be completed successfully before :
98 * <li> <code> getPagePrintSettings() </code> : to have existing
99 * print settings. </li>
102 public void _setPagePrintSettings() {
103 requiredMethod("getPagePrintSettings()");
106 Boolean landscape
= (Boolean
) PrintSettings
[8].Value
;
107 Boolean newlandscape
= new Boolean(!landscape
.booleanValue());
108 PrintSettings
[8].Value
= newlandscape
;
109 oObj
.setPagePrintSettings(PrintSettings
);
110 res
= (oObj
.getPagePrintSettings()[8].Value
.equals(newlandscape
));
112 tRes
.tested("setPagePrintSettings()",res
);
116 * Creates print options for printing into file situated in the SOffice
117 * temporary directory. If the file already exists it is deleted.
118 * Then calls the method. <p>
120 * Has <b>OK</b> status if the file to which printing must be performed
123 public void _printPages() {
127 XMultiServiceFactory xMSF
= (XMultiServiceFactory
)tParam
.getMSF();
129 String printFile
= utils
.getOfficeTemp(xMSF
) + "XPagePrintable.prt";
130 log
.println("Printing to : "+ printFile
);
132 PropertyValue
[] PrintOptions
= new PropertyValue
[1];
133 PropertyValue firstProp
= new PropertyValue();
134 firstProp
.Name
= "FileName";
136 firstProp
.Value
= printFile
;
137 firstProp
.State
= com
.sun
.star
.beans
.PropertyState
.DEFAULT_VALUE
;
138 PrintOptions
[0] = firstProp
;
140 if (! util
.utils
.deleteFile(xMSF
, printFile
)){
141 log
.println("ERROR: could not remove '" + printFile
+ "'");
145 oObj
.printPages(PrintOptions
);
147 util
.utils
.shortWait(tParam
.getInt(util
.PropertyName
.SHORT_WAIT
));
149 if (! util
.utils
.fileExists(xMSF
, printFile
)){
150 log
.println("ERROR: could not find '" + printFile
+ "'");
154 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
155 log
.println("Exception while checking 'printPages'");
157 ex
.printStackTrace(log
);
160 tRes
.tested("printPages()",res
);
163 } // finish class _XPagePrintable