Branch libreoffice-5-0-4
[LibreOffice.git] / extensions / workben / testresource.cxx
blobe31420824349d5845125263c171de649777c173d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <smart/com/sun/star/registry/XImplementationRegistration.hxx>
22 #include <smart/com/sun/star/script/XInvocation.hxx>
24 #include <rtl/ustring.hxx>
25 #include <osl/diagnose.h>
26 #include <usr/services.hxx>
27 #include <vcl/svapp.hxx>
29 using namespace usr;
30 using ::rtl::StringToOUString;
32 class MyApp : public Application
34 public:
35 void Main();
38 MyApp aMyApp;
42 void MyApp::Main()
44 XMultiServiceFactoryRef xSMgr = createRegistryServiceManager();
45 registerUsrServices( xSMgr );
46 setProcessServiceManager( xSMgr );
48 XInterfaceRef x = xSMgr->createInstance( L"com.sun.star.registry.ImplementationRegistration" );
49 XImplementationRegistrationRef xReg( x, USR_QUERY );
50 sal_Char szBuf[1024];
51 ORealDynamicLoader::computeModuleName( "res", szBuf, 1024 );
52 UString aDllName( StringToOUString( szBuf, CHARSET_SYSTEM ) );
53 xReg->registerImplementation( L"com.sun.star.loader.SharedLibrary", aDllName, XSimpleRegistryRef() );
55 x = xSMgr->createInstance( L"com.sun.star.resource.VclStringResourceLoader" );
56 XInvocationRef xResLoader( x, USR_QUERY );
57 XIntrospectionAccessRef xIntrospection = xResLoader->getIntrospection();
58 UString aFileName( L"TestResource" );
59 UsrAny aVal;
60 aVal.setString( aFileName );
61 xResLoader->setValue( L"FileName", aVal );
63 Sequence< UsrAny > Args( 1 );
64 Sequence< INT16 > OutPos;
65 Sequence< UsrAny > OutArgs;
66 Args.getArray()[0].setINT32( 1000 );
68 BOOL b = xResLoader->invoke( L"hasString", Args, OutPos, OutArgs ).getBOOL();
69 OSL_ENSURE( b, "hasString" );
71 UString aStr = xResLoader->invoke( L"getString", Args, OutPos, OutArgs ).getString();
72 OSL_ENSURE( aStr == L"Hello", "getString" );
74 Args.getArray()[0].setINT32( 1001 );
75 b = xResLoader->invoke( L"hasString", Args, OutPos, OutArgs ).getBOOL();
76 OSL_ENSURE( !b, "!hasString" );
78 xReg->revokeImplementation( aDllName, XSimpleRegistryRef() );
81 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */