Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / io / test / stm / testfactreg.cxx
blob42e49b949fe3121317c30c3fcfeffcfabc071448
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
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.
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).
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.
27 ************************************************************************/
29 #include <stdio.h>
30 #include <string.h>
32 #include <osl/diagnose.h>
34 #include <cppuhelper/factory.hxx> // for EXTERN_SERVICE_CALLTYPE
36 using namespace ::rtl;
37 using namespace ::cppu;
38 using namespace ::com::sun::star::registry;
39 using namespace ::com::sun::star::uno;
40 using namespace ::com::sun::star::lang;
42 #include "testfactreg.hxx"
45 extern "C"
48 sal_Bool SAL_CALL component_writeInfo(
49 void * pServiceManager, void * pRegistryKey )
51 if (pRegistryKey)
53 try
55 Reference< XRegistryKey > xKey(
56 reinterpret_cast< XRegistryKey * >( pRegistryKey ) );
58 OUString str = OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) +
59 OPipeTest_getImplementationName() +
60 OUString( RTL_CONSTASCII_USTRINGPARAM("/UNO/SERVICES") );
61 Reference< XRegistryKey > xNewKey = xKey->createKey( str );
62 xNewKey->createKey( OPipeTest_getServiceName() );
64 str = OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) +
65 OPumpTest_getImplementationName() +
66 OUString( RTL_CONSTASCII_USTRINGPARAM("/UNO/SERVICES") );
67 xNewKey = xKey->createKey( str );
68 xNewKey->createKey( OPumpTest_getServiceName() );
70 str = OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) +
71 ODataStreamTest_getImplementationName(1) +
72 OUString( RTL_CONSTASCII_USTRINGPARAM("/UNO/SERVICES") );
73 xNewKey = xKey->createKey( str );
74 xNewKey->createKey( ODataStreamTest_getServiceName(1) );
76 str = OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) +
77 ODataStreamTest_getImplementationName(2) +
78 OUString( RTL_CONSTASCII_USTRINGPARAM("/UNO/SERVICES") );
79 xNewKey = xKey->createKey( str );
80 xNewKey->createKey( ODataStreamTest_getServiceName(2) );
82 str = OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) +
83 OObjectStreamTest_getImplementationName(1) +
84 OUString( RTL_CONSTASCII_USTRINGPARAM("/UNO/SERVICES") );
85 xNewKey = xKey->createKey( str );
86 xNewKey->createKey( OObjectStreamTest_getServiceName(1) );
88 str = OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) +
89 OObjectStreamTest_getImplementationName(2) +
90 OUString( RTL_CONSTASCII_USTRINGPARAM("/UNO/SERVICES") );
91 xNewKey = xKey->createKey( str );
92 xNewKey->createKey( OObjectStreamTest_getServiceName(2) );
94 str = OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) +
95 OMarkableOutputStreamTest_getImplementationName() +
96 OUString( RTL_CONSTASCII_USTRINGPARAM("/UNO/SERVICES") );
97 xNewKey = xKey->createKey( str );
98 xNewKey->createKey( OMarkableOutputStreamTest_getServiceName() );
100 str = OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) +
101 OMarkableInputStreamTest_getImplementationName() +
102 OUString( RTL_CONSTASCII_USTRINGPARAM("/UNO/SERVICES") );
103 xNewKey = xKey->createKey( str );
104 xNewKey->createKey( OMarkableInputStreamTest_getServiceName() );
106 str = OUString( RTL_CONSTASCII_USTRINGPARAM("/") ) +
107 OMyPersistObject_getImplementationName() +
108 OUString( RTL_CONSTASCII_USTRINGPARAM("/UNO/SERVICES") );
109 xNewKey = xKey->createKey( str );
110 xNewKey->createKey( OMyPersistObject_getServiceName() );
112 return sal_True;
114 catch (InvalidRegistryException &)
116 OSL_FAIL( "### InvalidRegistryException!" );
119 return sal_False;
122 SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory(
123 const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey )
125 void * pRet = 0;
127 if (pServiceManager )
129 Reference< XSingleServiceFactory > xRet;
130 Reference< XMultiServiceFactory > xSMgr =
131 reinterpret_cast< XMultiServiceFactory * > ( pServiceManager );
133 OUString aImplementationName = OUString::createFromAscii( pImplName );
135 if (aImplementationName == OPipeTest_getImplementationName() )
137 xRet = createSingleFactory( xSMgr, aImplementationName,
138 OPipeTest_CreateInstance,
139 OPipeTest_getSupportedServiceNames() );
141 else if (aImplementationName == OPumpTest_getImplementationName() )
143 xRet = createSingleFactory( xSMgr, aImplementationName,
144 OPumpTest_CreateInstance,
145 OPumpTest_getSupportedServiceNames() );
148 else if( aImplementationName == ODataStreamTest_getImplementationName(1) ) {
149 xRet = createSingleFactory( xSMgr , aImplementationName,
150 ODataStreamTest_CreateInstance,
151 ODataStreamTest_getSupportedServiceNames(1) );
153 else if( aImplementationName == ODataStreamTest_getImplementationName(2) ) {
154 xRet = createSingleFactory( xSMgr , aImplementationName,
155 ODataStreamTest_CreateInstance,
156 ODataStreamTest_getSupportedServiceNames(2) );
158 else if( aImplementationName == OObjectStreamTest_getImplementationName(1) ) {
159 xRet = createSingleFactory( xSMgr , aImplementationName,
160 OObjectStreamTest_CreateInstance,
161 OObjectStreamTest_getSupportedServiceNames(1) );
163 else if( aImplementationName == OObjectStreamTest_getImplementationName(2) ) {
164 xRet = createSingleFactory( xSMgr , aImplementationName,
165 OObjectStreamTest_CreateInstance,
166 OObjectStreamTest_getSupportedServiceNames(2) );
168 else if( aImplementationName == OMarkableOutputStreamTest_getImplementationName() ) {
169 xRet = createSingleFactory( xSMgr , aImplementationName,
170 OMarkableOutputStreamTest_CreateInstance,
171 OMarkableOutputStreamTest_getSupportedServiceNames() );
173 else if( aImplementationName == OMarkableInputStreamTest_getImplementationName() ) {
174 xRet = createSingleFactory( xSMgr , aImplementationName,
175 OMarkableInputStreamTest_CreateInstance,
176 OMarkableInputStreamTest_getSupportedServiceNames() );
178 else if( aImplementationName == OMyPersistObject_getImplementationName() ) {
179 xRet = createSingleFactory( xSMgr , aImplementationName,
180 OMyPersistObject_CreateInstance,
181 OMyPersistObject_getSupportedServiceNames() );
183 if (xRet.is())
185 xRet->acquire();
186 pRet = xRet.get();
190 return pRet;
195 Sequence<sal_Int8 > createSeq( char * p )
197 Sequence<sal_Int8> seq( strlen( p )+1 );
198 strcpy( (char * ) seq.getArray() , p );
199 return seq;
202 Sequence<sal_Int8> createIntSeq( sal_Int32 i )
204 char pcCount[20];
205 sprintf( pcCount , "%d" , i );
206 return createSeq( pcCount );
209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */