xref: /AOO41X/main/cppuhelper/test/loader/loader.test.cxx (revision 9d7e27acf3441a88e7e2e9d0bd0e0c145f24ac0d)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "sal/main.h"
25 #include <cppuhelper/shlib.hxx>
26 #include <cppuhelper/implbase1.hxx>
27 #include <cppu/EnvDcp.hxx>
28 
29 #include "../testcmp/TestComponent.hxx"
30 
31 #include <iostream>
32 #include <cstring>
33 
34 #ifndef SAL_DLLPREFIX
35 # define SAL_DLLPREFIX  ""
36 #endif
37 
38 
39 using namespace ::com::sun::star;
40 
41 
42 class MyKey : public cppu::WeakImplHelper1<registry::XRegistryKey>
43 
44 {
45 public:
getKeyName()46     virtual rtl::OUString SAL_CALL getKeyName() throw (uno::RuntimeException) { return rtl::OUString(); };
47 
48     // Methods
isReadOnly()49     virtual sal_Bool SAL_CALL isReadOnly(  ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return sal_False;};
isValid()50     virtual sal_Bool SAL_CALL isValid(  ) throw (uno::RuntimeException) {return sal_False;};
getKeyType(const rtl::OUString &)51     virtual registry::RegistryKeyType SAL_CALL getKeyType( const rtl::OUString& /*rKeyName*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return registry::RegistryKeyType_KEY;};
getValueType()52     virtual registry::RegistryValueType SAL_CALL getValueType(  ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return registry::RegistryValueType_NOT_DEFINED;};
getLongValue()53     virtual sal_Int32 SAL_CALL getLongValue(  ) throw (registry::InvalidRegistryException, registry::InvalidValueException, uno::RuntimeException) {return 0;};
setLongValue(sal_Int32)54     virtual void SAL_CALL setLongValue( sal_Int32 /*value*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {};
getLongListValue()55     virtual uno::Sequence< sal_Int32 > SAL_CALL getLongListValue(  ) throw (registry::InvalidRegistryException, registry::InvalidValueException, uno::RuntimeException) { return uno::Sequence<sal_Int32>(); };
setLongListValue(const uno::Sequence<sal_Int32> &)56     virtual void SAL_CALL setLongListValue( const uno::Sequence< sal_Int32 >& /*seqValue*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {};
getAsciiValue()57     virtual rtl::OUString SAL_CALL getAsciiValue(  ) throw (registry::InvalidRegistryException, registry::InvalidValueException, uno::RuntimeException) {return rtl::OUString();};
setAsciiValue(const rtl::OUString &)58     virtual void SAL_CALL setAsciiValue( const rtl::OUString& /*value*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {};
getAsciiListValue()59     virtual uno::Sequence< rtl::OUString > SAL_CALL getAsciiListValue(  ) throw (registry::InvalidRegistryException, registry::InvalidValueException, uno::RuntimeException) {return uno::Sequence<rtl::OUString>();};
setAsciiListValue(const uno::Sequence<rtl::OUString> &)60     virtual void SAL_CALL setAsciiListValue( const uno::Sequence< rtl::OUString >& /*seqValue*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {};
getStringValue()61     virtual rtl::OUString SAL_CALL getStringValue(  ) throw (registry::InvalidRegistryException, registry::InvalidValueException, uno::RuntimeException) {return rtl::OUString();};
setStringValue(const rtl::OUString &)62     virtual void SAL_CALL setStringValue( const rtl::OUString& /*value*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {};
getStringListValue()63     virtual uno::Sequence< rtl::OUString > SAL_CALL getStringListValue(  ) throw (registry::InvalidRegistryException, registry::InvalidValueException, uno::RuntimeException) {return uno::Sequence<rtl::OUString>();};
setStringListValue(const uno::Sequence<rtl::OUString> &)64     virtual void SAL_CALL setStringListValue( const uno::Sequence< rtl::OUString >& /*seqValue*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {};
getBinaryValue()65     virtual uno::Sequence< sal_Int8 > SAL_CALL getBinaryValue(  ) throw (registry::InvalidRegistryException, registry::InvalidValueException, uno::RuntimeException) {return uno::Sequence<sal_Int8>();};
setBinaryValue(const uno::Sequence<sal_Int8> &)66     virtual void SAL_CALL setBinaryValue( const uno::Sequence< sal_Int8 >& /*value*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {};
openKey(const rtl::OUString &)67     virtual uno::Reference< registry::XRegistryKey > SAL_CALL openKey( const rtl::OUString& /*aKeyName*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return uno::Reference<registry::XRegistryKey>();};
createKey(const rtl::OUString &)68     virtual uno::Reference< registry::XRegistryKey > SAL_CALL createKey( const rtl::OUString& /*aKeyName*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return uno::Reference<registry::XRegistryKey>();};
closeKey()69     virtual void SAL_CALL closeKey(  ) throw (registry::InvalidRegistryException, uno::RuntimeException) {};
deleteKey(const rtl::OUString &)70     virtual void SAL_CALL deleteKey( const rtl::OUString& /*rKeyName*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {};
openKeys()71     virtual uno::Sequence< uno::Reference< registry::XRegistryKey > > SAL_CALL openKeys(  ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return uno::Sequence<uno::Reference<registry::XRegistryKey> >();};
getKeyNames()72     virtual uno::Sequence< rtl::OUString > SAL_CALL getKeyNames(  ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return uno::Sequence<rtl::OUString>();};
createLink(const rtl::OUString &,const rtl::OUString &)73     virtual sal_Bool SAL_CALL createLink( const rtl::OUString& /*aLinkName*/, const rtl::OUString& /*aLinkTarget*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return sal_False;};
deleteLink(const rtl::OUString &)74     virtual void SAL_CALL deleteLink( const rtl::OUString& /*rLinkName*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {};
getLinkTarget(const rtl::OUString &)75     virtual rtl::OUString SAL_CALL getLinkTarget( const rtl::OUString& /*rLinkName*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return rtl::OUString();};
getResolvedName(const rtl::OUString &)76     virtual rtl::OUString SAL_CALL getResolvedName( const rtl::OUString& /*aKeyName*/ ) throw (registry::InvalidRegistryException, uno::RuntimeException) {return rtl::OUString();};
77 };
78 
79 
80 
s_test__cppu_loadSharedLibComponentFactory(char const * pServicePurpose)81 static rtl::OUString s_test__cppu_loadSharedLibComponentFactory(char const * pServicePurpose)
82 {
83     rtl::OUString result;
84 
85     rtl::OUString servicePurpose = rtl::OUString(pServicePurpose,
86                                                  rtl_str_getLength(pServicePurpose),
87                                                  RTL_TEXTENCODING_ASCII_US);
88 
89     result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\ts_test__cppu_loadSharedLibComponentFactory "));
90     result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("(\""));
91     result += servicePurpose;
92     result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\") - "));
93 
94     try {
95         uno::Reference<uno::XInterface> xObject(
96             cppu::loadSharedLibComponentFactory(
97                 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SAL_DLLPREFIX "TestComponent.uno" SAL_DLLEXTENSION)),
98                 rtl::OUString(),
99                 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("impl.test.TestComponent")) + servicePurpose,
100                 uno::Reference<lang::XMultiServiceFactory>(),
101                 uno::Reference<registry::XRegistryKey>())
102             );
103 
104         rtl::OUString envDcp_purpose(cppu::EnvDcp::getPurpose(g_envDcp));
105         if (envDcp_purpose == servicePurpose)
106             result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("passed\n"));
107 
108         else
109         {
110             result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FAILED - got: \""));
111             result += envDcp_purpose;
112             result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\"\n"));
113         }
114     }
115     catch(uno::Exception & exception) {
116         result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FAILED - got: \""));
117         result += exception.Message;
118         result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\"\n"));
119     }
120 
121     return result;
122 }
123 
s_test__cppu_writeSharedLibComponentInfo(char const * pServicePurpose)124 static rtl::OUString s_test__cppu_writeSharedLibComponentInfo(char const * pServicePurpose)
125 {
126     rtl::OUString result;
127 
128     rtl::OUString servicePurpose = rtl::OUString(pServicePurpose,
129                                                  rtl_str_getLength(pServicePurpose),
130                                                  RTL_TEXTENCODING_ASCII_US);
131 
132     result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\ts_test__cppu_writeSharedLibComponentInfo "));
133     result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("(\""));
134     result += servicePurpose;
135     result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\") - "));
136 
137     char buff[256];
138     strcpy(buff, "TestComponent.uno=");
139     strcat(buff, pServicePurpose);
140 
141     putenv(buff);
142 
143     try {
144         cppu::writeSharedLibComponentInfo(
145             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SAL_DLLPREFIX "TestComponent.uno" SAL_DLLEXTENSION)),
146             rtl::OUString(),
147             uno::Reference<lang::XMultiServiceFactory>(),
148             uno::Reference<registry::XRegistryKey>(new MyKey)
149             );
150 
151         rtl::OUString envDcp_purpose(cppu::EnvDcp::getPurpose(g_envDcp));
152         if (envDcp_purpose == servicePurpose)
153             result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("passed\n"));
154 
155         else
156         {
157             result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FAILED - got: \""));
158             result += envDcp_purpose;
159             result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\"\n"));
160         }
161     }
162     catch(uno::Exception & exception) {
163         result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FAILED - got: \""));
164         result += exception.Message;
165         result += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\"\n"));
166     }
167 
168     return result;
169 }
170 
171 
172 SAL_IMPLEMENT_MAIN_WITH_ARGS(/*argc*/, argv)
173 {
174     int result = 0;
175 
176     rtl::OUString message;
177 
178     message += rtl::OUString(argv[0], rtl_str_getLength(argv[0]), RTL_TEXTENCODING_ASCII_US);
179     message += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\n"));
180 
181     message += s_test__cppu_loadSharedLibComponentFactory(":unsafe");
182     message += s_test__cppu_loadSharedLibComponentFactory(":affine");
183     message += s_test__cppu_loadSharedLibComponentFactory("");
184 
185     message += s_test__cppu_writeSharedLibComponentInfo(":unsafe");
186     message += s_test__cppu_writeSharedLibComponentInfo(":affine");
187     message += s_test__cppu_writeSharedLibComponentInfo("");
188 
189     if (message.indexOf(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FAILED"))) == -1)
190         message += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TESTS PASSED\n"));
191 
192     else
193     {
194         message += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TESTS _NOT_ PASSED\n"));
195         result = -1;
196     }
197 
198     std::cout << rtl::OUStringToOString(message, RTL_TEXTENCODING_ASCII_US).getStr();
199 
200     return result;
201 }
202