1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: test.cxx,v $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 #include <vcl/svapp.hxx>
34 // This works and was used before for standalone test, not sure why
43 #include <com/sun/star/xml/sax/SAXException.hpp>
44 #include <comphelper/processfactory.hxx>
45 #include <cppuhelper/bootstrap.hxx>
46 #include <rtl/ustring.hxx>
47 #include <ucbhelper/configurationkeys.hxx>
48 #include <ucbhelper/contentbroker.hxx>
50 #define SORT_DLG 1 /* requires sfx2, svx to be compiled */
52 #include "scitems.hxx"
53 #include "uiitems.hxx"
59 #undef _LAYOUT_POST_HXX
61 #include "recover.hxx"
62 #undef _LAYOUT_POST_HXX
65 #include "sortdlg.hxx"
66 #undef _LAYOUT_POST_HXX
69 #include "wordcountdialog.hxx"
70 #undef _LAYOUT_POST_HXX
73 #undef _LAYOUT_POST_HXX
75 #include <layout/layout-pre.hxx>
77 using namespace ::rtl
;
78 using namespace ::cppu
;
79 using namespace ::com::sun::star
;
80 using namespace ::com::sun::star::uno
;
82 class LayoutTest
: public Application
84 Reference
< XComponentContext
> mxContext
;
85 Reference
< lang::XMultiServiceFactory
> mxMSF
;
89 std::list
< OUString
> mFiles
;
92 LayoutTest( char const* installDir
);
96 void ExceptionalMain();
99 void LoadFile( OUString
const &aName
);
101 void ParseCommandLine();
106 fprintf (stderr
, "usage: test [--inst OOO_INSTALL_PREFIX] [DIALOG.XML]... | --test [DIALOG.XML]\n" );
110 static uno::Reference
< lang::XSingleServiceFactory
> get_factory( char const *service
)
112 uno::Reference
< lang::XSingleServiceFactory
> xFactory(
113 comphelper::createProcessComponent(
114 rtl::OUString::createFromAscii( service
) ), uno::UNO_QUERY
);
116 if ( !xFactory
.is() )
117 fprintf( stderr
, "error loading: %s\n", service
);
121 #define GET_FACTORY(x) get_factory( #x )
123 void LayoutTest::LoadFile( const OUString
&aTestFile
)
125 fprintf( stderr
, "TEST: layout instance\n" );
127 uno::Reference
< lang::XSingleServiceFactory
> xFactory
128 = GET_FACTORY( com
.sun
.star
.awt
.Layout
);
129 if ( !xFactory
.is() )
131 fprintf( stderr
, "Layout engine not installed\n" );
132 throw uno::RuntimeException(
133 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Layout engine not installed" ) ),
134 uno::Reference
< uno::XInterface
>() );
136 fprintf( stderr
, "TEST: initing root\n" );
138 uno::Sequence
< uno::Any
> aParams( 1 );
139 aParams
[0] <<= aTestFile
;
141 uno::Reference
< awt::XLayoutRoot
> xRoot (
142 xFactory
->createInstanceWithArguments( aParams
),
145 fprintf( stderr
, "TEST: file loaded\n" );
148 void LayoutTest::InitUCB()
151 Sequence
< Any
> aArgs( 6 );
153 <<= OUString::createFromAscii( UCB_CONFIGURATION_KEY1_LOCAL
);
155 <<= OUString::createFromAscii( UCB_CONFIGURATION_KEY2_OFFICE
);
156 aArgs
[2] <<= OUString::createFromAscii( "PIPE" );
158 aArgs
[4] <<= OUString::createFromAscii( "PORTAL" );
161 if ( !::ucbhelper::ContentBroker::initialize( mxMSF
, aArgs
) )
163 fprintf( stderr
, "Failed to init content broker\n" );
164 fprintf( stderr
, "arg[0]: %s\n", UCB_CONFIGURATION_KEY1_LOCAL
);
165 fprintf( stderr
, "arg[1]: %s\n", UCB_CONFIGURATION_KEY2_OFFICE
);
169 static void support_upstream_brand_prefix ()
171 if ( char const* inst
= getenv( "OOO_INSTALL_PREFIX" ) )
173 char const *brand_prefix
= "/openoffice.org3";
174 OUString brand_dir
= OUString::createFromAscii( inst
)
175 + OUString::createFromAscii( brand_prefix
);
176 struct stat stat_info
;
177 if ( !stat ( OUSTRING_CSTR( brand_dir
), &stat_info
) )
179 OSL_TRACE( "Appending %s to OOO_INSTALL_PREFIX", brand_prefix
);
180 setenv( "OOO_INSTALL_PREFIX", OUSTRING_CSTR( brand_dir
), 1 );
185 void LayoutTest::Init()
188 setenv( "OOO_INSTALL_PREFIX", OUSTRING_CSTR( mInstallDir
), 0 );
189 support_upstream_brand_prefix ();
190 OSL_TRACE( "OOO_INSTALL_PREFIX=%s", getenv( "OOO_INSTALL_PREFIX" ) );
192 mxContext
= defaultBootstrap_InitialComponentContext();
193 mxMSF
= new UnoBootstrapLayout( Reference
< lang::XMultiServiceFactory
>( mxContext
->getServiceManager(), UNO_QUERY
) );
194 ::comphelper::setProcessServiceFactory( mxMSF
);
198 void LayoutTest::ParseCommandLine()
200 printf ("%s\n", __PRETTY_FUNCTION__
);
201 for ( sal_uInt16 i
= 0; i
< GetCommandLineParamCount(); i
++ )
203 OUString aParam
= OUString( GetCommandLineParam( i
) );
204 if ( aParam
.equalsAscii( "-h" ) || aParam
.equalsAscii( "--help" ) )
206 if ( aParam
.equalsAscii( "--oustring-cstr"))
207 exit (printf ("%s: The strings: %s and %s.\n",
209 OUSTRING_CSTR (OUString::createFromAscii ("foo")),
210 OUSTRING_CSTR (OUString::createFromAscii ("bar"))));
211 if ( aParam
.equalsAscii( "--inst" ) )
213 if ( i
>= GetCommandLineParamCount() - 1)
215 mInstallDir
= GetCommandLineParam( ++i
);
216 setenv( "OOO_INSTALL_PREFIX", OUSTRING_CSTR( mInstallDir
), 1 );
218 else if ( aParam
.equalsAscii( "--test" ) )
220 mTestDialog
= OUString::createFromAscii( "zoom" );
221 if (i
+ 1 < GetCommandLineParamCount())
222 mTestDialog
= GetCommandLineParam( ++i
);
224 else if ( aParam
.equalsAscii( "--editor" ) )
227 mFiles
.push_back( aParam
);
230 if ( mFiles
.size() <= 0 )
231 mFiles
.push_back( OUString::createFromAscii( "layout.xml" ) );
234 void LayoutTest::RunEditor()
238 && mFiles
.front().compareToAscii( "layout.xml" ) != 0 )
239 aFile
= mFiles
.front();
240 Editor
editor( mxMSF
, aFile
);
245 short RunDialog( Dialog
& dialog
)
248 short result
= dialog
.Execute();
249 fprintf( stderr
, "Done: dialog execute exited:%d\n", result
);
254 short RunDialog( ::Dialog
& dialog
)
257 short result
= dialog
.Execute();
258 fprintf( stderr
, "Done: dialog execute exited:%d\n", result
);
265 get_factory( "com.sun.star.comp.sfx2.DocumentTemplates" );
266 get_factory( "com.sun.star.comp.Calc.SpreadsheetDocument" );
267 GET_FACTORY( com
.sun
.star
.i18n
.Transliteration
.l10n
);
269 #endif /* SORT_DLG */
271 void TestDialog( OUString
const& name
)
275 else if ( name
.equalsAscii( "plugin" ) )
277 PluginDialog
plugin ( 0 );
280 else if ( name
.equalsAscii( "query" ) )
282 QueryBox
query ( 0, "Do you want to do?", "do");
285 else if ( name
.equalsAscii( "query-compat" ) )
288 WinBits( WB_YES_NO
| WB_DEF_YES
),
289 // WinBits( WB_ABORT_RETRY_IGNORE ),
290 OUString::createFromAscii ("Do you want to do?"));
293 else if ( name
.equalsAscii( "recover" ) )
295 SvxRecoverDialog
recover ( 0 );
296 RunDialog( recover
);
299 else if ( name
.equalsAscii( "sort" ) )
302 ScSortDlg
sort (0, 0);
305 #endif /* SORT_DLG */
306 else if ( name
.equalsAscii( "wordcount" ) )
308 SwWordCountDialog
words ( 0 );
311 else if ( name
.equalsAscii( "zoom" ) )
313 SvxZoomDialog
zoom( 0 );
318 void LayoutTest::RunFiles()
320 fprintf( stderr
, "TEST: loading files\n" );
321 for ( std::list
< OUString
>::iterator i
= mFiles
.begin(); i
!= mFiles
.end(); i
++ )
323 fprintf( stderr
, "TEST: executing\n" );
325 fprintf( stderr
, "TEST: done executing\n" );
328 void LayoutTest::ExceptionalMain()
330 if ( mTestDialog
.getLength() )
331 TestDialog( mTestDialog
);
332 else if ( mEditMode
)
338 void LayoutTest::Main()
344 catch (xml::sax::SAXException
& rExc
)
346 OString
aStr( OUStringToOString( rExc
.Message
,
347 RTL_TEXTENCODING_ASCII_US
) );
349 if (rExc
.WrappedException
>>= exc
)
351 aStr
+= OString( " >>> " );
352 aStr
+= OUStringToOString( exc
.Message
, RTL_TEXTENCODING_ASCII_US
);
354 fprintf (stderr
, "Parsing error: '%s'\n", aStr
.getStr());
355 OSL_ENSURE( 0, aStr
.getStr() );
357 catch ( uno::Exception
& rExc
)
359 OString
aStr( OUStringToOString( rExc
.Message
,
360 RTL_TEXTENCODING_ASCII_US
) );
361 fprintf (stderr
, "UNO error: '%s'\n", aStr
.getStr());
362 OSL_ENSURE( 0, aStr
.getStr() );
365 Reference
< lang::XComponent
> xComp( mxContext
, UNO_QUERY
);
370 LayoutTest::LayoutTest( char const* installDir
)
371 : mInstallDir( OUString::createFromAscii ( installDir
) )
375 LayoutTest
layout_test( "/usr/local/lib/ooo" );