LCOV - code coverage report
Current view: top level - basic/source/runtime - sbdiagnose.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 4 5 80.0 %
Date: 2012-08-25 Functions: 3 3 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 3 6 50.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                 :            : 
      21                 :            : #include "rtlproto.hxx"
      22                 :            : #include "sbdiagnose.hxx"
      23                 :            : 
      24                 :            : #include "basic/sbstar.hxx"
      25                 :            : 
      26                 :            : #include <tools/debug.hxx>
      27                 :            : #include <comphelper/flagguard.hxx>
      28                 :            : 
      29                 :            : #ifdef DBG_UTIL
      30                 :            : 
      31                 :            : static DbgChannelId nRestoreChannelId = 0;
      32                 :            : static DbgChannelId nAssertionChannelId = 0;
      33                 :            : static StarBASICRef xAssertionChannelBasic;
      34                 :            : static String sCaptureFunctionName;
      35                 :            : static bool bReportingAssertion = false;
      36                 :            : 
      37                 :            : void ResetCapturedAssertions()
      38                 :            : {
      39                 :            :     if ( nRestoreChannelId != 0 )
      40                 :            :     {
      41                 :            :         DBG_INSTOUTERROR( nRestoreChannelId );
      42                 :            :     }
      43                 :            :     nRestoreChannelId = 0;
      44                 :            :     xAssertionChannelBasic = NULL;
      45                 :            :     sCaptureFunctionName = String();
      46                 :            :     bReportingAssertion = false;
      47                 :            : }
      48                 :            : 
      49                 :            : void DbgReportAssertion( const sal_Char* i_assertionMessage )
      50                 :            : {
      51                 :            :     if ( !xAssertionChannelBasic )
      52                 :            :     {
      53                 :            :         ResetCapturedAssertions();
      54                 :            :         return;
      55                 :            :     }
      56                 :            : 
      57                 :            :     // prevent infinite recursion
      58                 :            :     if ( bReportingAssertion )
      59                 :            :         return;
      60                 :            :     ::comphelper::FlagRestorationGuard aGuard( bReportingAssertion, true );
      61                 :            : 
      62                 :            :     SbxArrayRef const xArguments( new SbxArray( SbxVARIANT ) );
      63                 :            :     SbxVariableRef const xMessageText = new SbxVariable( SbxSTRING );
      64                 :            :     xMessageText->PutString( rtl::OUString::createFromAscii(i_assertionMessage) );
      65                 :            :     xArguments->Put( xMessageText, 1 );
      66                 :            : 
      67                 :            :     ErrCode const nError = xAssertionChannelBasic->Call( sCaptureFunctionName, xArguments );
      68                 :            :     if ( ( nError & SbERR_METHOD_NOT_FOUND ) != 0 )
      69                 :            :         ResetCapturedAssertions();
      70                 :            : }
      71                 :            : 
      72                 :            : #endif
      73                 :            : 
      74                 :            : /// capture assertions, route them to the given given Basic function
      75                 :          4 : RTLFUNC(CaptureAssertions)
      76                 :            : {
      77                 :            :     (void)bWrite;
      78                 :            : 
      79                 :            :     // need exactly one argument
      80         [ -  + ]:          4 :     if ( rPar.Count() != 2 )
      81                 :            :     {
      82                 :          0 :         StarBASIC::Error( SbERR_BAD_ARGUMENT );
      83                 :          4 :         return;
      84                 :            :     }
      85                 :            : 
      86                 :            : #ifdef DBG_UTIL
      87                 :            :     DBG_TESTSOLARMUTEX();
      88                 :            : 
      89                 :            :     String const sFunctionName = rPar.Get(1)->GetString();
      90                 :            :     if ( sFunctionName.Len() == 0 )
      91                 :            :     {
      92                 :            :         ResetCapturedAssertions();
      93                 :            :         return;
      94                 :            :     }
      95                 :            : 
      96                 :            :     if ( nAssertionChannelId == 0 )
      97                 :            :     {
      98                 :            :         // TODO: should we register a named channel at the VCL API, instead of an unnamed channel at the tools API?
      99                 :            :         // A named channel would mean it would appear in the nonpro-debug-options dialog
     100                 :            :         nAssertionChannelId = DbgRegisterUserChannel( &DbgReportAssertion );
     101                 :            :     }
     102                 :            : 
     103                 :            :     DbgChannelId const nCurrentChannelId = (DbgChannelId)DbgGetErrorOut();
     104                 :            :     if ( nCurrentChannelId != nAssertionChannelId )
     105                 :            :     {
     106                 :            :         // remember the current channel
     107                 :            :         nRestoreChannelId = nCurrentChannelId;
     108                 :            : 
     109                 :            :         // set the new channel
     110                 :            :         DBG_INSTOUTERROR( nAssertionChannelId );
     111                 :            : 
     112                 :            :         // ensure OSL assertions are captured, too
     113                 :            :         DbgData aData( *DbgGetData() );
     114                 :            :         aData.bHookOSLAssert = sal_True;
     115                 :            :         DbgUpdateOslHook( &aData );
     116                 :            :     }
     117                 :            : 
     118                 :            :     xAssertionChannelBasic = pBasic;
     119                 :            :     sCaptureFunctionName = sFunctionName;
     120                 :            : #else
     121                 :            :     (void)pBasic;
     122                 :            :     (void)rPar;
     123                 :            :     (void)bWrite;
     124                 :            : #endif
     125 [ +  - ][ +  - ]:        771 : }
     126                 :            : 
     127                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10