1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #include <vcl/svapp.hxx> 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir // This works and was used before for standalone test, not sure why 31*cdf0e10cSrcweir // we'd want it. 32*cdf0e10cSrcweir #define LAYOUT_WEAK 1 33*cdf0e10cSrcweir #include "uno.hxx" 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #include <cstdio> 36*cdf0e10cSrcweir #include <cstdlib> 37*cdf0e10cSrcweir #include <sys/stat.h> 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir #include <com/sun/star/xml/sax/SAXException.hpp> 40*cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 41*cdf0e10cSrcweir #include <cppuhelper/bootstrap.hxx> 42*cdf0e10cSrcweir #include <rtl/ustring.hxx> 43*cdf0e10cSrcweir #include <ucbhelper/configurationkeys.hxx> 44*cdf0e10cSrcweir #include <ucbhelper/contentbroker.hxx> 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir #define SORT_DLG 1 /* requires sfx2, svx to be compiled */ 47*cdf0e10cSrcweir #if SORT_DLG 48*cdf0e10cSrcweir #include "scitems.hxx" 49*cdf0e10cSrcweir #include "uiitems.hxx" 50*cdf0e10cSrcweir #endif /* SORT_DLG */ 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir #include "editor.hxx" 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir #include "plugin.hxx" 55*cdf0e10cSrcweir #undef _LAYOUT_POST_HXX 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir #include "recover.hxx" 58*cdf0e10cSrcweir #undef _LAYOUT_POST_HXX 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir #if SORT_DLG 61*cdf0e10cSrcweir #include "sortdlg.hxx" 62*cdf0e10cSrcweir #undef _LAYOUT_POST_HXX 63*cdf0e10cSrcweir #endif /* SORT_DLG */ 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir #include "wordcountdialog.hxx" 66*cdf0e10cSrcweir #undef _LAYOUT_POST_HXX 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir #include "zoom.hxx" 69*cdf0e10cSrcweir #undef _LAYOUT_POST_HXX 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir #include <layout/layout-pre.hxx> 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir using namespace ::rtl; 74*cdf0e10cSrcweir using namespace ::cppu; 75*cdf0e10cSrcweir using namespace ::com::sun::star; 76*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir class LayoutTest : public Application 79*cdf0e10cSrcweir { 80*cdf0e10cSrcweir Reference< XComponentContext > mxContext; 81*cdf0e10cSrcweir Reference< lang::XMultiServiceFactory > mxMSF; 82*cdf0e10cSrcweir OUString mInstallDir; 83*cdf0e10cSrcweir OUString mTestDialog; 84*cdf0e10cSrcweir bool mEditMode; 85*cdf0e10cSrcweir std::list< OUString > mFiles; 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir public: 88*cdf0e10cSrcweir LayoutTest( char const* installDir ); 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir void RunEditor(); 91*cdf0e10cSrcweir void RunFiles(); 92*cdf0e10cSrcweir void ExceptionalMain(); 93*cdf0e10cSrcweir void Init(); 94*cdf0e10cSrcweir void InitUCB(); 95*cdf0e10cSrcweir void LoadFile( OUString const &aName ); 96*cdf0e10cSrcweir void Main(); 97*cdf0e10cSrcweir void ParseCommandLine(); 98*cdf0e10cSrcweir }; 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir static void usage() 101*cdf0e10cSrcweir { 102*cdf0e10cSrcweir fprintf (stderr, "usage: test [--inst OOO_INSTALL_PREFIX] [DIALOG.XML]... | --test [DIALOG.XML]\n" ); 103*cdf0e10cSrcweir exit( 2 ); 104*cdf0e10cSrcweir } 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir static uno::Reference< lang::XSingleServiceFactory > get_factory( char const *service ) 107*cdf0e10cSrcweir { 108*cdf0e10cSrcweir uno::Reference< lang::XSingleServiceFactory > xFactory( 109*cdf0e10cSrcweir comphelper::createProcessComponent( 110*cdf0e10cSrcweir rtl::OUString::createFromAscii( service ) ), uno::UNO_QUERY ); 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir if ( !xFactory.is() ) 113*cdf0e10cSrcweir fprintf( stderr, "error loading: %s\n", service ); 114*cdf0e10cSrcweir return xFactory; 115*cdf0e10cSrcweir } 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir #define GET_FACTORY(x) get_factory( #x ) 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir void LayoutTest::LoadFile( const OUString &aTestFile ) 120*cdf0e10cSrcweir { 121*cdf0e10cSrcweir fprintf( stderr, "TEST: layout instance\n" ); 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir uno::Reference< lang::XSingleServiceFactory > xFactory 124*cdf0e10cSrcweir = GET_FACTORY( com.sun.star.awt.Layout ); 125*cdf0e10cSrcweir if ( !xFactory.is() ) 126*cdf0e10cSrcweir { 127*cdf0e10cSrcweir fprintf( stderr, "Layout engine not installed\n" ); 128*cdf0e10cSrcweir throw uno::RuntimeException( 129*cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Layout engine not installed" ) ), 130*cdf0e10cSrcweir uno::Reference< uno::XInterface >() ); 131*cdf0e10cSrcweir } 132*cdf0e10cSrcweir fprintf( stderr, "TEST: initing root\n" ); 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir uno::Sequence< uno::Any > aParams( 1 ); 135*cdf0e10cSrcweir aParams[0] <<= aTestFile; 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir uno::Reference< awt::XLayoutRoot > xRoot ( 138*cdf0e10cSrcweir xFactory->createInstanceWithArguments( aParams ), 139*cdf0e10cSrcweir uno::UNO_QUERY ); 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir fprintf( stderr, "TEST: file loaded\n" ); 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir void LayoutTest::InitUCB() 145*cdf0e10cSrcweir { 146*cdf0e10cSrcweir OUString aEmpty; 147*cdf0e10cSrcweir Sequence< Any > aArgs( 6 ); 148*cdf0e10cSrcweir aArgs[0] 149*cdf0e10cSrcweir <<= OUString::createFromAscii( UCB_CONFIGURATION_KEY1_LOCAL ); 150*cdf0e10cSrcweir aArgs[1] 151*cdf0e10cSrcweir <<= OUString::createFromAscii( UCB_CONFIGURATION_KEY2_OFFICE ); 152*cdf0e10cSrcweir aArgs[2] <<= OUString::createFromAscii( "PIPE" ); 153*cdf0e10cSrcweir aArgs[3] <<= aEmpty; 154*cdf0e10cSrcweir aArgs[4] <<= OUString::createFromAscii( "PORTAL" ); 155*cdf0e10cSrcweir aArgs[5] <<= aEmpty; 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir if ( !::ucbhelper::ContentBroker::initialize( mxMSF, aArgs ) ) 158*cdf0e10cSrcweir { 159*cdf0e10cSrcweir fprintf( stderr, "Failed to init content broker\n" ); 160*cdf0e10cSrcweir fprintf( stderr, "arg[0]: %s\n", UCB_CONFIGURATION_KEY1_LOCAL ); 161*cdf0e10cSrcweir fprintf( stderr, "arg[1]: %s\n", UCB_CONFIGURATION_KEY2_OFFICE ); 162*cdf0e10cSrcweir } 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir static void support_upstream_brand_prefix () 166*cdf0e10cSrcweir { 167*cdf0e10cSrcweir if ( char const* inst = getenv( "OOO_INSTALL_PREFIX" ) ) 168*cdf0e10cSrcweir { 169*cdf0e10cSrcweir char const *brand_prefix = "/openoffice.org3"; 170*cdf0e10cSrcweir OUString brand_dir = OUString::createFromAscii( inst ) 171*cdf0e10cSrcweir + OUString::createFromAscii( brand_prefix ); 172*cdf0e10cSrcweir struct stat stat_info; 173*cdf0e10cSrcweir if ( !stat ( OUSTRING_CSTR( brand_dir ), &stat_info ) ) 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir OSL_TRACE( "Appending %s to OOO_INSTALL_PREFIX", brand_prefix ); 176*cdf0e10cSrcweir setenv( "OOO_INSTALL_PREFIX", OUSTRING_CSTR( brand_dir ), 1 ); 177*cdf0e10cSrcweir } 178*cdf0e10cSrcweir } 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir void LayoutTest::Init() 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir ParseCommandLine(); 184*cdf0e10cSrcweir setenv( "OOO_INSTALL_PREFIX", OUSTRING_CSTR( mInstallDir ), 0 ); 185*cdf0e10cSrcweir support_upstream_brand_prefix (); 186*cdf0e10cSrcweir OSL_TRACE( "OOO_INSTALL_PREFIX=%s", getenv( "OOO_INSTALL_PREFIX" ) ); 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir mxContext = defaultBootstrap_InitialComponentContext(); 189*cdf0e10cSrcweir mxMSF = new UnoBootstrapLayout( Reference< lang::XMultiServiceFactory >( mxContext->getServiceManager(), UNO_QUERY ) ); 190*cdf0e10cSrcweir ::comphelper::setProcessServiceFactory( mxMSF ); 191*cdf0e10cSrcweir InitUCB(); 192*cdf0e10cSrcweir } 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir void LayoutTest::ParseCommandLine() 195*cdf0e10cSrcweir { 196*cdf0e10cSrcweir printf ("%s\n", __PRETTY_FUNCTION__); 197*cdf0e10cSrcweir for ( sal_uInt16 i = 0; i < GetCommandLineParamCount(); i++ ) 198*cdf0e10cSrcweir { 199*cdf0e10cSrcweir OUString aParam = OUString( GetCommandLineParam( i ) ); 200*cdf0e10cSrcweir if ( aParam.equalsAscii( "-h" ) || aParam.equalsAscii( "--help" ) ) 201*cdf0e10cSrcweir usage(); 202*cdf0e10cSrcweir if ( aParam.equalsAscii( "--inst" ) ) 203*cdf0e10cSrcweir { 204*cdf0e10cSrcweir if ( i >= GetCommandLineParamCount() - 1) 205*cdf0e10cSrcweir usage(); 206*cdf0e10cSrcweir mInstallDir = GetCommandLineParam( ++i ); 207*cdf0e10cSrcweir setenv( "OOO_INSTALL_PREFIX", OUSTRING_CSTR( mInstallDir ), 1 ); 208*cdf0e10cSrcweir } 209*cdf0e10cSrcweir else if ( aParam.equalsAscii( "--test" ) ) 210*cdf0e10cSrcweir { 211*cdf0e10cSrcweir mTestDialog = OUString::createFromAscii( "zoom" ); 212*cdf0e10cSrcweir if (i + 1 < GetCommandLineParamCount()) 213*cdf0e10cSrcweir mTestDialog = GetCommandLineParam( ++i ); 214*cdf0e10cSrcweir } 215*cdf0e10cSrcweir else if ( aParam.equalsAscii( "--editor" ) ) 216*cdf0e10cSrcweir mEditMode = true; 217*cdf0e10cSrcweir else 218*cdf0e10cSrcweir mFiles.push_back( aParam ); 219*cdf0e10cSrcweir } 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir if ( mFiles.size() <= 0 ) 222*cdf0e10cSrcweir mFiles.push_back( OUString::createFromAscii( "layout.xml" ) ); 223*cdf0e10cSrcweir } 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir void LayoutTest::RunEditor() 226*cdf0e10cSrcweir { 227*cdf0e10cSrcweir OUString aFile; 228*cdf0e10cSrcweir if ( !mFiles.empty() 229*cdf0e10cSrcweir && mFiles.front().compareToAscii( "layout.xml" ) != 0 ) 230*cdf0e10cSrcweir aFile = mFiles.front(); 231*cdf0e10cSrcweir Editor editor( mxMSF, aFile ); 232*cdf0e10cSrcweir editor.Show(); 233*cdf0e10cSrcweir editor.Execute(); 234*cdf0e10cSrcweir } 235*cdf0e10cSrcweir 236*cdf0e10cSrcweir short RunDialog( Dialog& dialog ) 237*cdf0e10cSrcweir { 238*cdf0e10cSrcweir dialog.Show(); 239*cdf0e10cSrcweir short result = dialog.Execute(); 240*cdf0e10cSrcweir fprintf( stderr, "Done: dialog execute exited:%d\n", result); 241*cdf0e10cSrcweir return result; 242*cdf0e10cSrcweir } 243*cdf0e10cSrcweir 244*cdf0e10cSrcweir #undef Dialog 245*cdf0e10cSrcweir short RunDialog( ::Dialog& dialog ) 246*cdf0e10cSrcweir { 247*cdf0e10cSrcweir dialog.Show(); 248*cdf0e10cSrcweir short result = dialog.Execute(); 249*cdf0e10cSrcweir fprintf( stderr, "Done: dialog execute exited:%d\n", result); 250*cdf0e10cSrcweir return result; 251*cdf0e10cSrcweir } 252*cdf0e10cSrcweir 253*cdf0e10cSrcweir #if SORT_DLG 254*cdf0e10cSrcweir static void LoadSC() 255*cdf0e10cSrcweir { 256*cdf0e10cSrcweir get_factory( "com.sun.star.comp.sfx2.DocumentTemplates" ); 257*cdf0e10cSrcweir get_factory( "com.sun.star.comp.Calc.SpreadsheetDocument" ); 258*cdf0e10cSrcweir GET_FACTORY( com.sun.star.i18n.Transliteration.l10n ); 259*cdf0e10cSrcweir } 260*cdf0e10cSrcweir #endif /* SORT_DLG */ 261*cdf0e10cSrcweir 262*cdf0e10cSrcweir void TestDialog( OUString const& name ) 263*cdf0e10cSrcweir { 264*cdf0e10cSrcweir if ( 0 ) 265*cdf0e10cSrcweir ; 266*cdf0e10cSrcweir else if ( name.equalsAscii( "plugin" ) ) 267*cdf0e10cSrcweir { 268*cdf0e10cSrcweir PluginDialog plugin ( 0 ); 269*cdf0e10cSrcweir RunDialog( plugin ); 270*cdf0e10cSrcweir } 271*cdf0e10cSrcweir else if ( name.equalsAscii( "query" ) ) 272*cdf0e10cSrcweir { 273*cdf0e10cSrcweir QueryBox query ( 0, "Do you want to do?", "do"); 274*cdf0e10cSrcweir RunDialog( query ); 275*cdf0e10cSrcweir } 276*cdf0e10cSrcweir else if ( name.equalsAscii( "query-compat" ) ) 277*cdf0e10cSrcweir { 278*cdf0e10cSrcweir QueryBox query ( 0, 279*cdf0e10cSrcweir WinBits( WB_YES_NO | WB_DEF_YES ), 280*cdf0e10cSrcweir // WinBits( WB_ABORT_RETRY_IGNORE ), 281*cdf0e10cSrcweir OUString::createFromAscii ("Do you want to do?")); 282*cdf0e10cSrcweir RunDialog( query ); 283*cdf0e10cSrcweir } 284*cdf0e10cSrcweir else if ( name.equalsAscii( "recover" ) ) 285*cdf0e10cSrcweir { 286*cdf0e10cSrcweir SvxRecoverDialog recover ( 0 ); 287*cdf0e10cSrcweir RunDialog( recover ); 288*cdf0e10cSrcweir } 289*cdf0e10cSrcweir #if SORT_DLG 290*cdf0e10cSrcweir else if ( name.equalsAscii( "sort" ) ) 291*cdf0e10cSrcweir { 292*cdf0e10cSrcweir LoadSC(); 293*cdf0e10cSrcweir ScSortDlg sort (0, 0); 294*cdf0e10cSrcweir RunDialog( sort ); 295*cdf0e10cSrcweir } 296*cdf0e10cSrcweir #endif /* SORT_DLG */ 297*cdf0e10cSrcweir else if ( name.equalsAscii( "wordcount" ) ) 298*cdf0e10cSrcweir { 299*cdf0e10cSrcweir SwWordCountDialog words ( 0 ); 300*cdf0e10cSrcweir RunDialog( words ); 301*cdf0e10cSrcweir } 302*cdf0e10cSrcweir else if ( name.equalsAscii( "zoom" ) ) 303*cdf0e10cSrcweir { 304*cdf0e10cSrcweir SvxZoomDialog zoom( 0 ); 305*cdf0e10cSrcweir RunDialog( zoom ); 306*cdf0e10cSrcweir } 307*cdf0e10cSrcweir } 308*cdf0e10cSrcweir 309*cdf0e10cSrcweir void LayoutTest::RunFiles() 310*cdf0e10cSrcweir { 311*cdf0e10cSrcweir fprintf( stderr, "TEST: loading files\n" ); 312*cdf0e10cSrcweir for ( std::list< OUString >::iterator i = mFiles.begin(); i != mFiles.end(); i++ ) 313*cdf0e10cSrcweir LoadFile( *i ); 314*cdf0e10cSrcweir fprintf( stderr, "TEST: executing\n" ); 315*cdf0e10cSrcweir Execute(); 316*cdf0e10cSrcweir fprintf( stderr, "TEST: done executing\n" ); 317*cdf0e10cSrcweir } 318*cdf0e10cSrcweir 319*cdf0e10cSrcweir void LayoutTest::ExceptionalMain() 320*cdf0e10cSrcweir { 321*cdf0e10cSrcweir if ( mTestDialog.getLength() ) 322*cdf0e10cSrcweir TestDialog( mTestDialog ); 323*cdf0e10cSrcweir else if ( mEditMode ) 324*cdf0e10cSrcweir RunEditor(); 325*cdf0e10cSrcweir else 326*cdf0e10cSrcweir RunFiles(); 327*cdf0e10cSrcweir } 328*cdf0e10cSrcweir 329*cdf0e10cSrcweir void LayoutTest::Main() 330*cdf0e10cSrcweir { 331*cdf0e10cSrcweir try 332*cdf0e10cSrcweir { 333*cdf0e10cSrcweir ExceptionalMain(); 334*cdf0e10cSrcweir } 335*cdf0e10cSrcweir catch (xml::sax::SAXException & rExc) 336*cdf0e10cSrcweir { 337*cdf0e10cSrcweir OString aStr( OUStringToOString( rExc.Message, 338*cdf0e10cSrcweir RTL_TEXTENCODING_ASCII_US ) ); 339*cdf0e10cSrcweir uno::Exception exc; 340*cdf0e10cSrcweir if (rExc.WrappedException >>= exc) 341*cdf0e10cSrcweir { 342*cdf0e10cSrcweir aStr += OString( " >>> " ); 343*cdf0e10cSrcweir aStr += OUStringToOString( exc.Message, RTL_TEXTENCODING_ASCII_US ); 344*cdf0e10cSrcweir } 345*cdf0e10cSrcweir fprintf (stderr, "Parsing error: '%s'\n", aStr.getStr()); 346*cdf0e10cSrcweir OSL_ENSURE( 0, aStr.getStr() ); 347*cdf0e10cSrcweir } 348*cdf0e10cSrcweir catch ( uno::Exception & rExc ) 349*cdf0e10cSrcweir { 350*cdf0e10cSrcweir OString aStr( OUStringToOString( rExc.Message, 351*cdf0e10cSrcweir RTL_TEXTENCODING_ASCII_US ) ); 352*cdf0e10cSrcweir fprintf (stderr, "UNO error: '%s'\n", aStr.getStr()); 353*cdf0e10cSrcweir OSL_ENSURE( 0, aStr.getStr() ); 354*cdf0e10cSrcweir } 355*cdf0e10cSrcweir 356*cdf0e10cSrcweir Reference< lang::XComponent > xComp( mxContext, UNO_QUERY ); 357*cdf0e10cSrcweir if ( xComp.is() ) 358*cdf0e10cSrcweir xComp->dispose(); 359*cdf0e10cSrcweir } 360*cdf0e10cSrcweir 361*cdf0e10cSrcweir LayoutTest::LayoutTest( char const* installDir ) 362*cdf0e10cSrcweir : mInstallDir( OUString::createFromAscii ( installDir ) ) 363*cdf0e10cSrcweir { 364*cdf0e10cSrcweir } 365*cdf0e10cSrcweir 366*cdf0e10cSrcweir LayoutTest layout_test( "/usr/local/lib/ooo" ); 367