2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import lib
.MultiMethodTest
;
24 import com
.sun
.star
.beans
.PropertyValue
;
25 import com
.sun
.star
.lang
.XMultiServiceFactory
;
26 import com
.sun
.star
.text
.XPagePrintable
;
29 * Testing <code>com.sun.star.text.XPagePrintable</code>
32 * <li><code> getPagePrintSettings()</code></li>
33 * <li><code> setPagePrintSettings()</code></li>
34 * <li><code> printPages()</code></li>
36 * Test is <b> NOT </b> multithread compliant. <p>
37 * @see com.sun.star.text.XPagePrintable
39 public class _XPagePrintable
extends MultiMethodTest
{
41 public static XPagePrintable oObj
= null;
42 public PropertyValue
[] PrintSettings
= new PropertyValue
[0];
45 * Types of print settings properties by order they returned by
46 * <code>getPagePrintSettings()</code>.
48 public String
[] types
= new String
[]{"Short","Short","Integer","Integer",
49 "Integer","Integer","Integer","Integer","Boolean"};
52 * Calls the method and examines the returned array of properties. <p>
54 * Has <b>OK</b> status if all properties' types are correspond
55 * to their expected values of the <code>types</code> array.
59 public void _getPagePrintSettings() {
61 PrintSettings
= oObj
.getPagePrintSettings();
63 for (int i
=0;i
<PrintSettings
.length
;i
++) {
64 String the_type
= PrintSettings
[i
].Value
.getClass().toString();
65 if (!the_type
.endsWith(types
[i
])) {
66 log
.println("Name: "+PrintSettings
[i
].Name
);
67 log
.println("Value: "+PrintSettings
[i
].Value
);
68 log
.println("Type"+the_type
);
69 log
.println("Expected: java.lang."+types
[i
]);
74 tRes
.tested("getPagePrintSettings()",res
);
78 * Changes a property 'IsLandscape' in existing print settings,
79 * and sets these settings back. <p>
81 * Has <b>OK</b> status if settings gotten again has the changed
82 * 'IsLandscape' property value. <p>
84 * The following method tests are to be completed successfully before :
86 * <li> <code> getPagePrintSettings() </code> : to have existing
87 * print settings. </li>
90 public void _setPagePrintSettings() {
91 requiredMethod("getPagePrintSettings()");
94 Boolean landscape
= (Boolean
) PrintSettings
[8].Value
;
95 Boolean newlandscape
= Boolean
.valueOf(!landscape
.booleanValue());
96 PrintSettings
[8].Value
= newlandscape
;
97 oObj
.setPagePrintSettings(PrintSettings
);
98 res
= oObj
.getPagePrintSettings()[8].Value
.equals(newlandscape
);
100 tRes
.tested("setPagePrintSettings()",res
);
104 * Creates print options for printing into file situated in the SOffice
105 * temporary directory. If the file already exists it is deleted.
106 * Then calls the method. <p>
108 * Has <b>OK</b> status if the file to which printing must be performed
111 public void _printPages() throws Exception
{
115 XMultiServiceFactory xMSF
= tParam
.getMSF();
117 String printFile
= utils
.getOfficeTemp(xMSF
) + "XPagePrintable.prt";
118 log
.println("Printing to : "+ printFile
);
120 PropertyValue
[] PrintOptions
= new PropertyValue
[1];
121 PropertyValue firstProp
= new PropertyValue();
122 firstProp
.Name
= "FileName";
124 firstProp
.Value
= printFile
;
125 firstProp
.State
= com
.sun
.star
.beans
.PropertyState
.DEFAULT_VALUE
;
126 PrintOptions
[0] = firstProp
;
128 if (! util
.utils
.deleteFile(xMSF
, printFile
)){
129 log
.println("ERROR: could not remove '" + printFile
+ "'");
133 oObj
.printPages(PrintOptions
);
137 if (! util
.utils
.fileExists(xMSF
, printFile
)){
138 log
.println("ERROR: could not find '" + printFile
+ "'");
142 } catch (com
.sun
.star
.lang
.IllegalArgumentException ex
) {
143 log
.println("Exception while checking 'printPages'");
145 ex
.printStackTrace(log
);
148 tRes
.tested("printPages()",res
);
151 } // finish class _XPagePrintable