bump product version to 4.1.6.2
[LibreOffice.git] / extensions / test / ole / unloading / unloadTest.cxx
bloba81244113d5da28473773ffa336fac3298d79405
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include<osl/module.hxx>
21 #include <osl/time.h>
22 #include <rtl/ustring.hxx>
23 #include <cppuhelper/factory.hxx>
24 #include <cppuhelper/servicefactory.hxx>
25 #include <cppuhelper/bootstrap.hxx>
26 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
27 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
28 #include <com/sun/star/lang/XServiceInfo.hpp>
29 #include <com/sun/star/lang/XComponent.hpp>
30 #include <com/sun/star/uno/XComponentContext.hpp>
31 #include <com/sun/star/registry/XSimpleRegistry.hpp>
33 #include <stdio.h>
34 using namespace ::rtl;
35 using namespace ::osl;
36 using namespace ::com::sun::star::uno;
37 using namespace ::com::sun::star::lang;
38 using namespace ::cppu;
39 using namespace ::com::sun::star::registry;
42 sal_Bool test1();
43 sal_Bool test2();
44 sal_Bool test3();
45 sal_Bool test4();
47 int main(int, char**)
49 sal_Bool bTest1= test1();
50 sal_Bool bTest2= test2();
51 sal_Bool bTest3= test3();
52 sal_Bool bTest4= test4();
54 if( bTest1 && bTest2 && bTest3 && bTest4)
55 printf("\n#########################\n Test was successful\n#######################\n");
57 return 0;
60 sal_Bool test1()
62 printf("\n Test1: com.sun.star.bridge.oleautomation.BridgeSupplier\n");
63 Reference<XSimpleRegistry> xreg= createSimpleRegistry();
64 xreg->open( OUString("services.rdb"),
65 sal_False, sal_False );
67 Reference< XComponentContext > context= bootstrap_InitialComponentContext(xreg);
68 Reference<XMultiComponentFactory> fac= context->getServiceManager();
69 OUString sService1("com.sun.star.bridge.oleautomation.BridgeSupplier");
70 Reference<XInterface> xint1= fac->createInstanceWithContext( sService1, context);
72 OUString sModule(
73 RTL_CONSTASCII_USTRINGPARAM("oleautobridge.uno" SAL_DLLEXTENSION));
74 oslModule hMod= osl_loadModule( sModule.pData, 0);
75 osl_unloadModule( hMod);
77 rtl_unloadUnusedModules( NULL);
79 OUString sFactoryFunc("component_getFactory");
80 void* pSymbol= osl_getSymbol( hMod,sFactoryFunc.pData);
81 // true, instance alive
82 sal_Bool bTest1= pSymbol ? sal_True : sal_False;
84 xint1=0;
85 rtl_unloadUnusedModules( NULL);
86 pSymbol= osl_getSymbol( hMod,sFactoryFunc.pData);
87 sal_Bool bTest2= pSymbol ? sal_False : sal_True;
89 Reference<XComponent> xcomp( context, UNO_QUERY);
90 xcomp->dispose();
92 return bTest2 && bTest1;
95 sal_Bool test2()
97 printf("Test2: com.sun.star.bridge.OleBridgeSupplierVar1\n");
98 Reference<XSimpleRegistry> xreg= createSimpleRegistry();
99 xreg->open( OUString("services.rdb"),
100 sal_False, sal_False );
102 Reference< XComponentContext > context= bootstrap_InitialComponentContext(xreg);
103 Reference<XMultiComponentFactory> fac= context->getServiceManager();
104 OUString sService2("com.sun.star.bridge.OleBridgeSupplierVar1");
105 Reference<XInterface> xint= fac->createInstanceWithContext( sService2, context);
107 OUString sModule(
108 RTL_CONSTASCII_USTRINGPARAM("oleautobridge.uno" SAL_DLLEXTENSION));
109 oslModule hMod= osl_loadModule( sModule.pData, 0);
110 osl_unloadModule( hMod);
112 rtl_unloadUnusedModules( NULL);
113 OUString sFactoryFunc("component_getFactory");
114 void* pSymbol= osl_getSymbol( hMod,sFactoryFunc.pData);
115 // true, instance alive
116 sal_Bool bTest1= pSymbol ? sal_True : sal_False;
118 xint=0;
119 rtl_unloadUnusedModules( NULL);
120 pSymbol= osl_getSymbol( hMod,sFactoryFunc.pData);
121 sal_Bool bTest2= pSymbol ? sal_False : sal_True;
123 Reference<XComponent> xcomp( context, UNO_QUERY);
124 xcomp->dispose();
125 return bTest1 && bTest2;
128 sal_Bool test3()
130 printf("Test3: com.sun.star.bridge.oleautomation.Factory\n");
131 Reference<XSimpleRegistry> xreg= createSimpleRegistry();
132 xreg->open( OUString("services.rdb"),
133 sal_False, sal_False );
135 Reference< XComponentContext > context= bootstrap_InitialComponentContext(xreg);
137 Reference<XMultiComponentFactory> fac= context->getServiceManager();
138 OUString sService("com.sun.star.bridge.oleautomation.Factory");
139 Reference<XInterface> xint= fac->createInstanceWithContext( sService, context);
142 OUString sModule(
143 RTL_CONSTASCII_USTRINGPARAM("oleautobridge.uno" SAL_DLLEXTENSION));
144 oslModule hMod= osl_loadModule( sModule.pData, 0);
145 osl_unloadModule( hMod);
147 rtl_unloadUnusedModules( NULL);
148 OUString sFactoryFunc("component_getFactory");
149 void* pSymbol= osl_getSymbol( hMod,sFactoryFunc.pData);
150 // true, instance alive
151 sal_Bool bTest1= pSymbol ? sal_True : sal_False;
153 xint=0;
154 rtl_unloadUnusedModules( NULL);
155 pSymbol= osl_getSymbol( hMod,sFactoryFunc.pData);
156 sal_Bool bTest2= pSymbol ? sal_False : sal_True;
158 Reference<XComponent> xcomp( context, UNO_QUERY);
159 xcomp->dispose();
161 return bTest1 && bTest2;
164 sal_Bool test4()
166 void* pSymbol= NULL;
167 sal_Bool bTest1= sal_False;
168 sal_Bool bTest2= sal_False;
169 oslModule hMod= NULL;
170 OUString sModule(
171 RTL_CONSTASCII_USTRINGPARAM("oleautobridge.uno" SAL_DLLEXTENSION));
172 OUString sFactoryFunc("component_getFactory");
174 printf("Test4: com.sun.star.bridge.oleautomation.ApplicationRegistration\n");
175 Reference<XSimpleRegistry> xreg= createSimpleRegistry();
176 xreg->open( OUString("services.rdb"),
177 sal_False, sal_False );
179 Reference< XComponentContext > context= bootstrap_InitialComponentContext(xreg);
180 Reference<XMultiComponentFactory> fac= context->getServiceManager();
181 OUString sService4("com.sun.star.bridge.oleautomation.ApplicationRegistration");
182 Reference<XInterface> xint= fac->createInstanceWithContext( sService4, context);
184 hMod= osl_loadModule( sModule.pData, 0);
185 osl_unloadModule( hMod);
187 rtl_unloadUnusedModules( NULL);
188 void* pSymbol= osl_getSymbol( hMod,sFactoryFunc.pData);
189 // true, instance alive
190 bTest1= pSymbol ? sal_True : sal_False;
191 // ApplicationRegistration is a one-instance-service, therefore kill service manager first
192 Reference<XComponent> xcomp( context, UNO_QUERY);
193 xcomp->dispose();
196 rtl_unloadUnusedModules( NULL);
197 pSymbol= osl_getSymbol( hMod,sFactoryFunc.pData);
198 bTest2= pSymbol ? sal_False : sal_True;
200 return bTest1 && bTest2;
203 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */