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