diff options
Diffstat (limited to 'toolkit/workben/layout/test.cxx')
-rw-r--r-- | toolkit/workben/layout/test.cxx | 214 |
1 files changed, 129 insertions, 85 deletions
diff --git a/toolkit/workben/layout/test.cxx b/toolkit/workben/layout/test.cxx index b98eaff2fc80..1bd9603fc5ac 100644 --- a/toolkit/workben/layout/test.cxx +++ b/toolkit/workben/layout/test.cxx @@ -30,7 +30,6 @@ ************************************************************************/ #include <vcl/svapp.hxx> -//#include <transex3/vosapp.hxx> // This works and was used before for standalone test, not sure why // we'd want it. @@ -38,29 +37,41 @@ #include "uno.hxx" #include <cstdio> -#include <osl/file.h> +#include <cstdlib> +#include <sys/stat.h> -#include <rtl/ustring.hxx> +#include <com/sun/star/xml/sax/SAXException.hpp> +#include <comphelper/processfactory.hxx> #include <cppuhelper/bootstrap.hxx> - -#include <ucbhelper/contentbroker.hxx> +#include <rtl/ustring.hxx> #include <ucbhelper/configurationkeys.hxx> +#include <ucbhelper/contentbroker.hxx> -#include <comphelper/processfactory.hxx> -#include <com/sun/star/xml/sax/SAXException.hpp> +#define SORT_DLG 1 /* requires sfx2, svx to be compiled */ +#if SORT_DLG +#include "scitems.hxx" +#include "uiitems.hxx" +#endif /* SORT_DLG */ #include "editor.hxx" -#include "wordcountdialog.hxx" +#include "plugin.hxx" #undef _LAYOUT_POST_HXX -#include "zoom.hxx" +#include "recover.hxx" #undef _LAYOUT_POST_HXX -#include "recover.hxx" +#if SORT_DLG +#include "sortdlg.hxx" +#undef _LAYOUT_POST_HXX +#endif /* SORT_DLG */ + +#include "wordcountdialog.hxx" +#undef _LAYOUT_POST_HXX + +#include "zoom.hxx" #undef _LAYOUT_POST_HXX -//#undef SW_WORDCOUNTDIALOG_HXX #include <layout/layout-pre.hxx> using namespace ::rtl; @@ -68,38 +79,6 @@ using namespace ::cppu; using namespace ::com::sun::star; using namespace ::com::sun::star::uno; -Reference< XComponentContext > createInitialComponentContext( - OUString const & inst_dir ) -{ - Reference< XComponentContext > xContext; - - try - { - OUString file_url; - oslFileError rc = osl_getFileURLFromSystemPath( - inst_dir.pData, &file_url.pData ); - OSL_ASSERT( osl_File_E_None == rc ); - (void) rc; // quiet warning - - OUString unorc = file_url + OUString( - OUString::createFromAscii( "/program/" SAL_CONFIGFILE( "uno" )) ); - - return defaultBootstrap_InitialComponentContext( unorc ); - } - - catch( Exception& rExc ) - { - OString aStr( OUStringToOString( rExc.Message, - RTL_TEXTENCODING_ASCII_US ) ); - OSL_ENSURE( 0, aStr.getStr() ); - } - - return xContext; -} - - -// ----------------------------------------------------------------------- - class LayoutTest : public Application { Reference< XComponentContext > mxContext; @@ -115,7 +94,7 @@ public: void RunEditor(); void RunFiles(); void ExceptionalMain(); - void IInit(); + void Init(); void InitUCB(); void LoadFile( OUString const &aName ); void Main(); @@ -124,18 +103,29 @@ public: static void usage() { - fprintf (stderr, "usage: test [--inst inst_dir] [DIALOG.XML]... | --test [DIALOG.XML]\n" ); + fprintf (stderr, "usage: test [--inst OOO_INSTALL_PREFIX] [DIALOG.XML]... | --test [DIALOG.XML]\n" ); exit( 2 ); } +static uno::Reference< lang::XSingleServiceFactory > get_factory( char const *service ) +{ + uno::Reference< lang::XSingleServiceFactory > xFactory( + comphelper::createProcessComponent( + rtl::OUString::createFromAscii( service ) ), uno::UNO_QUERY ); + + if ( !xFactory.is() ) + fprintf( stderr, "error loading: %s\n", service ); + return xFactory; +} + +#define GET_FACTORY(x) get_factory( #x ) + void LayoutTest::LoadFile( const OUString &aTestFile ) { fprintf( stderr, "TEST: layout instance\n" ); - uno::Reference< lang::XSingleServiceFactory > xFactory( - comphelper::createProcessComponent( - rtl::OUString::createFromAscii( "com.sun.star.awt.Layout" ) ), - uno::UNO_QUERY ); + uno::Reference< lang::XSingleServiceFactory > xFactory + = GET_FACTORY( com.sun.star.awt.Layout ); if ( !xFactory.is() ) { fprintf( stderr, "Layout engine not installed\n" ); @@ -155,40 +145,51 @@ void LayoutTest::LoadFile( const OUString &aTestFile ) fprintf( stderr, "TEST: file loaded\n" ); } -// Nurgh ... void LayoutTest::InitUCB() { OUString aEmpty; - Sequence< Any > aArgs(6); + Sequence< Any > aArgs( 6 ); aArgs[0] - <<= OUString::createFromAscii(UCB_CONFIGURATION_KEY1_LOCAL); + <<= OUString::createFromAscii( UCB_CONFIGURATION_KEY1_LOCAL ); aArgs[1] - <<= OUString::createFromAscii(UCB_CONFIGURATION_KEY2_OFFICE); + <<= OUString::createFromAscii( UCB_CONFIGURATION_KEY2_OFFICE ); aArgs[2] <<= OUString::createFromAscii( "PIPE" ); aArgs[3] <<= aEmpty; aArgs[4] <<= OUString::createFromAscii( "PORTAL" ); aArgs[5] <<= aEmpty; - if (! ::ucbhelper::ContentBroker::initialize( mxMSF, aArgs ) ) + if ( !::ucbhelper::ContentBroker::initialize( mxMSF, aArgs ) ) + { fprintf( stderr, "Failed to init content broker\n" ); + fprintf( stderr, "arg[0]: %s\n", UCB_CONFIGURATION_KEY1_LOCAL ); + fprintf( stderr, "arg[1]: %s\n", UCB_CONFIGURATION_KEY2_OFFICE ); + } +} + +static void support_upstream_brand_prefix () +{ + if ( char const* inst = getenv( "OOO_INSTALL_PREFIX" ) ) + { + char const *brand_prefix = "/openoffice.org3"; + OUString brand_dir = OUString::createFromAscii( inst ) + + OUString::createFromAscii( brand_prefix ); + struct stat stat_info; + if ( !stat ( OUSTRING_CSTR( brand_dir ), &stat_info ) ) + { + OSL_TRACE( "Appending %s to OOO_INSTALL_PREFIX", brand_prefix ); + setenv( "OOO_INSTALL_PREFIX", OUSTRING_CSTR( brand_dir ), 1 ); + } + } } -#define INIT_ENV_VOODOO( installDir ) \ - /* Unless you do this, obviously you don't deserve to have anything work */ \ - OString aCfg = "CFG_INIFILE=file://" \ - + OUStringToOString( installDir, RTL_TEXTENCODING_UTF8 ) \ - + "/program/configmgrrc"; \ - putenv( (char *)aCfg.getStr() ); \ - /* Unless you do this, obviously you don't want your paths to be correct & \ - hence no images.zip location is possible. */ \ - OString aBaseInst = "BaseInstallation=file://" \ - + OUStringToOString( installDir, RTL_TEXTENCODING_UTF8 ); \ - putenv( (char *)aBaseInst.getStr() ); \ - -void LayoutTest::IInit() +void LayoutTest::Init() { - INIT_ENV_VOODOO( mInstallDir ); - mxContext = createInitialComponentContext( mInstallDir ); + ParseCommandLine(); + setenv( "OOO_INSTALL_PREFIX", OUSTRING_CSTR( mInstallDir ), 0 ); + support_upstream_brand_prefix (); + OSL_TRACE( "OOO_INSTALL_PREFIX=%s", getenv( "OOO_INSTALL_PREFIX" ) ); + + mxContext = defaultBootstrap_InitialComponentContext(); mxMSF = new UnoBootstrapLayout( Reference< lang::XMultiServiceFactory >( mxContext->getServiceManager(), UNO_QUERY ) ); ::comphelper::setProcessServiceFactory( mxMSF ); InitUCB(); @@ -196,6 +197,7 @@ void LayoutTest::IInit() void LayoutTest::ParseCommandLine() { + printf ("%s\n", __PRETTY_FUNCTION__); for ( sal_uInt16 i = 0; i < GetCommandLineParamCount(); i++ ) { OUString aParam = OUString( GetCommandLineParam( i ) ); @@ -206,6 +208,7 @@ void LayoutTest::ParseCommandLine() if ( i >= GetCommandLineParamCount() - 1) usage(); mInstallDir = GetCommandLineParam( ++i ); + setenv( "OOO_INSTALL_PREFIX", OUSTRING_CSTR( mInstallDir ), 1 ); } else if ( aParam.equalsAscii( "--test" ) ) { @@ -234,32 +237,77 @@ void LayoutTest::RunEditor() editor.Execute(); } -void RunDialog( layout::Dialog& dialog ) +short RunDialog( Dialog& dialog ) { dialog.Show(); - dialog.Execute(); - fprintf( stderr, "1st execute exited" ); - dialog.Execute(); - fprintf( stderr, "2nd execute exited" ); + short result = dialog.Execute(); + fprintf( stderr, "Done: dialog execute exited:%d\n", result); + return result; } +#undef Dialog +short RunDialog( ::Dialog& dialog ) +{ + dialog.Show(); + short result = dialog.Execute(); + fprintf( stderr, "Done: dialog execute exited:%d\n", result); + return result; +} + +#if SORT_DLG +static void LoadSC() +{ + get_factory( "com.sun.star.comp.sfx2.DocumentTemplates" ); + get_factory( "com.sun.star.comp.Calc.SpreadsheetDocument" ); + GET_FACTORY( com.sun.star.i18n.Transliteration.l10n ); +} +#endif /* SORT_DLG */ + void TestDialog( OUString const& name ) { - if ( name.equalsAscii( "zoom" ) ) + if ( 0 ) + ; + else if ( name.equalsAscii( "plugin" ) ) { - SvxZoomDialog zoom( 0 ); - RunDialog( zoom ); + PluginDialog plugin ( 0 ); + RunDialog( plugin ); } - else if ( name.equalsAscii( "wordcount" ) ) + else if ( name.equalsAscii( "query" ) ) { - SwWordCountDialog words ( 0 ); - RunDialog( words ); + QueryBox query ( 0, "Do you want to do?", "do"); + RunDialog( query ); + } + else if ( name.equalsAscii( "query-compat" ) ) + { + QueryBox query ( 0, + WinBits( WB_YES_NO | WB_DEF_YES ), +// WinBits( WB_ABORT_RETRY_IGNORE ), + OUString::createFromAscii ("Do you want to do?")); + RunDialog( query ); } else if ( name.equalsAscii( "recover" ) ) { SvxRecoverDialog recover ( 0 ); RunDialog( recover ); } +#if SORT_DLG + else if ( name.equalsAscii( "sort" ) ) + { + LoadSC(); + ScSortDlg sort (0, 0); + RunDialog( sort ); + } +#endif /* SORT_DLG */ + else if ( name.equalsAscii( "wordcount" ) ) + { + SwWordCountDialog words ( 0 ); + RunDialog( words ); + } + else if ( name.equalsAscii( "zoom" ) ) + { + SvxZoomDialog zoom( 0 ); + RunDialog( zoom ); + } } void LayoutTest::RunFiles() @@ -274,10 +322,6 @@ void LayoutTest::RunFiles() void LayoutTest::ExceptionalMain() { - ParseCommandLine(); - IInit(); - INIT_ENV_VOODOO( mInstallDir ); - if ( mTestDialog.getLength() ) TestDialog( mTestDialog ); else if ( mEditMode ) @@ -323,4 +367,4 @@ LayoutTest::LayoutTest( char const* installDir ) { } -LayoutTest lt( "/usr/local/lib/ooo" ); +LayoutTest layout_test( "/usr/local/lib/ooo" ); |