LCOV - code coverage report
Current view: top level - smoketest - smoketest.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 68 0.0 %
Date: 2012-08-25 Functions: 0 24 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*
       3                 :            :  * This file is part of the LibreOffice project.
       4                 :            :  *
       5                 :            :  * This Source Code Form is subject to the terms of the Mozilla Public
       6                 :            :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7                 :            :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8                 :            :  *
       9                 :            :  * This file incorporates work covered by the following license notice:
      10                 :            :  *
      11                 :            :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12                 :            :  *   contributor license agreements. See the NOTICE file distributed
      13                 :            :  *   with this work for additional information regarding copyright
      14                 :            :  *   ownership. The ASF licenses this file to you under the Apache
      15                 :            :  *   License, Version 2.0 (the "License"); you may not use this file
      16                 :            :  *   except in compliance with the License. You may obtain a copy of
      17                 :            :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18                 :            :  */
      19                 :            : 
      20                 :            : #include <sal/types.h>
      21                 :            : #include "boost/noncopyable.hpp"
      22                 :            : #include "com/sun/star/awt/AsyncCallback.hpp"
      23                 :            : #include "com/sun/star/awt/XCallback.hpp"
      24                 :            : #include "com/sun/star/beans/PropertyState.hpp"
      25                 :            : #include "com/sun/star/beans/PropertyValue.hpp"
      26                 :            : #include "com/sun/star/document/MacroExecMode.hpp"
      27                 :            : #include "com/sun/star/frame/DispatchResultEvent.hpp"
      28                 :            : #include "com/sun/star/frame/DispatchResultState.hpp"
      29                 :            : #include "com/sun/star/frame/XComponentLoader.hpp"
      30                 :            : #include "com/sun/star/frame/XController.hpp"
      31                 :            : #include "com/sun/star/frame/XDispatchProvider.hpp"
      32                 :            : #include "com/sun/star/frame/XDispatchResultListener.hpp"
      33                 :            : #include "com/sun/star/frame/XModel.hpp"
      34                 :            : #include "com/sun/star/frame/XNotifyingDispatch.hpp"
      35                 :            : #include "com/sun/star/lang/EventObject.hpp"
      36                 :            : #include "com/sun/star/uno/Any.hxx"
      37                 :            : #include "com/sun/star/uno/Reference.hxx"
      38                 :            : #include "com/sun/star/uno/RuntimeException.hpp"
      39                 :            : #include "com/sun/star/uno/Sequence.hxx"
      40                 :            : #include "com/sun/star/util/URL.hpp"
      41                 :            : #include "cppuhelper/implbase1.hxx"
      42                 :            : #include "cppunit/TestAssert.h"
      43                 :            : #include "cppunit/TestFixture.h"
      44                 :            : #include "cppunit/extensions/HelperMacros.h"
      45                 :            : #include "cppunit/plugin/TestPlugIn.h"
      46                 :            : #include "osl/conditn.hxx"
      47                 :            : #include "osl/diagnose.h"
      48                 :            : #include "osl/time.h"
      49                 :            : #include "rtl/oustringostreaminserter.hxx"
      50                 :            : #include "rtl/ustring.h"
      51                 :            : #include "rtl/ustring.hxx"
      52                 :            : #include "unotest/gettestargument.hxx"
      53                 :            : #include "unotest/officeconnection.hxx"
      54                 :            : #include "unotest/toabsolutefileurl.hxx"
      55                 :            : 
      56                 :            : namespace {
      57                 :            : 
      58                 :            : namespace css = com::sun::star;
      59                 :            : 
      60                 :          0 : struct Result: private boost::noncopyable {
      61                 :            :     osl::Condition condition;
      62                 :            :     bool success;
      63                 :            :     rtl::OUString result;
      64                 :            : };
      65                 :            : 
      66                 :          0 : class Listener:
      67                 :            :     public cppu::WeakImplHelper1< css::frame::XDispatchResultListener >
      68                 :            : {
      69                 :            : public:
      70                 :          0 :     Listener(Result * result): result_(result) { OSL_ASSERT(result != 0); }
      71                 :            : 
      72                 :            : private:
      73                 :          0 :     virtual void SAL_CALL disposing(css::lang::EventObject const &)
      74                 :          0 :         throw (css::uno::RuntimeException) {}
      75                 :            : 
      76                 :            :     virtual void SAL_CALL dispatchFinished(
      77                 :            :         css::frame::DispatchResultEvent const & Result)
      78                 :            :         throw (css::uno::RuntimeException);
      79                 :            : 
      80                 :            :     Result * result_;
      81                 :            : };
      82                 :            : 
      83                 :          0 : void Listener::dispatchFinished(css::frame::DispatchResultEvent const & Result)
      84                 :            :     throw (css::uno::RuntimeException)
      85                 :            : {
      86                 :            :     result_->success =
      87                 :            :         (Result.State == css::frame::DispatchResultState::SUCCESS) &&
      88                 :          0 :         (Result.Result >>= result_->result);
      89                 :          0 :     result_->condition.set();
      90                 :          0 : }
      91                 :            : 
      92                 :          0 : class Callback: public cppu::WeakImplHelper1< css::awt::XCallback > {
      93                 :            : public:
      94                 :          0 :     Callback(
      95                 :            :         css::uno::Reference< css::frame::XNotifyingDispatch > const & dispatch,
      96                 :            :         css::util::URL const & url,
      97                 :            :         css::uno::Sequence< css::beans::PropertyValue > const & arguments,
      98                 :            :         css::uno::Reference< css::frame::XDispatchResultListener > const &
      99                 :            :             listener):
     100                 :            :         dispatch_(dispatch), url_(url), arguments_(arguments),
     101                 :          0 :         listener_(listener)
     102                 :          0 :     { OSL_ASSERT(dispatch.is()); }
     103                 :            : 
     104                 :            : private:
     105                 :          0 :     virtual void SAL_CALL notify(css::uno::Any const &)
     106                 :            :         throw (css::uno::RuntimeException)
     107                 :          0 :     { dispatch_->dispatchWithNotification(url_, arguments_, listener_); }
     108                 :            : 
     109                 :            :     css::uno::Reference< css::frame::XNotifyingDispatch > dispatch_;
     110                 :            :     css::util::URL url_;
     111                 :            :     css::uno::Sequence< css::beans::PropertyValue > arguments_;
     112                 :            :     css::uno::Reference< css::frame::XDispatchResultListener > listener_;
     113                 :            : };
     114                 :            : 
     115                 :          0 : class Test: public CppUnit::TestFixture {
     116                 :            : public:
     117                 :            :     virtual void setUp();
     118                 :            : 
     119                 :            :     virtual void tearDown();
     120                 :            : 
     121                 :            : private:
     122                 :          0 :     CPPUNIT_TEST_SUITE(Test);
     123                 :          0 :     CPPUNIT_TEST(test);
     124                 :          0 :     CPPUNIT_TEST_SUITE_END();
     125                 :            : 
     126                 :            :     void test();
     127                 :            : 
     128                 :            :     test::OfficeConnection connection_;
     129                 :            : };
     130                 :            : 
     131                 :          0 : void Test::setUp() {
     132                 :          0 :     connection_.setUp();
     133                 :          0 : }
     134                 :            : 
     135                 :          0 : void Test::tearDown() {
     136                 :          0 :     connection_.tearDown();
     137                 :          0 : }
     138                 :            : 
     139                 :          0 : void Test::test() {
     140                 :          0 :     rtl::OUString doc;
     141                 :          0 :     CPPUNIT_ASSERT(
     142                 :            :         test::getTestArgument(
     143                 :          0 :             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("smoketest.doc")), &doc));
     144                 :          0 :     css::uno::Sequence< css::beans::PropertyValue > args(2);
     145                 :          0 :     args[0].Name = rtl::OUString(
     146                 :          0 :         RTL_CONSTASCII_USTRINGPARAM("MacroExecutionMode"));
     147                 :          0 :     args[0].Handle = -1;
     148                 :          0 :     args[0].Value <<=
     149                 :          0 :         com::sun::star::document::MacroExecMode::ALWAYS_EXECUTE_NO_WARN;
     150                 :          0 :     args[0].State = css::beans::PropertyState_DIRECT_VALUE;
     151                 :          0 :     args[1].Name = rtl::OUString(
     152                 :          0 :         RTL_CONSTASCII_USTRINGPARAM("ReadOnly"));
     153                 :          0 :     args[1].Handle = -1;
     154                 :          0 :     args[1].Value <<= sal_True;
     155                 :          0 :     args[1].State = css::beans::PropertyState_DIRECT_VALUE;
     156                 :          0 :     css::util::URL url;
     157                 :            :     url.Complete = rtl::OUString(
     158                 :            :         RTL_CONSTASCII_USTRINGPARAM(
     159                 :            :             "vnd.sun.star.script:Standard.Global.StartTestWithDefaultOptions?"
     160                 :          0 :             "language=Basic&location=document"));
     161                 :            :     css::uno::Reference< css::frame::XNotifyingDispatch > disp(
     162                 :            :         css::uno::Reference< css::frame::XDispatchProvider >(
     163                 :            :             css::uno::Reference< css::frame::XController >(
     164                 :            :                 css::uno::Reference< css::frame::XModel >(
     165                 :            :                     css::uno::Reference< css::frame::XComponentLoader >(
     166                 :          0 :                         (connection_.getComponentContext()->
     167                 :          0 :                          getServiceManager()->createInstanceWithContext(
     168                 :            :                              rtl::OUString(
     169                 :            :                                  RTL_CONSTASCII_USTRINGPARAM(
     170                 :            :                                      "com.sun.star.frame.Desktop")),
     171                 :          0 :                              connection_.getComponentContext())),
     172                 :          0 :                         css::uno::UNO_QUERY_THROW)->loadComponentFromURL(
     173                 :            :                             test::toAbsoluteFileUrl(doc),
     174                 :            :                             rtl::OUString(
     175                 :            :                                 RTL_CONSTASCII_USTRINGPARAM("_default")),
     176                 :          0 :                             0, args),
     177                 :          0 :                     css::uno::UNO_QUERY_THROW)->getCurrentController(),
     178                 :          0 :                 css::uno::UNO_SET_THROW)->getFrame(),
     179                 :          0 :             css::uno::UNO_QUERY_THROW)->queryDispatch(
     180                 :          0 :                 url, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("_self")), 0),
     181                 :          0 :         css::uno::UNO_QUERY_THROW);
     182                 :          0 :     Result result;
     183                 :            :     // Shifted to main thread to work around potential deadlocks (i112867):
     184                 :            :     com::sun::star::awt::AsyncCallback::create(
     185                 :          0 :         connection_.getComponentContext())->addCallback(
     186                 :            :             new Callback(
     187                 :            :                 disp, url, css::uno::Sequence< css::beans::PropertyValue >(),
     188                 :          0 :                 new Listener(&result)),
     189                 :          0 :             css::uno::Any());
     190                 :            :     // Wait for result.condition or connection_ going stale:
     191                 :          0 :     for (;;) {
     192                 :          0 :         TimeValue delay = { 1, 0 }; // 1 sec
     193                 :          0 :         osl::Condition::Result res = result.condition.wait(&delay);
     194                 :          0 :         if (res == osl::Condition::result_ok) {
     195                 :            :             break;
     196                 :            :         }
     197                 :          0 :         CPPUNIT_ASSERT_EQUAL(osl::Condition::result_timeout, res);
     198                 :          0 :         CPPUNIT_ASSERT(connection_.isStillAlive());
     199                 :            :     }
     200                 :          0 :     CPPUNIT_ASSERT(result.success);
     201                 :          0 :     CPPUNIT_ASSERT_EQUAL(rtl::OUString(), result.result);
     202                 :          0 : }
     203                 :            : 
     204                 :          0 : CPPUNIT_TEST_SUITE_REGISTRATION(Test);
     205                 :            : 
     206                 :            : }
     207                 :            : 
     208                 :          0 : CPPUNIT_PLUGIN_IMPLEMENT();
     209                 :            : 
     210                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10