Avoid potential negative array index access to cached text.
[LibreOffice.git] / qadevOOo / tests / java / ifc / text / _XPagePrintable.java
blob5b1f6997849e8ef1aecea3200b1506772c602f04
1 /*
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 .
19 package ifc.text;
21 import lib.MultiMethodTest;
22 import util.utils;
24 import com.sun.star.beans.PropertyValue;
25 import com.sun.star.lang.XMultiServiceFactory;
26 import com.sun.star.text.XPagePrintable;
28 /**
29 * Testing <code>com.sun.star.text.XPagePrintable</code>
30 * interface methods :
31 * <ul>
32 * <li><code> getPagePrintSettings()</code></li>
33 * <li><code> setPagePrintSettings()</code></li>
34 * <li><code> printPages()</code></li>
35 * </ul> <p>
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];
44 /**
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"};
51 /**
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.
57 * @see #types
59 public void _getPagePrintSettings() {
60 boolean res = true;
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]);
70 res = false;
74 tRes.tested("getPagePrintSettings()",res);
77 /**
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 :
85 * <ul>
86 * <li> <code> getPagePrintSettings() </code> : to have existing
87 * print settings. </li>
88 * </ul>
90 public void _setPagePrintSettings() {
91 requiredMethod("getPagePrintSettings()");
92 boolean res = true;
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
109 * is exists.
111 public void _printPages() throws Exception {
112 boolean res = true;
114 try {
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 + "'");
130 res = false;
133 oObj.printPages(PrintOptions);
135 waitForEventIdle();
137 if (! util.utils.fileExists(xMSF, printFile)){
138 log.println("ERROR: could not find '" + printFile + "'");
139 res = false;
142 } catch (com.sun.star.lang.IllegalArgumentException ex) {
143 log.println("Exception while checking 'printPages'");
144 res = false;
145 ex.printStackTrace(log);
148 tRes.tested("printPages()",res);
151 } // finish class _XPagePrintable