update dev300-m58
[ooovba.git] / extensions / workben / testresource.cxx
blobeb2de7cfafe688a82c58f7030c574da5f476bec4
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: testresource.cxx,v $
10 * $Revision: 1.5 $
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 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_extensions.hxx"
34 #include <smart/com/sun/star/registry/XImplementationRegistration.hxx>
35 #include <smart/com/sun/star/script/XInvocation.hxx>
37 #include <rtl/ustring.hxx>
38 #include <vos/dynload.hxx>
39 #include <vos/diagnose.hxx>
40 #include <usr/services.hxx>
41 #include <vcl/svapp.hxx>
43 using namespace rtl;
44 using namespace vos;
45 using namespace usr;
47 class MyApp : public Application
49 public:
50 void Main();
53 MyApp aMyApp;
55 // -----------------------------------------------------------------------
57 void MyApp::Main()
59 XMultiServiceFactoryRef xSMgr = createRegistryServiceManager();
60 registerUsrServices( xSMgr );
61 setProcessServiceManager( xSMgr );
63 XInterfaceRef x = xSMgr->createInstance( L"com.sun.star.registry.ImplementationRegistration" );
64 XImplementationRegistrationRef xReg( x, USR_QUERY );
65 sal_Char szBuf[1024];
66 ORealDynamicLoader::computeModuleName( "res", szBuf, 1024 );
67 UString aDllName( StringToOUString( szBuf, CHARSET_SYSTEM ) );
68 xReg->registerImplementation( L"com.sun.star.loader.SharedLibrary", aDllName, XSimpleRegistryRef() );
70 x = xSMgr->createInstance( L"com.sun.star.resource.VclStringResourceLoader" );
71 XInvocationRef xResLoader( x, USR_QUERY );
72 XIntrospectionAccessRef xIntrospection = xResLoader->getIntrospection();
73 UString aFileName( L"TestResource" );
74 UsrAny aVal;
75 aVal.setString( aFileName );
76 xResLoader->setValue( L"FileName", aVal );
78 Sequence< UsrAny > Args( 1 );
79 Sequence< INT16 > OutPos;
80 Sequence< UsrAny > OutArgs;
81 Args.getArray()[0].setINT32( 1000 );
83 BOOL b = xResLoader->invoke( L"hasString", Args, OutPos, OutArgs ).getBOOL();
84 VOS_ENSHURE( b, "hasString" );
86 UString aStr = xResLoader->invoke( L"getString", Args, OutPos, OutArgs ).getString();
87 VOS_ENSHURE( aStr == L"Hello", "getString" );
89 Args.getArray()[0].setINT32( 1001 );
90 b = xResLoader->invoke( L"hasString", Args, OutPos, OutArgs ).getBOOL();
91 VOS_ENSHURE( !b, "!hasString" );
93 xReg->revokeImplementation( aDllName, XSimpleRegistryRef() );