LibreOffice Module svtools (master) 1
test.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
21// switches
22// use it to enable test scenarios
23
24
25#define TEST_DYNAMICMENUOPTIONS
26
28
30#include <com/sun/star/lang/XMultiServiceFactory.hpp>
31#include <com/sun/star/lang/XInitialization.hpp>
32#include <com/sun/star/registry/XSimpleRegistry.hpp>
33
34#include <cppuhelper/servicefactory.hxx>
36#include <com/sun/star/uno/Reference.h>
37#include <com/sun/star/uno/Sequence.h>
38
39#include <rtl/ustring>
40#include <rtl/ustrbuf.hxx>
41#include <osl/diagnose.h>
42#include <sal/log.hxx>
43
44#include <vcl/event.hxx>
45#include <vcl/svapp.hxx>
46
47using namespace ::osl ;
48using namespace ::comphelper ;
49using namespace ::com::sun::star::uno ;
50using namespace ::com::sun::star::lang ;
51using namespace ::com::sun::star::beans ;
52using namespace ::com::sun::star::registry ;
53
55{
56
57 // interface
58
59 public:
60 void Main();
61
62
63 // test methods
64
65 private:
67
68
69 // helper methods
70
71 private:
72 static Reference< XMultiServiceFactory > getUNOServiceManager();
73
74
75 // member
76
77 private:
78
79}; // class TestApplication
80
81
82// global variables
83
84
86
87
88// main
89
90
92{
97 // Init global servicemanager and set it for external services.
98 ::comphelper::setProcessServiceFactory( TestApplication::getUNOServiceManager() );
99 // Control success of operation.
100 OSL_ENSURE( !(::comphelper::getProcessServiceFactory()!=TestApplication::getUNOServiceManager()), "TestApplication::Main() Global servicemanager not right initialized." );
101
106 #ifdef TEST_DYNAMICMENUOPTIONS
108 #endif
109
110// Execute();
111 OSL_FAIL( "Test was successful!" );
112}
113
114
115// test configuration of dynamic menus "New" and "Wizard"
116
118{
120
121 // Test:
122 // read menus
123 // if( menus == empty )
124 // {
125 // fill it with samples
126 // read it again
127 // }
128 // output content
129
130 Sequence< Sequence< PropertyValue > > lNewMenu = aCFG.GetMenu( EDynamicMenuType::NewMenu );
131 Sequence< Sequence< PropertyValue > > lWizardMenu = aCFG.GetMenu( EDynamicMenuType::WizardMenu );
132
133 if( lNewMenu.getLength() < 1 )
134 {
135 aCFG.AppendItem( EDynamicMenuType::NewMenu, "private:factory/swriter", "new writer", "icon_writer", "_blank");
136 aCFG.AppendItem( EDynamicMenuType::NewMenu, "private:factory/scalc", "new calc", "icon_calc", "_blank");
137 aCFG.AppendItem( EDynamicMenuType::NewMenu, "private:factory/sdraw", "new draw", "icon_draw", "_blank");
138
139 lNewMenu = aCFG.GetMenu( EDynamicMenuType::NewMenu );
140 }
141
142 if( lWizardMenu.getLength() < 1 )
143 {
144 aCFG.AppendItem( EDynamicMenuType::WizardMenu, "file://a", "system file", "icon_file", "_self");
145 aCFG.AppendItem( EDynamicMenuType::WizardMenu, "ftp://b", "ftp host", "icon_ftp", "_self");
146 aCFG.AppendItem( EDynamicMenuType::WizardMenu, "http://c", "www", "icon_www", "_self");
147
148 lWizardMenu = aCFG.GetMenu( EDynamicMenuType::WizardMenu );
149 }
150
151 sal_uInt32 nItemCount ;
152 sal_uInt32 nItem ;
153 sal_uInt32 nPropertyCount;
154 sal_uInt32 nProperty ;
155 OUString sPropertyValue;
156 OUStringBuffer sOut( 5000 ) ;
157
158 nItemCount = lNewMenu.getLength();
159 for( nItem=0; nItem<nItemCount; ++nItem )
160 {
161 nPropertyCount = lNewMenu[nItem].getLength();
162 for( nProperty=0; nProperty<nPropertyCount; ++nProperty )
163 {
164 lNewMenu[nItem][nProperty].Value >>= sPropertyValue;
165
166 sOut.appendAscii ( "New/" );
167 sOut.append ( (sal_Int32)nItem );
168 sOut.appendAscii ( "/" );
169 sOut.append ( lNewMenu[nItem][nProperty].Name );
170 sOut.appendAscii ( " = " );
171 sOut.append ( sPropertyValue );
172 sOut.appendAscii ( "\n" );
173 }
174 }
175
176 sOut.appendAscii("\n--------------------------------------\n");
177
178 nItemCount = lWizardMenu.getLength();
179 for( nItem=0; nItem<nItemCount; ++nItem )
180 {
181 nPropertyCount = lNewMenu[nItem].getLength();
182 for( nProperty=0; nProperty<nPropertyCount; ++nProperty )
183 {
184 lWizardMenu[nItem][nProperty].Value >>= sPropertyValue;
185
186 sOut.appendAscii ( "Wizard/" );
187 sOut.append ( (sal_Int32)nItem );
188 sOut.appendAscii ( "/" );
189 sOut.append ( lNewMenu[nItem][nProperty].Name );
190 sOut.appendAscii ( " = " );
191 sOut.append ( sPropertyValue );
192 sOut.appendAscii ( "\n" );
193 }
194 }
195
196 SAL_WARN( "svtools", sOut );
197}
198
199
200// create new uno servicemanager by using normal applicat.rdb and user.rdb of an office installation!
201// Don't use this application at the same time like the office!
202
203Reference< XMultiServiceFactory > TestApplication::getUNOServiceManager()
204{
205 static Reference< XMultiServiceFactory > smgr;
206 if( ! smgr.is() )
207 {
208 Reference< XComponentContext > rCtx =
210 smgr.set( rCtx->getServiceManager() , UNO_QUERY );
211 }
212 return smgr;
213}
214
215/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void impl_testDynamicMenuOptions()
Definition: test.cxx:117
static Reference< XMultiServiceFactory > getUNOServiceManager()
Definition: test.cxx:203
void Main()
Definition: test.cxx:91
#define SAL_WARN(area, stream)
CPPUHELPER_DLLPUBLIC css::uno::Reference< css::uno::XComponentContext > SAL_CALL defaultBootstrap_InitialComponentContext()
TestApplication aTestApplication
Definition: test.cxx:85
OUString Name