Update ooo320-m1
[ooovba.git] / cppuhelper / test / loader / loader.test.cxx
blob6e157b93cb53099acea07800efeb423a3660be59
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: loader.test.cxx,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "sal/main.h"
32 #include <cppuhelper/shlib.hxx>
33 #include <cppuhelper/implbase1.hxx>
34 #include <cppu/EnvDcp.hxx>
36 #include "../testcmp/TestComponent.hxx"
38 #include <iostream>
39 #include <cstring>
41 #ifndef SAL_DLLPREFIX
42 # define SAL_DLLPREFIX ""
43 #endif
46 using namespace ::com::sun::star;
49 class MyKey : public cppu::WeakImplHelper1<registry::XRegistryKey>
52 public:
53 virtual rtl::OUString SAL_CALL getKeyName() throw (uno::RuntimeException) { return rtl::OUString(); };
55 // Methods
56 virtual sal_Bool SAL_CALL isReadOnly( ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return sal_False;};
57 virtual sal_Bool SAL_CALL isValid( ) throw (uno::RuntimeException) {return sal_False;};
58 virtual registry::RegistryKeyType SAL_CALL getKeyType( const rtl::OUString& /*rKeyName*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return registry::RegistryKeyType_KEY;};
59 virtual registry::RegistryValueType SAL_CALL getValueType( ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return registry::RegistryValueType_NOT_DEFINED;};
60 virtual sal_Int32 SAL_CALL getLongValue( ) throw (registry::InvalidRegistryException, registry::InvalidValueException, uno::RuntimeException) {return 0;};
61 virtual void SAL_CALL setLongValue( sal_Int32 /*value*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {};
62 virtual uno::Sequence< sal_Int32 > SAL_CALL getLongListValue( ) throw (registry::InvalidRegistryException, registry::InvalidValueException, uno::RuntimeException) { return uno::Sequence<sal_Int32>(); };
63 virtual void SAL_CALL setLongListValue( const uno::Sequence< sal_Int32 >& /*seqValue*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {};
64 virtual rtl::OUString SAL_CALL getAsciiValue( ) throw (registry::InvalidRegistryException, registry::InvalidValueException, uno::RuntimeException) {return rtl::OUString();};
65 virtual void SAL_CALL setAsciiValue( const rtl::OUString& /*value*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {};
66 virtual uno::Sequence< rtl::OUString > SAL_CALL getAsciiListValue( ) throw (registry::InvalidRegistryException, registry::InvalidValueException, uno::RuntimeException) {return uno::Sequence<rtl::OUString>();};
67 virtual void SAL_CALL setAsciiListValue( const uno::Sequence< rtl::OUString >& /*seqValue*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {};
68 virtual rtl::OUString SAL_CALL getStringValue( ) throw (registry::InvalidRegistryException, registry::InvalidValueException, uno::RuntimeException) {return rtl::OUString();};
69 virtual void SAL_CALL setStringValue( const rtl::OUString& /*value*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {};
70 virtual uno::Sequence< rtl::OUString > SAL_CALL getStringListValue( ) throw (registry::InvalidRegistryException, registry::InvalidValueException, uno::RuntimeException) {return uno::Sequence<rtl::OUString>();};
71 virtual void SAL_CALL setStringListValue( const uno::Sequence< rtl::OUString >& /*seqValue*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {};
72 virtual uno::Sequence< sal_Int8 > SAL_CALL getBinaryValue( ) throw (registry::InvalidRegistryException, registry::InvalidValueException, uno::RuntimeException) {return uno::Sequence<sal_Int8>();};
73 virtual void SAL_CALL setBinaryValue( const uno::Sequence< sal_Int8 >& /*value*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {};
74 virtual uno::Reference< registry::XRegistryKey > SAL_CALL openKey( const rtl::OUString& /*aKeyName*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return uno::Reference<registry::XRegistryKey>();};
75 virtual uno::Reference< registry::XRegistryKey > SAL_CALL createKey( const rtl::OUString& /*aKeyName*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return uno::Reference<registry::XRegistryKey>();};
76 virtual void SAL_CALL closeKey( ) throw (registry::InvalidRegistryException, uno::RuntimeException) {};
77 virtual void SAL_CALL deleteKey( const rtl::OUString& /*rKeyName*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {};
78 virtual uno::Sequence< uno::Reference< registry::XRegistryKey > > SAL_CALL openKeys( ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return uno::Sequence<uno::Reference<registry::XRegistryKey> >();};
79 virtual uno::Sequence< rtl::OUString > SAL_CALL getKeyNames( ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return uno::Sequence<rtl::OUString>();};
80 virtual sal_Bool SAL_CALL createLink( const rtl::OUString& /*aLinkName*/, const rtl::OUString& /*aLinkTarget*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return sal_False;};
81 virtual void SAL_CALL deleteLink( const rtl::OUString& /*rLinkName*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {};
82 virtual rtl::OUString SAL_CALL getLinkTarget( const rtl::OUString& /*rLinkName*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return rtl::OUString();};
83 virtual rtl::OUString SAL_CALL getResolvedName( const rtl::OUString& /*aKeyName*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return rtl::OUString();};
88 static rtl::OUString s_test__cppu_loadSharedLibComponentFactory(char const * pServicePurpose)
90 rtl::OUString result;
92 rtl::OUString servicePurpose = rtl::OUString(pServicePurpose,
93 rtl_str_getLength(pServicePurpose),
94 RTL_TEXTENCODING_ASCII_US);
96 result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\ts_test__cppu_loadSharedLibComponentFactory "));
97 result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("(\""));
98 result += servicePurpose;
99 result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\") - "));
101 try {
102 uno::Reference<uno::XInterface> xObject(
103 cppu::loadSharedLibComponentFactory(
104 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SAL_DLLPREFIX "TestComponent.uno" SAL_DLLEXTENSION)),
105 rtl::OUString(),
106 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("impl.test.TestComponent")) + servicePurpose,
107 uno::Reference<lang::XMultiServiceFactory>(),
108 uno::Reference<registry::XRegistryKey>())
111 rtl::OUString envDcp_purpose(cppu::EnvDcp::getPurpose(g_envDcp));
112 if (envDcp_purpose == servicePurpose)
113 result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("passed\n"));
115 else
117 result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FAILED - got: \""));
118 result += envDcp_purpose;
119 result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\"\n"));
122 catch(uno::Exception & exception) {
123 result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FAILED - got: \""));
124 result += exception.Message;
125 result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\"\n"));
128 return result;
131 static rtl::OUString s_test__cppu_writeSharedLibComponentInfo(char const * pServicePurpose)
133 rtl::OUString result;
135 rtl::OUString servicePurpose = rtl::OUString(pServicePurpose,
136 rtl_str_getLength(pServicePurpose),
137 RTL_TEXTENCODING_ASCII_US);
139 result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\ts_test__cppu_writeSharedLibComponentInfo "));
140 result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("(\""));
141 result += servicePurpose;
142 result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\") - "));
144 char buff[256];
145 strcpy(buff, "TestComponent.uno=");
146 strcat(buff, pServicePurpose);
148 putenv(buff);
150 try {
151 cppu::writeSharedLibComponentInfo(
152 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SAL_DLLPREFIX "TestComponent.uno" SAL_DLLEXTENSION)),
153 rtl::OUString(),
154 uno::Reference<lang::XMultiServiceFactory>(),
155 uno::Reference<registry::XRegistryKey>(new MyKey)
158 rtl::OUString envDcp_purpose(cppu::EnvDcp::getPurpose(g_envDcp));
159 if (envDcp_purpose == servicePurpose)
160 result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("passed\n"));
162 else
164 result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FAILED - got: \""));
165 result += envDcp_purpose;
166 result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\"\n"));
169 catch(uno::Exception & exception) {
170 result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FAILED - got: \""));
171 result += exception.Message;
172 result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\"\n"));
175 return result;
179 SAL_IMPLEMENT_MAIN_WITH_ARGS(/*argc*/, argv)
181 int result = 0;
183 rtl::OUString message;
185 message += rtl::OUString(argv[0], rtl_str_getLength(argv[0]), RTL_TEXTENCODING_ASCII_US);
186 message += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\n"));
188 message += s_test__cppu_loadSharedLibComponentFactory(":unsafe");
189 message += s_test__cppu_loadSharedLibComponentFactory(":affine");
190 message += s_test__cppu_loadSharedLibComponentFactory("");
192 message += s_test__cppu_writeSharedLibComponentInfo(":unsafe");
193 message += s_test__cppu_writeSharedLibComponentInfo(":affine");
194 message += s_test__cppu_writeSharedLibComponentInfo("");
196 if (message.indexOf(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FAILED"))) == -1)
197 message += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TESTS PASSED\n"));
199 else
201 message += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TESTS _NOT_ PASSED\n"));
202 result = -1;
205 std::cout << rtl::OUStringToOString(message, RTL_TEXTENCODING_ASCII_US).getStr();
207 return result;