1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 #include <vcl/svapp.hxx>
30 // This works and was used before for standalone test, not sure why
39 #include <com/sun/star/xml/sax/SAXException.hpp>
40 #include <comphelper/processfactory.hxx>
41 #include <cppuhelper/bootstrap.hxx>
42 #include <rtl/ustring.hxx>
43 #include <ucbhelper/configurationkeys.hxx>
44 #include <ucbhelper/contentbroker.hxx>
46 #define SORT_DLG 1 /* requires sfx2, svx to be compiled */
48 #include "scitems.hxx"
49 #include "uiitems.hxx"
55 #undef _LAYOUT_POST_HXX
57 #include "recover.hxx"
58 #undef _LAYOUT_POST_HXX
61 #include "sortdlg.hxx"
62 #undef _LAYOUT_POST_HXX
65 #include "wordcountdialog.hxx"
66 #undef _LAYOUT_POST_HXX
69 #undef _LAYOUT_POST_HXX
71 #include <layout/layout-pre.hxx>
73 using namespace ::rtl
;
74 using namespace ::cppu
;
75 using namespace ::com::sun::star
;
76 using namespace ::com::sun::star::uno
;
78 class LayoutTest
: public Application
80 Reference
< XComponentContext
> mxContext
;
81 Reference
< lang::XMultiServiceFactory
> mxMSF
;
85 std::list
< OUString
> mFiles
;
88 LayoutTest( char const* installDir
);
92 void ExceptionalMain();
95 void LoadFile( OUString
const &aName
);
97 void ParseCommandLine();
102 fprintf (stderr
, "usage: test [--inst OOO_INSTALL_PREFIX] [DIALOG.XML]... | --test [DIALOG.XML]\n" );
106 static uno::Reference
< lang::XSingleServiceFactory
> get_factory( char const *service
)
108 uno::Reference
< lang::XSingleServiceFactory
> xFactory(
109 comphelper::createProcessComponent(
110 rtl::OUString::createFromAscii( service
) ), uno::UNO_QUERY
);
112 if ( !xFactory
.is() )
113 fprintf( stderr
, "error loading: %s\n", service
);
117 #define GET_FACTORY(x) get_factory( #x )
119 void LayoutTest::LoadFile( const OUString
&aTestFile
)
121 fprintf( stderr
, "TEST: layout instance\n" );
123 uno::Reference
< lang::XSingleServiceFactory
> xFactory
124 = GET_FACTORY( com
.sun
.star
.awt
.Layout
);
125 if ( !xFactory
.is() )
127 fprintf( stderr
, "Layout engine not installed\n" );
128 throw uno::RuntimeException(
129 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Layout engine not installed" ) ),
130 uno::Reference
< uno::XInterface
>() );
132 fprintf( stderr
, "TEST: initing root\n" );
134 uno::Sequence
< uno::Any
> aParams( 1 );
135 aParams
[0] <<= aTestFile
;
137 uno::Reference
< awt::XLayoutRoot
> xRoot (
138 xFactory
->createInstanceWithArguments( aParams
),
141 fprintf( stderr
, "TEST: file loaded\n" );
144 void LayoutTest::InitUCB()
147 Sequence
< Any
> aArgs( 6 );
149 <<= OUString::createFromAscii( UCB_CONFIGURATION_KEY1_LOCAL
);
151 <<= OUString::createFromAscii( UCB_CONFIGURATION_KEY2_OFFICE
);
152 aArgs
[2] <<= OUString::createFromAscii( "PIPE" );
154 aArgs
[4] <<= OUString::createFromAscii( "PORTAL" );
157 if ( !::ucbhelper::ContentBroker::initialize( mxMSF
, aArgs
) )
159 fprintf( stderr
, "Failed to init content broker\n" );
160 fprintf( stderr
, "arg[0]: %s\n", UCB_CONFIGURATION_KEY1_LOCAL
);
161 fprintf( stderr
, "arg[1]: %s\n", UCB_CONFIGURATION_KEY2_OFFICE
);
165 static void support_upstream_brand_prefix ()
167 if ( char const* inst
= getenv( "OOO_INSTALL_PREFIX" ) )
169 char const *brand_prefix
= "/openoffice.org3";
170 OUString brand_dir
= OUString::createFromAscii( inst
)
171 + OUString::createFromAscii( brand_prefix
);
172 struct stat stat_info
;
173 if ( !stat ( OUSTRING_CSTR( brand_dir
), &stat_info
) )
175 OSL_TRACE( "Appending %s to OOO_INSTALL_PREFIX", brand_prefix
);
176 setenv( "OOO_INSTALL_PREFIX", OUSTRING_CSTR( brand_dir
), 1 );
181 void LayoutTest::Init()
184 setenv( "OOO_INSTALL_PREFIX", OUSTRING_CSTR( mInstallDir
), 0 );
185 support_upstream_brand_prefix ();
186 OSL_TRACE( "OOO_INSTALL_PREFIX=%s", getenv( "OOO_INSTALL_PREFIX" ) );
188 mxContext
= defaultBootstrap_InitialComponentContext();
189 mxMSF
= new UnoBootstrapLayout( Reference
< lang::XMultiServiceFactory
>( mxContext
->getServiceManager(), UNO_QUERY
) );
190 ::comphelper::setProcessServiceFactory( mxMSF
);
194 void LayoutTest::ParseCommandLine()
196 printf ("%s\n", __PRETTY_FUNCTION__
);
197 for ( sal_uInt16 i
= 0; i
< GetCommandLineParamCount(); i
++ )
199 OUString aParam
= OUString( GetCommandLineParam( i
) );
200 if ( aParam
.equalsAscii( "-h" ) || aParam
.equalsAscii( "--help" ) )
202 if ( aParam
.equalsAscii( "--inst" ) )
204 if ( i
>= GetCommandLineParamCount() - 1)
206 mInstallDir
= GetCommandLineParam( ++i
);
207 setenv( "OOO_INSTALL_PREFIX", OUSTRING_CSTR( mInstallDir
), 1 );
209 else if ( aParam
.equalsAscii( "--test" ) )
211 mTestDialog
= OUString::createFromAscii( "zoom" );
212 if (i
+ 1 < GetCommandLineParamCount())
213 mTestDialog
= GetCommandLineParam( ++i
);
215 else if ( aParam
.equalsAscii( "--editor" ) )
218 mFiles
.push_back( aParam
);
221 if ( mFiles
.size() <= 0 )
222 mFiles
.push_back( OUString::createFromAscii( "layout.xml" ) );
225 void LayoutTest::RunEditor()
229 && mFiles
.front().compareToAscii( "layout.xml" ) != 0 )
230 aFile
= mFiles
.front();
231 Editor
editor( mxMSF
, aFile
);
236 short RunDialog( Dialog
& dialog
)
239 short result
= dialog
.Execute();
240 fprintf( stderr
, "Done: dialog execute exited:%d\n", result
);
245 short RunDialog( ::Dialog
& dialog
)
248 short result
= dialog
.Execute();
249 fprintf( stderr
, "Done: dialog execute exited:%d\n", result
);
256 get_factory( "com.sun.star.comp.sfx2.DocumentTemplates" );
257 get_factory( "com.sun.star.comp.Calc.SpreadsheetDocument" );
258 GET_FACTORY( com
.sun
.star
.i18n
.Transliteration
.l10n
);
260 #endif /* SORT_DLG */
262 void TestDialog( OUString
const& name
)
266 else if ( name
.equalsAscii( "plugin" ) )
268 PluginDialog
plugin ( 0 );
271 else if ( name
.equalsAscii( "query" ) )
273 QueryBox
query ( 0, "Do you want to do?", "do");
276 else if ( name
.equalsAscii( "query-compat" ) )
279 WinBits( WB_YES_NO
| WB_DEF_YES
),
280 // WinBits( WB_ABORT_RETRY_IGNORE ),
281 OUString::createFromAscii ("Do you want to do?"));
284 else if ( name
.equalsAscii( "recover" ) )
286 SvxRecoverDialog
recover ( 0 );
287 RunDialog( recover
);
290 else if ( name
.equalsAscii( "sort" ) )
293 ScSortDlg
sort (0, 0);
296 #endif /* SORT_DLG */
297 else if ( name
.equalsAscii( "wordcount" ) )
299 SwWordCountDialog
words ( 0 );
302 else if ( name
.equalsAscii( "zoom" ) )
304 SvxZoomDialog
zoom( 0 );
309 void LayoutTest::RunFiles()
311 fprintf( stderr
, "TEST: loading files\n" );
312 for ( std::list
< OUString
>::iterator i
= mFiles
.begin(); i
!= mFiles
.end(); i
++ )
314 fprintf( stderr
, "TEST: executing\n" );
316 fprintf( stderr
, "TEST: done executing\n" );
319 void LayoutTest::ExceptionalMain()
321 if ( mTestDialog
.getLength() )
322 TestDialog( mTestDialog
);
323 else if ( mEditMode
)
329 void LayoutTest::Main()
335 catch (xml::sax::SAXException
& rExc
)
337 OString
aStr( OUStringToOString( rExc
.Message
,
338 RTL_TEXTENCODING_ASCII_US
) );
340 if (rExc
.WrappedException
>>= exc
)
342 aStr
+= OString( " >>> " );
343 aStr
+= OUStringToOString( exc
.Message
, RTL_TEXTENCODING_ASCII_US
);
345 fprintf (stderr
, "Parsing error: '%s'\n", aStr
.getStr());
346 OSL_ENSURE( 0, aStr
.getStr() );
348 catch ( uno::Exception
& rExc
)
350 OString
aStr( OUStringToOString( rExc
.Message
,
351 RTL_TEXTENCODING_ASCII_US
) );
352 fprintf (stderr
, "UNO error: '%s'\n", aStr
.getStr());
353 OSL_ENSURE( 0, aStr
.getStr() );
356 Reference
< lang::XComponent
> xComp( mxContext
, UNO_QUERY
);
361 LayoutTest::LayoutTest( char const* installDir
)
362 : mInstallDir( OUString::createFromAscii ( installDir
) )
366 LayoutTest
layout_test( "/usr/local/lib/ooo" );