1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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>
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
;
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");
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("oleautobridge.uno" SAL_DLLEXTENSION
);
73 oslModule hMod
= osl_loadModule( sModule
.pData
, 0);
74 osl_unloadModule( hMod
);
76 rtl_unloadUnusedModules( NULL
);
78 OUString
sFactoryFunc("component_getFactory");
79 void* pSymbol
= osl_getSymbol( hMod
,sFactoryFunc
.pData
);
80 // true, instance alive
81 sal_Bool bTest1
= pSymbol
? sal_True
: sal_False
;
84 rtl_unloadUnusedModules( NULL
);
85 pSymbol
= osl_getSymbol( hMod
,sFactoryFunc
.pData
);
86 sal_Bool bTest2
= pSymbol
? sal_False
: sal_True
;
88 Reference
<XComponent
> xcomp( context
, UNO_QUERY
);
91 return bTest2
&& bTest1
;
96 printf("Test2: com.sun.star.bridge.OleBridgeSupplierVar1\n");
97 Reference
<XSimpleRegistry
> xreg
= createSimpleRegistry();
98 xreg
->open( OUString("services.rdb"),
99 sal_False
, sal_False
);
101 Reference
< XComponentContext
> context
= bootstrap_InitialComponentContext(xreg
);
102 Reference
<XMultiComponentFactory
> fac
= context
->getServiceManager();
103 OUString
sService2("com.sun.star.bridge.OleBridgeSupplierVar1");
104 Reference
<XInterface
> xint
= fac
->createInstanceWithContext( sService2
, context
);
106 OUString
sModule("oleautobridge.uno" SAL_DLLEXTENSION
);
107 oslModule hMod
= osl_loadModule( sModule
.pData
, 0);
108 osl_unloadModule( hMod
);
110 rtl_unloadUnusedModules( NULL
);
111 OUString
sFactoryFunc("component_getFactory");
112 void* pSymbol
= osl_getSymbol( hMod
,sFactoryFunc
.pData
);
113 // true, instance alive
114 sal_Bool bTest1
= pSymbol
? sal_True
: sal_False
;
117 rtl_unloadUnusedModules( NULL
);
118 pSymbol
= osl_getSymbol( hMod
,sFactoryFunc
.pData
);
119 sal_Bool bTest2
= pSymbol
? sal_False
: sal_True
;
121 Reference
<XComponent
> xcomp( context
, UNO_QUERY
);
123 return bTest1
&& bTest2
;
128 printf("Test3: com.sun.star.bridge.oleautomation.Factory\n");
129 Reference
<XSimpleRegistry
> xreg
= createSimpleRegistry();
130 xreg
->open( OUString("services.rdb"),
131 sal_False
, sal_False
);
133 Reference
< XComponentContext
> context
= bootstrap_InitialComponentContext(xreg
);
135 Reference
<XMultiComponentFactory
> fac
= context
->getServiceManager();
136 OUString
sService("com.sun.star.bridge.oleautomation.Factory");
137 Reference
<XInterface
> xint
= fac
->createInstanceWithContext( sService
, context
);
140 OUString
sModule("oleautobridge.uno" SAL_DLLEXTENSION
);
141 oslModule hMod
= osl_loadModule( sModule
.pData
, 0);
142 osl_unloadModule( hMod
);
144 rtl_unloadUnusedModules( NULL
);
145 OUString
sFactoryFunc("component_getFactory");
146 void* pSymbol
= osl_getSymbol( hMod
,sFactoryFunc
.pData
);
147 // true, instance alive
148 sal_Bool bTest1
= pSymbol
? sal_True
: sal_False
;
151 rtl_unloadUnusedModules( NULL
);
152 pSymbol
= osl_getSymbol( hMod
,sFactoryFunc
.pData
);
153 sal_Bool bTest2
= pSymbol
? sal_False
: sal_True
;
155 Reference
<XComponent
> xcomp( context
, UNO_QUERY
);
158 return bTest1
&& bTest2
;
164 sal_Bool bTest1
= sal_False
;
165 sal_Bool bTest2
= sal_False
;
166 oslModule hMod
= NULL
;
167 OUString
sModule("oleautobridge.uno" SAL_DLLEXTENSION
);
168 OUString
sFactoryFunc("component_getFactory");
170 printf("Test4: com.sun.star.bridge.oleautomation.ApplicationRegistration\n");
171 Reference
<XSimpleRegistry
> xreg
= createSimpleRegistry();
172 xreg
->open( OUString("services.rdb"),
173 sal_False
, sal_False
);
175 Reference
< XComponentContext
> context
= bootstrap_InitialComponentContext(xreg
);
176 Reference
<XMultiComponentFactory
> fac
= context
->getServiceManager();
177 OUString
sService4("com.sun.star.bridge.oleautomation.ApplicationRegistration");
178 Reference
<XInterface
> xint
= fac
->createInstanceWithContext( sService4
, context
);
180 hMod
= osl_loadModule( sModule
.pData
, 0);
181 osl_unloadModule( hMod
);
183 rtl_unloadUnusedModules( NULL
);
184 void* pSymbol
= osl_getSymbol( hMod
,sFactoryFunc
.pData
);
185 // true, instance alive
186 bTest1
= pSymbol
? sal_True
: sal_False
;
187 // ApplicationRegistration is a one-instance-service, therefore kill service manager first
188 Reference
<XComponent
> xcomp( context
, UNO_QUERY
);
192 rtl_unloadUnusedModules( NULL
);
193 pSymbol
= osl_getSymbol( hMod
,sFactoryFunc
.pData
);
194 bTest2
= pSymbol
? sal_False
: sal_True
;
196 return bTest1
&& bTest2
;
199 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */