Update ooo320-m1
[ooovba.git] / svtools / source / config / test / test.cxx
blob7d6d7d8dd5896bde280e71860e78abbe3a0b48dc
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: test.cxx,v $
10 * $Revision: 1.7 $
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_svtools.hxx"
34 //_________________________________________________________________________________________________________________
35 // switches
36 // use it to enable test szenarios
37 //_________________________________________________________________________________________________________________
39 #define TEST_DYNAMICMENUOPTIONS
41 //_________________________________________________________________________________________________________________
42 // my own includes
43 //_________________________________________________________________________________________________________________
45 #include <svtools/dynamicmenuoptions.hxx>
47 //_________________________________________________________________________________________________________________
48 // interface includes
49 //_________________________________________________________________________________________________________________
50 #include <cppuhelper/bootstrap.hxx>
51 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
52 #include <com/sun/star/lang/XInitialization.hpp>
53 #include <com/sun/star/registry/XSimpleRegistry.hpp>
55 //_________________________________________________________________________________________________________________
56 // other includes
57 //_________________________________________________________________________________________________________________
59 #ifndef _COMPHELPER_PROCESSFACTORY_HXX_
60 #include <comphelper/regpathhelper.hxx>
61 #endif
62 #include <cppuhelper/servicefactory.hxx>
63 #include <cppuhelper/bootstrap.hxx>
64 #include <comphelper/processfactory.hxx>
65 #include <com/sun/star/uno/Reference.h>
66 #include <com/sun/star/uno/Sequence.h>
68 #ifndef _RTL_USTRING_
69 #include <rtl/ustring.hxx>
70 #endif
71 #include <rtl/ustrbuf.hxx>
72 #include <osl/diagnose.h>
73 #include <osl/mutex.hxx>
76 #include <svtools/unoiface.hxx>
77 #include <tools/urlobj.hxx>
79 #include <vcl/event.hxx>
80 #include <vcl/svapp.hxx>
81 #include <vcl/wrkwin.hxx>
82 #include <vcl/msgbox.hxx>
83 #include <stdio.h>
85 //_________________________________________________________________________________________________________________
86 // const
87 //_________________________________________________________________________________________________________________
89 //_________________________________________________________________________________________________________________
90 // namespace
91 //_________________________________________________________________________________________________________________
93 using namespace ::rtl ;
94 using namespace ::osl ;
95 using namespace ::comphelper ;
96 using namespace ::com::sun::star::uno ;
97 using namespace ::com::sun::star::lang ;
98 using namespace ::com::sun::star::beans ;
99 using namespace ::com::sun::star::registry ;
101 //_________________________________________________________________________________________________________________
102 // defines
103 //_________________________________________________________________________________________________________________
105 #define ASCII( STEXT ) OUString( RTL_CONSTASCII_USTRINGPARAM( STEXT ))
107 #define SERVICENAME_SIMPLEREGISTRY OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.registry.SimpleRegistry" ))
108 #define SERVICENAME_NESTEDREGISTRY OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.registry.NestedRegistry" ))
110 //_________________________________________________________________________________________________________________
111 // declarations
112 //_________________________________________________________________________________________________________________
114 class TestApplication : public Application
116 //*************************************************************************************************************
117 // interface
118 //*************************************************************************************************************
119 public:
120 void Main();
122 //*************************************************************************************************************
123 // test methods
124 //*************************************************************************************************************
125 private:
126 void impl_testDynamicMenuOptions();
128 //*************************************************************************************************************
129 // helper methods
130 //*************************************************************************************************************
131 private:
132 static Reference< XMultiServiceFactory > getUNOServiceManager();
134 //*************************************************************************************************************
135 // member
136 //*************************************************************************************************************
137 private:
139 }; // class TestApplication
141 //_________________________________________________________________________________________________________________
142 // global variables
143 //_________________________________________________________________________________________________________________
145 TestApplication aTestApplication ;
147 //_________________________________________________________________________________________________________________
148 // main
149 //_________________________________________________________________________________________________________________
151 void TestApplication::Main()
153 /**-***********************************************************************************************************
154 initialize program
155 **************************************************************************************************************/
157 // Init global servicemanager and set it for external services.
158 ::comphelper::setProcessServiceFactory( TestApplication::getUNOServiceManager() );
159 // Control sucess of operation.
160 OSL_ENSURE( !(::comphelper::getProcessServiceFactory()!=TestApplication::getUNOServiceManager()), "TestApplication::Main()\nGlobal servicemanager not right initialized.\n" );
162 /**-***********************************************************************************************************
163 test area
164 **************************************************************************************************************/
166 #ifdef TEST_DYNAMICMENUOPTIONS
167 impl_testDynamicMenuOptions();
168 #endif
170 // Execute();
171 OSL_ENSURE( sal_False, "Test was successful!\n" );
174 //*****************************************************************************************************************
175 // test configuration of dynamic menus "New" and "Wizard"
176 //*****************************************************************************************************************
177 void TestApplication::impl_testDynamicMenuOptions()
179 SvtDynamicMenuOptions aCFG;
181 // Test:
182 // read menus
183 // if( menus == empty )
184 // {
185 // fill it with samples
186 // read it again
187 // }
188 // output content
190 Sequence< Sequence< PropertyValue > > lNewMenu = aCFG.GetMenu( E_NEWMENU );
191 Sequence< Sequence< PropertyValue > > lWizardMenu = aCFG.GetMenu( E_WIZARDMENU );
193 if( lNewMenu.getLength() < 1 )
195 aCFG.AppendItem( E_NEWMENU, ASCII("private:factory/swriter"), ASCII("new writer"), ASCII("icon_writer"), ASCII("_blank") );
196 aCFG.AppendItem( E_NEWMENU, ASCII("private:factory/scalc" ), ASCII("new calc" ), ASCII("icon_calc" ), ASCII("_blank") );
197 aCFG.AppendItem( E_NEWMENU, ASCII("private:factory/sdraw" ), ASCII("new draw" ), ASCII("icon_draw" ), ASCII("_blank") );
199 lNewMenu = aCFG.GetMenu( E_NEWMENU );
202 if( lWizardMenu.getLength() < 1 )
204 aCFG.AppendItem( E_WIZARDMENU, ASCII("file://a"), ASCII("system file"), ASCII("icon_file"), ASCII("_self") );
205 aCFG.AppendItem( E_WIZARDMENU, ASCII("ftp://b" ), ASCII("ftp host" ), ASCII("icon_ftp" ), ASCII("_self") );
206 aCFG.AppendItem( E_WIZARDMENU, ASCII("http://c"), ASCII("www" ), ASCII("icon_www" ), ASCII("_self") );
208 lWizardMenu = aCFG.GetMenu( E_WIZARDMENU );
211 sal_uInt32 nItemCount ;
212 sal_uInt32 nItem ;
213 sal_uInt32 nPropertyCount;
214 sal_uInt32 nProperty ;
215 OUString sPropertyValue;
216 OUStringBuffer sOut( 5000 ) ;
218 nItemCount = lNewMenu.getLength();
219 for( nItem=0; nItem<nItemCount; ++nItem )
221 nPropertyCount = lNewMenu[nItem].getLength();
222 for( nProperty=0; nProperty<nPropertyCount; ++nProperty )
224 lNewMenu[nItem][nProperty].Value >>= sPropertyValue;
226 sOut.appendAscii ( "New/" );
227 sOut.append ( (sal_Int32)nItem );
228 sOut.appendAscii ( "/" );
229 sOut.append ( lNewMenu[nItem][nProperty].Name );
230 sOut.appendAscii ( " = " );
231 sOut.append ( sPropertyValue );
232 sOut.appendAscii ( "\n" );
236 sOut.appendAscii("\n--------------------------------------\n");
238 nItemCount = lWizardMenu.getLength();
239 for( nItem=0; nItem<nItemCount; ++nItem )
241 nPropertyCount = lNewMenu[nItem].getLength();
242 for( nProperty=0; nProperty<nPropertyCount; ++nProperty )
244 lWizardMenu[nItem][nProperty].Value >>= sPropertyValue;
246 sOut.appendAscii ( "Wizard/" );
247 sOut.append ( (sal_Int32)nItem );
248 sOut.appendAscii ( "/" );
249 sOut.append ( lNewMenu[nItem][nProperty].Name );
250 sOut.appendAscii ( " = " );
251 sOut.append ( sPropertyValue );
252 sOut.appendAscii ( "\n" );
256 OSL_ENSURE( sal_False, OUStringToOString( sOut.makeStringAndClear(), RTL_TEXTENCODING_UTF8 ).getStr() );
259 //*****************************************************************************************************************
260 // create new uno servicemanager by using normall applicat.rdb and user.rdb of an office installation!
261 // Don't use this application at same time like the office!
262 //*****************************************************************************************************************
263 Reference< XMultiServiceFactory > TestApplication::getUNOServiceManager()
265 static Reference< XMultiServiceFactory > smgr;
266 if( ! smgr.is() )
268 Reference< XComponentContext > rCtx =
269 cppu::defaultBootstrap_InitialComponentContext();
270 smgr = Reference< XMultiServiceFactory > ( rCtx->getServiceManager() , UNO_QUERY );
272 return smgr;