bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / ifc / document / _Settings.java
blob7d6c3937a7d416715766a3e9e08df1a2931aa262
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 .
18 package ifc.document;
20 import com.sun.star.beans.Property;
21 import com.sun.star.beans.PropertyAttribute;
22 import com.sun.star.i18n.XForbiddenCharacters;
23 import com.sun.star.uno.UnoRuntime;
24 import java.lang.reflect.Method;
26 //import java.awt.print.PrinterJob;
28 //import javax.print.PrintService;
30 import lib.MultiPropertyTest;
31 import lib.Status;
32 import lib.StatusException;
36 * Generic test for all properties contained in this service
38 public class _Settings extends MultiPropertyTest {
40 /**
41 * This property accepts only values in a range of 1-3
42 * @see com.sun.star.document.PrinterIndependentLayout
44 public void _PrinterIndependentLayout() {
45 try{
46 Short oldVal = (Short) oObj.getPropertyValue("PrinterIndependentLayout");
47 Short newVal = oldVal.intValue() == 1 ? new Short("3") : new Short("1");
50 testProperty("PrinterIndependentLayout", oldVal, newVal);
52 } catch (com.sun.star.beans.UnknownPropertyException e) {
53 throw new StatusException(Status.failed("the property 'PrinterIndependentLayout' is unknown."));
54 } catch (com.sun.star.lang.WrappedTargetException e) {
55 throw new StatusException(Status.failed("the property 'PrinterIndependentLayout' could not be tested."));
59 public void _PrinterName() {
60 Object[] oServices = null;
61 Exception ex = null;
63 try {
64 Class<?> cPrinterJob = Class.forName("java.awt.print.PrinterJob");
65 Method lookupMethod = cPrinterJob.getDeclaredMethod("lookupPrintServices", new Class[0]);
66 Object retValue = lookupMethod.invoke(cPrinterJob, new Object[0]);
67 oServices = (Object[])retValue;
69 catch(java.lang.ClassNotFoundException e) {
70 ex = e;
72 catch(java.lang.NoSuchMethodException e) {
73 ex = e;
75 catch(java.lang.IllegalAccessException e) {
76 ex = e;
78 catch(java.lang.reflect.InvocationTargetException e) {
79 ex = e;
82 if (ex != null) {
83 // get Java version:
84 String javaVersion = System.getProperty("java.version");
85 throw new StatusException(Status.failed(
86 "Cannot execute test with current Java version (Java 1.4 required) " +
87 javaVersion + ": " + ex.getMessage()));
89 // PrintService[] services = PrinterJob.lookupPrintServices();
91 if (oServices.length > 1) {
92 testProperty("PrinterName", getPrinterNameWithReflection(oServices[0]),
93 getPrinterNameWithReflection(oServices[1]));
94 } else {
95 log.println(
96 "checking this property needs at least two printers to be installed on your system");
97 throw new StatusException(Status.failed(
98 "only one printer installed so I can't change it"));
102 public void _ForbiddenCharacters() {
103 boolean res = true;
105 try {
106 //check if it is read only as specified
107 res &= isReadOnly("ForbiddenCharacters");
109 if (!isReadOnly("ForbiddenCharacters")) {
110 log.println(
111 "The Property 'ForbiddenCharacters' isn't readOnly as specified");
114 //check if the property has the right type
115 Object pValue = oObj.getPropertyValue("ForbiddenCharacters");
116 XForbiddenCharacters fc = UnoRuntime.queryInterface(
117 XForbiddenCharacters.class,
118 pValue);
119 res &= (fc != null);
120 } catch (com.sun.star.beans.UnknownPropertyException e) {
121 log.println(
122 "Exception while checking property 'ForbiddenCharacters' " +
123 e.getMessage());
124 } catch (com.sun.star.lang.WrappedTargetException e) {
125 log.println(
126 "Exception while checking property 'ForbiddenCharacters' " +
127 e.getMessage());
130 tRes.tested("ForbiddenCharacters", res);
133 protected boolean isReadOnly(String PropertyName) {
134 boolean res = false;
135 Property[] props = oObj.getPropertySetInfo().getProperties();
137 for (int i = 0; i < props.length; i++) {
138 if (props[i].Name.equals(PropertyName)) {
139 res = ((props[i].Attributes & PropertyAttribute.READONLY) != 0);
143 return res;
146 private String getPrinterNameWithReflection(Object pService) {
147 String pName = null;
148 try {
149 Class<?> cPrintService = Class.forName("javax.print.PrintService");
150 Method getNameMethod = cPrintService.getDeclaredMethod("getName", new Class[0]);
151 Object retValue = getNameMethod.invoke(pService, new Object[0]);
152 pName = (String)retValue;
154 // ignore all exceptions: we already ran into one of these if Java is too old
155 catch(java.lang.ClassNotFoundException e) {
157 catch(java.lang.NoSuchMethodException e) {
159 catch(java.lang.IllegalAccessException e) {
161 catch(java.lang.reflect.InvocationTargetException e) {
163 return pName;