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_Ext" script:language="StarBasic">REM ***** BASIC ***** 26 27const cMessageExtensionService = "Extension Service" 28const cMessageExtensionInstall = "Install Extension" 29const cMessageExtensionUninstall = "Uninstall Extension" 30 31Sub TestExtensions 32 Dim oTestExtension as Object, obj_null as Object 33 Dim sCurrentMessage as String 34 Dim bResult as Boolean 35 Dim sImplementationNameString as String 36 sImplementationNameString = cUnoSmoketestTestExtension + "$_TestExtension" 37 38 On Local Error GoTo EXTERROR 39 40 gCurrentTestCase = cLogfileFailed 41 LocalTestLog% = OpenLogDat (GetLogFileName(gCurrentDocTest)) 42 43 sCurrentMessage = cMessageExtensionService 44 gCurrentTestCase = cEXTService 45 46 'Create an implementation of com.sun.star.ucb.XCommandEnvironment which is needed for 47 'adding the extension. The implementation is in 48 'javaunohelper/com/sun/star/comp/juhtest/SmoketestCommandEnvironment.java and the code is in juh.jar 49 cmdEnv = createUnoService(cUnoSmoketestCommandEnvironment) 50 51 'Create the component context and then get the singleton ExtensionManager 52 'A singleton cannot be created with createUnoService 53 ctx = getDefaultContext 54 ext_mgr = ctx.getValueByName("/singletons/" + cExtensionManager) 55 56 LogTestResult( "Extension "+ cMessageExtensionService, not IsNull (ext_mgr) ) 57 if (IsNull(ext_mgr)) then 58 Close #LocalTestLog% 59 LocalTestLog = 0 60 Exit Sub 61 End If 62 63 sCurrentMessage = cMessageExtensionInstall 64 gCurrentTestCase = cEXTInstall 65 66 'Add the extension. We must provide a file URL here. 67 'By passing "user" we determine that the actions we perform on 68 'XExtensionManager only affect the user installation. To modify the share installation one would pass "share". 69 70 Dim props() as Object 71 ext_mgr.addExtension(sExtensionURL + cExtensionFileName, props, "user", obj_null, cmdEnv) 72 73 'Check if the extension has been added by creating a service which is contained in the extension. 74 oTestExtension = createUnoService(cUnoSmoketestTestExtension) 75 bResult = (oTestExtension.getImplementationName = sImplementationNameString) 76 LogTestResult( "Extension "+ cMessageExtensionInstall, bResult ) 77 if (not bResult) then 78 Close #LocalTestLog% 79 LocalTestLog = 0 80 Exit Sub 81 End If 82 83 sCurrentMessage = cMessageExtensionUninstall 84 gCurrentTestCase = cEXTUninstall 85 86 'Remove the package 87 ext_mgr.removeExtension("org.openoffice.legacy." + cExtensionFileName, cExtensionFileName, "user",obj_null, cmdEnv) 88 89 'Try to create the service which is contained in the now removed extension. 90 oTestExtension = createUnoService(cUnoSmoketestTestExtension) 91 92 'The service must not be available anymore. Therefor isNull must return true. 93 LogTestResult( "Extension "+ cMessageExtensionUninstall, IsNull (oTestExtension) ) 94 95 Print #LocalTestLog, "---" 96 Close #LocalTestLog% 97 LocalTestLog = 0 98 Exit Sub ' Without error 99 100 EXTERROR: 101 If ( gCurrentTestCase = cLogfileFailed ) then 102 LogTestResult( " ", False ) 103 Exit Sub 104 else 105 LogTestResult( "Extension "+ sCurrentMessage, False ) 106 Close #LocalTestLog% 107 LocalTestLog = 0 108 End If 109 Exit Sub ' With error 110 111End Sub 112</script:module> 113