1 <?xml version="1.0" encoding="UTF-8"?>
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 <!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
20 <script:module xmlns:script="http://openoffice.org/2000/script" script:name="Test_DB" script:language="StarBasic">REM ***** Database Test *****
22 const cMessageDatabaseService = "Database Service"
23 const cMessageDatabaseOpen = "Open Database"
24 const cMessageDatabaseInsert = "Insert record into Database"
25 const cMessageDatabaseDelete = "Delete record from Database"
26 const cMessageDatabaseSeek = "Read other record from Database"
27 const cMessageDatabaseClose = "Close Database"
31 Dim oDBConnection as Object, oDataSource as Object, oDBContext as Object
32 Dim sDBName as String, sTable as String, sCurrentMessage as String
33 Dim nRowCount as Integer
34 Dim bResult as Boolean
35 Const sTestString = "Automatical Test"
37 On Local Error GoTo DBERROR
39 gCurrentTestCase = cLogfileFailed
40 LocalTestLog% = OpenLogDat (GetLogFileName(gCurrentDocTest))
42 gCurrentTestCase = cDBService
43 sCurrentMessage = cMessageDatabaseService + " " + cUnoDatabaseContext
45 oDBContext = CreateUnoService(cUnoDatabaseContext)
46 sDBName="Bibliography" 'Names of Databases
48 gCurrentTestCase = cDBOpen
49 sCurrentMessage = cMessageDatabaseOpen
51 oDataSource = oDBContext.GetByName(sDBName)
52 sTable=oDataSource.Tables.ElementNames(0)
53 oDBConnection = oDBContext.GetByName(sDBName).GetConnection("","")
55 LogTestResult( "Database "+ cMessageDatabaseOpen, not IsNull (oDBConnection) )
56 if (IsNull(oDBConnection)) then
62 ' Database is open now
64 gCurrentTestCase = cDBService
65 sCurrentMessage = cMessageDatabaseService + " " + cUnoRowSet
66 oRowSet = createUnoService(cUnoRowSet)
68 if (IsNull(oRowSet)) then
69 LogTestResult( "Database "+ cMessageDatabaseService + " " + cUnoRowSet, not IsNull (oRowSet) )
72 LogTestResult( "Database "+ cMessageDatabaseService, TRUE )
75 gCurrentTestCase = cDBInsert
76 sCurrentMessage = cMessageDatabaseInsert
78 oRowSet.ActiveConnection = oDBConnection
80 oRowSet.CommandType = com.sun.star.sdb.CommandType.COMMAND
81 oRowSet.Command = "SELECT * FROM " + sTable
84 oRowSet.moveToInsertRow
85 oRowSet.updateString(5, sTestString)
88 nRowCount=oRowSet.RowCount
90 oRowSet.moveToCurrentRow()
92 bResult = (oRowSet.getString(5) = sTestString)
93 LogTestResult( "Database "+ cMessageDatabaseInsert, bResult )
95 'delete only if insert passed
98 gCurrentTestCase = cDBDelete
99 sCurrentMessage = cMessageDatabaseDelete
101 bResult = (nRowCount - oRowSet.RowCount = 0)
104 bResult = (nRowCount - oRowSet.RowCount = 1)
106 LogTestResult( "Database "+ cMessageDatabaseDelete, bResult )
109 ' read other record
111 gCurrentTestCase = cDBSeek
112 sCurrentMessage = cMessageDatabaseSeek
114 bResult = not (oRowSet.getString(5) = sTestString)
115 LogTestResult( "Database "+ cMessageDatabaseSeek, bResult )
117 gCurrentTestCase = cDBClose
118 sCurrentMessage = cMessageDatabaseClose
119 oDBConnection.Dispose()
120 LogTestResult( "Database "+ cMessageDatabaseClose, True )
122 Print #LocalTestLog, "---"
125 Exit Sub ' Without error
128 If ( gCurrentTestCase = cLogfileFailed ) then
129 LogTestResult( " ", False )
132 LogTestResult( "Database "+ sCurrentMessage, FALSE )
136 Exit Sub ' With error