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 .
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
;
32 import lib
.StatusException
;
36 * Generic test for all properties contained in this service
38 public class _Settings
extends MultiPropertyTest
{
41 * This property accepts only values in a range of 1-3
42 * @see com.sun.star.document.PrinterIndependentLayout
44 public void _PrinterIndependentLayout() {
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;
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
) {
72 catch(java
.lang
.NoSuchMethodException e
) {
75 catch(java
.lang
.IllegalAccessException e
) {
78 catch(java
.lang
.reflect
.InvocationTargetException e
) {
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]));
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() {
106 //check if it is read only as specified
107 res
&= isReadOnly("ForbiddenCharacters");
109 if (!isReadOnly("ForbiddenCharacters")) {
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,
120 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
122 "Exception while checking property 'ForbiddenCharacters' " +
124 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
126 "Exception while checking property 'ForbiddenCharacters' " +
130 tRes
.tested("ForbiddenCharacters", res
);
133 protected boolean isReadOnly(String PropertyName
) {
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);
146 private String
getPrinterNameWithReflection(Object pService
) {
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
) {