1<?xml version="1.0" encoding="UTF-8"?> 2<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> 3<script:module xmlns:script="http://openoffice.org/2000/script" script:name="view_XPrintable" script:language="StarBasic"> 4 5 6'************************************************************************* 7' 8' Licensed to the Apache Software Foundation (ASF) under one 9' or more contributor license agreements. See the NOTICE file 10' distributed with this work for additional information 11' regarding copyright ownership. The ASF licenses this file 12' to you under the Apache License, Version 2.0 (the 13' "License"); you may not use this file except in compliance 14' with the License. You may obtain a copy of the License at 15' 16' http://www.apache.org/licenses/LICENSE-2.0 17' 18' Unless required by applicable law or agreed to in writing, 19' software distributed under the License is distributed on an 20' "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 21' KIND, either express or implied. See the License for the 22' specific language governing permissions and limitations 23' under the License. 24' 25'************************************************************************* 26 27 28 29 30 31' Be sure that all variables are dimensioned: 32option explicit 33 34 35 36Sub RunTest() 37 38'************************************************************************* 39' INTERFACE: 40' com.sun.star.view.XPrintable 41'************************************************************************* 42On Error Goto ErrHndl 43 Dim bOK As Boolean 44 Dim sFileName, sFileUrl As String 45 Dim aPrintingOptions(1) As New com.sun.star.beans.PropertyValue 46 Dim aPrinterProps As Variant 47 Dim i As Integer 48 49 Test.StartMethod("getPrinter()") 50 bOK = true 51 aPrinterProps = oObj.getPrinter() 52 bOK = bOK AND (ubound(aPrinterProps) > 0) 53 Test.MethodTested("getPrinter()", bOK) 54 55 56 Test.StartMethod("print()") 57 bOK = true 58 59 sFileUrl = utils.getTempFileURL("/XPrintable.prt", true) 60 sFileName = utils.URL2Path(sFileUrl) 61 62 aPrintingOptions(0).Name = "FileName" 63 aPrintingOptions(0).Value = sFileName 64 aPrintingOptions(0).State = com.sun.star.beans.PropertyState.DEFAULT_VALUE 65 66 aPrintingOptions(1).Name = "Wait" 67 aPrintingOptions(1).Value = true 68 oObj.Print(aPrintingOptions()) 69 70 ' without waiting Office can hang on setPrinter() call. 71 wait(500) 72 73 bOK = bOK AND FileExists(sFileName) 74 Test.MethodTested("print()", bOK) 75 76 Test.StartMethod("setPrinter()") 77 bOK = true 78 Dim iPaperFormat As Integer 79 Dim iNewPaperFormat As Integer 80 81 for i = 0 to ubound(aPrinterProps()) 82 if (aPrinterProps(i).Name = "PaperFormat") then 83 iPaperFormat = aPrinterProps(i).Value 84 exit for 85 endif 86 next i 87 88 if (iPaperFormat = com.sun.star.view.PaperFormat.A4) then 89 iNewPaperFormat = com.sun.star.view.PaperFormat.LETTER 90 else 91 iNewPaperFormat = com.sun.star.view.PaperFormat.A4 92 endif 93 94 aPrinterProps(i).Value = iNewPaperFormat 95 96 oObj.setPrinter(aPrinterProps()) 97 98 aPrinterProps() = oObj.getPrinter() 99 100 for i = 0 to ubound(aPrinterProps()) 101 if (aPrinterProps(i).Name = "PaperFormat") then 102 bOK = bOK AND (aPrinterProps(i).Value = iNewPaperFormat) 103 exit for 104 endif 105 next i 106 Test.MethodTested("setPrinter()", bOK) 107 108Exit Sub 109ErrHndl: 110 Test.Exception() 111 bOK = false 112 resume next 113End Sub 114</script:module> 115