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