xref: /aoo41x/main/smoketestdoc/data/Test_DB.xml (revision 5111cb72)
1<?xml version="1.0" encoding="UTF-8"?>
2<!--***********************************************************
3 *
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements.  See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership.  The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License.  You may obtain a copy of the License at
11 *
12 *   http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied.  See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 *
21 ***********************************************************-->
22
23
24<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
25<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Test_DB" script:language="StarBasic">REM  *****  Database Test  *****
26
27const cMessageDatabaseService = &quot;Database Service&quot;
28const cMessageDatabaseOpen = &quot;Open Database&quot;
29const cMessageDatabaseInsert = &quot;Insert record into Database&quot;
30const cMessageDatabaseDelete = &quot;Delete record from Database&quot;
31const cMessageDatabaseSeek = &quot;Read other record from Database&quot;
32const cMessageDatabaseClose = &quot;Close Database&quot;
33
34Sub TestDB
35
36	Dim oDBConnection as Object, oDataSource as Object, oDBContext as Object
37	Dim sDBName as String, sTable as String, sCurrentMessage as String
38	Dim nRowCount as Integer
39	Dim bResult as Boolean
40	Const sTestString = &quot;Automatical Test&quot;
41
42	On Local Error GoTo DBERROR
43
44	gCurrentTestCase = cLogfileFailed
45	LocalTestLog% = OpenLogDat (GetLogFileName(gCurrentDocTest))
46
47	gCurrentTestCase = cDBService
48	sCurrentMessage = cMessageDatabaseService + &quot; &quot; + cUnoDatabaseContext
49
50	oDBContext = CreateUnoService(cUnoDatabaseContext)
51	sDBName=oDBContext.ElementNames(0) &apos;Names of Databases
52
53	gCurrentTestCase = cDBOpen
54	sCurrentMessage = cMessageDatabaseOpen
55
56	oDataSource = oDBContext.GetByName(sDBName)
57	sTable=oDataSource.Tables.ElementNames(0)
58	oDBConnection = oDBContext.GetByName(sDBName).GetConnection(&quot;&quot;,&quot;&quot;)
59
60	LogTestResult( &quot;Database &quot;+ cMessageDatabaseOpen, not IsNull (oDBConnection) )
61	if (IsNull(oDBConnection)) then
62   	Close #LocalTestLog%
63		LocalTestLog = 0
64		Exit Sub
65	End If
66
67	&apos; Database is open now
68
69	gCurrentTestCase = cDBService
70	sCurrentMessage = cMessageDatabaseService + &quot; &quot; + cUnoRowSet
71	oRowSet = createUnoService(cUnoRowSet)
72
73	if (IsNull(oRowSet)) then
74		LogTestResult( &quot;Database &quot;+ cMessageDatabaseService + &quot; &quot; + cUnoRowSet, not IsNull (oRowSet) )
75		Exit Sub
76	else
77		LogTestResult( &quot;Database &quot;+ cMessageDatabaseService, TRUE )
78	End If
79
80	gCurrentTestCase = cDBInsert
81	sCurrentMessage = cMessageDatabaseInsert
82
83	oRowSet.ActiveConnection = oDBConnection
84
85	oRowSet.CommandType = com.sun.star.sdb.CommandType.COMMAND
86	oRowSet.Command = &quot;SELECT * FROM &quot; + sTable
87	oRowSet.execute()
88
89	oRowSet.moveToInsertRow
90	oRowSet.updateString(5, sTestString)
91
92	oRowSet.insertRow()
93	nRowCount=oRowSet.RowCount
94
95	oRowSet.moveToCurrentRow()
96
97	bResult = (oRowSet.getString(5) = sTestString)
98	LogTestResult( &quot;Database &quot;+ cMessageDatabaseInsert, bResult )
99
100	&apos;delete only if insert passed
101
102	if (bResult) Then
103		gCurrentTestCase = cDBDelete
104		sCurrentMessage = cMessageDatabaseDelete
105		oRowSet.deleteRow()
106		bResult = (nRowCount - oRowSet.RowCount = 0)
107		if ( bResult ) Then
108			oRowSet.next()
109			bResult = (nRowCount - oRowSet.RowCount = 1)
110		End If
111		LogTestResult( &quot;Database &quot;+ cMessageDatabaseDelete, bResult )
112	End If
113
114	&apos; read other record
115
116	gCurrentTestCase = cDBSeek
117	sCurrentMessage = cMessageDatabaseSeek
118	oRowSet.first()
119	bResult = not (oRowSet.getString(5) = sTestString)
120	LogTestResult( &quot;Database &quot;+ cMessageDatabaseSeek, bResult )
121
122	gCurrentTestCase = cDBClose
123	sCurrentMessage = cMessageDatabaseClose
124	oDBConnection.Dispose()
125	LogTestResult( &quot;Database &quot;+ cMessageDatabaseClose, True )
126
127	Print #LocalTestLog, &quot;---&quot;
128	Close #LocalTestLog%
129	LocalTestLog = 0
130	Exit Sub &apos; Without error
131
132	DBERROR:
133	If ( gCurrentTestCase = cLogfileFailed ) then
134		LogTestResult( &quot; &quot;, False )
135		Exit Sub
136	else
137		LogTestResult( &quot;Database &quot;+ sCurrentMessage, FALSE )
138		Close #LocalTestLog%
139		LocalTestLog = 0
140	End If
141	Exit Sub &apos; With error
142End Sub
143</script:module>
144