Update ooo320-m1
[ooovba.git] / qadevOOo / tests / basic / mod / stm / DataInputStream / stm_DataInputStream.xba
blobf6bbc69111c89257fbcf68e3f827087561ae3a17
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="stm_DataInputStream" script:language="StarBasic">
6 '*************************************************************************
8 ' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9 '
10 ' Copyright 2008 by Sun Microsystems, Inc.
12 ' OpenOffice.org - a multi-platform office productivity suite
14 ' $RCSfile: stm_DataInputStream.xba,v $
16 ' $Revision: 1.3 $
18 ' This file is part of OpenOffice.org.
20 ' OpenOffice.org is free software: you can redistribute it and/or modify
21 ' it under the terms of the GNU Lesser General Public License version 3
22 ' only, as published by the Free Software Foundation.
24 ' OpenOffice.org is distributed in the hope that it will be useful,
25 ' but WITHOUT ANY WARRANTY; without even the implied warranty of
26 ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 ' GNU Lesser General Public License version 3 for more details
28 ' (a copy is included in the LICENSE file that accompanied this code).
30 ' You should have received a copy of the GNU Lesser General Public License
31 ' version 3 along with OpenOffice.org. If not, see
32 ' <http://www.openoffice.org/license.html>
33 ' for a copy of the LGPLv3 License.
35 '*************************************************************************
36 '*************************************************************************
40 ' Be sure that all variables are dimensioned:
41 option explicit
44 ' REQUIRED VARIABLES for interface/service tests:
45 Global cFileName As String
46 Global oFileAcc As Object
47 Global oInputStream As Object
48 Global oOutputStream As Object
49 Global bInputStream As Boolean
50 Global bOutputStream As Boolean
53 Sub CreateObj()
55 '*************************************************************************
56 ' COMPONENT:
57 ' stm.DataInputStream
58 '*************************************************************************
59 On Error Goto ErrHndl
60 Dim oOS As Object
62 bInputStream = false
63 bOutputStream = false
64 cFileName = utils.getTempFileURL("BasicDataInputStream.dat")
65 oFileAcc = createUnoService("com.sun.star.ucb.SimpleFileAccess")
67 oObj = createUnoService("com.sun.star.io.DataInputStream")
69 'Creating a file...
70 oOS = oFileAcc.openFileWrite(cFileName)
71 oOS.closeOutput()
73 ResetStreams()
74 Exit Sub
75 ErrHndl:
76 Test.Exception()
77 End Sub
79 Function getOutStream() As Object
80 On Error goto ErrHndl
81 Dim oFO As Object
82 ResetStreams()
83 oInputStream.closeInput()
84 oOutputStream = createUnoService("com.sun.star.io.DataOutputStream")
85 oFileAcc.kill(cFileName)
86 oFO = oFileAcc.openFileWrite(cFileName)
87 oOutputStream.setOutputStream(oFO)
88 bOutputStream = true
89 getOutStream() = oOutputStream
90 Exit Function
91 ErrHndl:
92 Test.Exception()
93 getOutStream() = NULL_OBJECT
94 End Function
96 Function getInStream() As Object
97 On Error goto ErrHndl
98 ResetStreams()
99 getInStream() = oInputStream
100 Exit Function
101 ErrHndl:
102 Test.Exception()
103 getInStream() = NULL_OBJECT
104 End Function
106 Sub ResetStreams()
107 On Error goto ErrHndl
108 if bInputStream then
109 oInputStream.closeInput()
110 bInputStream = false
111 end if
112 if bOutputStream then
113 oOutputStream.closeOutput()
114 bOutputStream = false
115 end if
117 if NOT oFileAcc.exists(cFileName) then
118 Dim oFO As Object
119 oFO = oFileAcc.openFileWrite(cFileName)
120 oFO.closeOutput()
121 end if
123 oInputStream = oFileAcc.openFileRead(cFileName)
124 bInputStream = true
125 oObj.setInputStream(oInputStream)
126 Exit Sub
127 ErrHndl:
128 Test.Exception()
129 resume next
130 End Sub
132 Sub DisposeObj()
133 if NOT isNULL(oObj) then oObj.closeInput()
134 End Sub
135 </script:module>