xref: /AOO41X/main/extensions/workben/testresource.cxx (revision 2a97ec55f1442d65917e8c8b82a55ab76c9ff676)
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 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_extensions.hxx"
26 
27 #include <smart/com/sun/star/registry/XImplementationRegistration.hxx>
28 #include <smart/com/sun/star/script/XInvocation.hxx>
29 
30 #include <rtl/ustring.hxx>
31 #include <vos/dynload.hxx>
32 #include <vos/diagnose.hxx>
33 #include <usr/services.hxx>
34 #include <vcl/svapp.hxx>
35 
36 using namespace rtl;
37 using namespace vos;
38 using namespace usr;
39 
40 class MyApp : public Application
41 {
42 public:
43     void        Main();
44 };
45 
46 MyApp aMyApp;
47 
48 // -----------------------------------------------------------------------
49 
Main()50 void MyApp::Main()
51 {
52     XMultiServiceFactoryRef xSMgr = createRegistryServiceManager();
53     registerUsrServices( xSMgr );
54     setProcessServiceManager( xSMgr );
55 
56     XInterfaceRef x = xSMgr->createInstance( L"com.sun.star.registry.ImplementationRegistration" );
57     XImplementationRegistrationRef xReg( x, USR_QUERY );
58     sal_Char szBuf[1024];
59     ORealDynamicLoader::computeModuleName( "res", szBuf, 1024 );
60     UString aDllName( StringToOUString( szBuf, CHARSET_SYSTEM ) );
61     xReg->registerImplementation( L"com.sun.star.loader.SharedLibrary", aDllName, XSimpleRegistryRef() );
62 
63     x = xSMgr->createInstance( L"com.sun.star.resource.VclStringResourceLoader" );
64     XInvocationRef xResLoader( x, USR_QUERY );
65     XIntrospectionAccessRef xIntrospection = xResLoader->getIntrospection();
66     UString aFileName( L"TestResource" );
67     UsrAny aVal;
68     aVal.setString( aFileName );
69     xResLoader->setValue( L"FileName", aVal );
70 
71     Sequence< UsrAny > Args( 1 );
72     Sequence< INT16 > OutPos;
73     Sequence< UsrAny > OutArgs;
74     Args.getArray()[0].setINT32( 1000 );
75 
76     BOOL b = xResLoader->invoke( L"hasString", Args, OutPos, OutArgs ).getBOOL();
77     VOS_ENSHURE( b, "hasString" );
78 
79     UString aStr = xResLoader->invoke( L"getString", Args, OutPos, OutArgs ).getString();
80     VOS_ENSHURE( aStr == L"Hello", "getString" );
81 
82     Args.getArray()[0].setINT32( 1001 );
83     b = xResLoader->invoke( L"hasString", Args, OutPos, OutArgs ).getBOOL();
84     VOS_ENSHURE( !b, "!hasString" );
85 
86     xReg->revokeImplementation( aDllName, XSimpleRegistryRef() );
87 }
88 
89