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