xref: /aoo41x/main/smoketestdoc/data/Test_DB.xml (revision cdf0e10c)
1*cdf0e10cSrcweir<?xml version="1.0" encoding="UTF-8"?>
2*cdf0e10cSrcweir<!--**********************************************************************
3*cdf0e10cSrcweir*
4*cdf0e10cSrcweir* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5*cdf0e10cSrcweir*
6*cdf0e10cSrcweir* Copyright 2000, 2010 Oracle and/or its affiliates.
7*cdf0e10cSrcweir*
8*cdf0e10cSrcweir* OpenOffice.org - a multi-platform office productivity suite
9*cdf0e10cSrcweir*
10*cdf0e10cSrcweir* This file is part of OpenOffice.org.
11*cdf0e10cSrcweir*
12*cdf0e10cSrcweir* OpenOffice.org is free software: you can redistribute it and/or modify
13*cdf0e10cSrcweir* it under the terms of the GNU Lesser General Public License version 3
14*cdf0e10cSrcweir* only, as published by the Free Software Foundation.
15*cdf0e10cSrcweir*
16*cdf0e10cSrcweir* OpenOffice.org is distributed in the hope that it will be useful,
17*cdf0e10cSrcweir* but WITHOUT ANY WARRANTY; without even the implied warranty of
18*cdf0e10cSrcweir* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19*cdf0e10cSrcweir* GNU Lesser General Public License version 3 for more details
20*cdf0e10cSrcweir* (a copy is included in the LICENSE file that accompanied this code).
21*cdf0e10cSrcweir*
22*cdf0e10cSrcweir* You should have received a copy of the GNU Lesser General Public License
23*cdf0e10cSrcweir* version 3 along with OpenOffice.org.  If not, see
24*cdf0e10cSrcweir* <http://www.openoffice.org/license.html>
25*cdf0e10cSrcweir* for a copy of the LGPLv3 License.
26*cdf0e10cSrcweir*
27*cdf0e10cSrcweir**********************************************************************-->
28*cdf0e10cSrcweir<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
29*cdf0e10cSrcweir<script:module xmlns:script="http://openoffice.org/2000/script" script:name="Test_DB" script:language="StarBasic">REM  *****  Database Test  *****
30*cdf0e10cSrcweir
31*cdf0e10cSrcweirconst cMessageDatabaseService = &quot;Database Service&quot;
32*cdf0e10cSrcweirconst cMessageDatabaseOpen = &quot;Open Database&quot;
33*cdf0e10cSrcweirconst cMessageDatabaseInsert = &quot;Insert record into Database&quot;
34*cdf0e10cSrcweirconst cMessageDatabaseDelete = &quot;Delete record from Database&quot;
35*cdf0e10cSrcweirconst cMessageDatabaseSeek = &quot;Read other record from Database&quot;
36*cdf0e10cSrcweirconst cMessageDatabaseClose = &quot;Close Database&quot;
37*cdf0e10cSrcweir
38*cdf0e10cSrcweirSub TestDB
39*cdf0e10cSrcweir
40*cdf0e10cSrcweir	Dim oDBConnection as Object, oDataSource as Object, oDBContext as Object
41*cdf0e10cSrcweir	Dim sDBName as String, sTable as String, sCurrentMessage as String
42*cdf0e10cSrcweir	Dim nRowCount as Integer
43*cdf0e10cSrcweir	Dim bResult as Boolean
44*cdf0e10cSrcweir	Const sTestString = &quot;Automatical Test&quot;
45*cdf0e10cSrcweir
46*cdf0e10cSrcweir	On Local Error GoTo DBERROR
47*cdf0e10cSrcweir
48*cdf0e10cSrcweir	gCurrentTestCase = cLogfileFailed
49*cdf0e10cSrcweir	LocalTestLog% = OpenLogDat (GetLogFileName(gCurrentDocTest))
50*cdf0e10cSrcweir
51*cdf0e10cSrcweir	gCurrentTestCase = cDBService
52*cdf0e10cSrcweir	sCurrentMessage = cMessageDatabaseService + &quot; &quot; + cUnoDatabaseContext
53*cdf0e10cSrcweir
54*cdf0e10cSrcweir	oDBContext = CreateUnoService(cUnoDatabaseContext)
55*cdf0e10cSrcweir	sDBName=oDBContext.ElementNames(0) &apos;Names of Databases
56*cdf0e10cSrcweir
57*cdf0e10cSrcweir	gCurrentTestCase = cDBOpen
58*cdf0e10cSrcweir	sCurrentMessage = cMessageDatabaseOpen
59*cdf0e10cSrcweir
60*cdf0e10cSrcweir	oDataSource = oDBContext.GetByName(sDBName)
61*cdf0e10cSrcweir	sTable=oDataSource.Tables.ElementNames(0)
62*cdf0e10cSrcweir	oDBConnection = oDBContext.GetByName(sDBName).GetConnection(&quot;&quot;,&quot;&quot;)
63*cdf0e10cSrcweir
64*cdf0e10cSrcweir	LogTestResult( &quot;Database &quot;+ cMessageDatabaseOpen, not IsNull (oDBConnection) )
65*cdf0e10cSrcweir	if (IsNull(oDBConnection)) then
66*cdf0e10cSrcweir   	Close #LocalTestLog%
67*cdf0e10cSrcweir		LocalTestLog = 0
68*cdf0e10cSrcweir		Exit Sub
69*cdf0e10cSrcweir	End If
70*cdf0e10cSrcweir
71*cdf0e10cSrcweir	&apos; Database is open now
72*cdf0e10cSrcweir
73*cdf0e10cSrcweir	gCurrentTestCase = cDBService
74*cdf0e10cSrcweir	sCurrentMessage = cMessageDatabaseService + &quot; &quot; + cUnoRowSet
75*cdf0e10cSrcweir	oRowSet = createUnoService(cUnoRowSet)
76*cdf0e10cSrcweir
77*cdf0e10cSrcweir	if (IsNull(oRowSet)) then
78*cdf0e10cSrcweir		LogTestResult( &quot;Database &quot;+ cMessageDatabaseService + &quot; &quot; + cUnoRowSet, not IsNull (oRowSet) )
79*cdf0e10cSrcweir		Exit Sub
80*cdf0e10cSrcweir	else
81*cdf0e10cSrcweir		LogTestResult( &quot;Database &quot;+ cMessageDatabaseService, TRUE )
82*cdf0e10cSrcweir	End If
83*cdf0e10cSrcweir
84*cdf0e10cSrcweir	gCurrentTestCase = cDBInsert
85*cdf0e10cSrcweir	sCurrentMessage = cMessageDatabaseInsert
86*cdf0e10cSrcweir
87*cdf0e10cSrcweir	oRowSet.ActiveConnection = oDBConnection
88*cdf0e10cSrcweir
89*cdf0e10cSrcweir	oRowSet.CommandType = com.sun.star.sdb.CommandType.COMMAND
90*cdf0e10cSrcweir	oRowSet.Command = &quot;SELECT * FROM &quot; + sTable
91*cdf0e10cSrcweir	oRowSet.execute()
92*cdf0e10cSrcweir
93*cdf0e10cSrcweir	oRowSet.moveToInsertRow
94*cdf0e10cSrcweir	oRowSet.updateString(5, sTestString)
95*cdf0e10cSrcweir
96*cdf0e10cSrcweir	oRowSet.insertRow()
97*cdf0e10cSrcweir	nRowCount=oRowSet.RowCount
98*cdf0e10cSrcweir
99*cdf0e10cSrcweir	oRowSet.moveToCurrentRow()
100*cdf0e10cSrcweir
101*cdf0e10cSrcweir	bResult = (oRowSet.getString(5) = sTestString)
102*cdf0e10cSrcweir	LogTestResult( &quot;Database &quot;+ cMessageDatabaseInsert, bResult )
103*cdf0e10cSrcweir
104*cdf0e10cSrcweir	&apos;delete only if insert passed
105*cdf0e10cSrcweir
106*cdf0e10cSrcweir	if (bResult) Then
107*cdf0e10cSrcweir		gCurrentTestCase = cDBDelete
108*cdf0e10cSrcweir		sCurrentMessage = cMessageDatabaseDelete
109*cdf0e10cSrcweir		oRowSet.deleteRow()
110*cdf0e10cSrcweir		bResult = (nRowCount - oRowSet.RowCount = 0)
111*cdf0e10cSrcweir		if ( bResult ) Then
112*cdf0e10cSrcweir			oRowSet.next()
113*cdf0e10cSrcweir			bResult = (nRowCount - oRowSet.RowCount = 1)
114*cdf0e10cSrcweir		End If
115*cdf0e10cSrcweir		LogTestResult( &quot;Database &quot;+ cMessageDatabaseDelete, bResult )
116*cdf0e10cSrcweir	End If
117*cdf0e10cSrcweir
118*cdf0e10cSrcweir	&apos; read other record
119*cdf0e10cSrcweir
120*cdf0e10cSrcweir	gCurrentTestCase = cDBSeek
121*cdf0e10cSrcweir	sCurrentMessage = cMessageDatabaseSeek
122*cdf0e10cSrcweir	oRowSet.first()
123*cdf0e10cSrcweir	bResult = not (oRowSet.getString(5) = sTestString)
124*cdf0e10cSrcweir	LogTestResult( &quot;Database &quot;+ cMessageDatabaseSeek, bResult )
125*cdf0e10cSrcweir
126*cdf0e10cSrcweir	gCurrentTestCase = cDBClose
127*cdf0e10cSrcweir	sCurrentMessage = cMessageDatabaseClose
128*cdf0e10cSrcweir	oDBConnection.Dispose()
129*cdf0e10cSrcweir	LogTestResult( &quot;Database &quot;+ cMessageDatabaseClose, True )
130*cdf0e10cSrcweir
131*cdf0e10cSrcweir	Print #LocalTestLog, &quot;---&quot;
132*cdf0e10cSrcweir	Close #LocalTestLog%
133*cdf0e10cSrcweir	LocalTestLog = 0
134*cdf0e10cSrcweir	Exit Sub &apos; Without error
135*cdf0e10cSrcweir
136*cdf0e10cSrcweir	DBERROR:
137*cdf0e10cSrcweir	If ( gCurrentTestCase = cLogfileFailed ) then
138*cdf0e10cSrcweir		LogTestResult( &quot; &quot;, False )
139*cdf0e10cSrcweir		Exit Sub
140*cdf0e10cSrcweir	else
141*cdf0e10cSrcweir		LogTestResult( &quot;Database &quot;+ sCurrentMessage, FALSE )
142*cdf0e10cSrcweir		Close #LocalTestLog%
143*cdf0e10cSrcweir		LocalTestLog = 0
144*cdf0e10cSrcweir	End If
145*cdf0e10cSrcweir	Exit Sub &apos; With error
146*cdf0e10cSrcweirEnd Sub
147*cdf0e10cSrcweir</script:module>
148