LCOV - code coverage report
Current view: top level - basic/source/sbx - sbxbool.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 14 88 15.9 %
Date: 2014-11-03 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          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 <tools/errcode.hxx>
      21             : #include <basic/sbx.hxx>
      22             : #include "sbxconv.hxx"
      23             : #include "sbxres.hxx"
      24             : 
      25        5594 : enum SbxBOOL ImpGetBool( const SbxValues* p )
      26             : {
      27             :     enum SbxBOOL nRes;
      28        5594 :     switch( +p->eType )
      29             :     {
      30             :         case SbxNULL:
      31           0 :             SbxBase::SetError( SbxERR_CONVERSION );
      32             :         case SbxEMPTY:
      33           0 :             nRes = SbxFALSE; break;
      34             :         case SbxCHAR:
      35           0 :             nRes = p->nChar ? SbxTRUE : SbxFALSE; break;
      36             :         case SbxBYTE:
      37           0 :             nRes = p->nByte ? SbxTRUE : SbxFALSE; break;
      38             :         case SbxINTEGER:
      39             :         case SbxBOOL:
      40        5414 :             nRes = p->nInteger ? SbxTRUE : SbxFALSE; break;
      41             :         case SbxERROR:
      42             :         case SbxUSHORT:
      43           0 :             nRes = p->nUShort ? SbxTRUE : SbxFALSE; break;
      44             :         case SbxLONG:
      45         180 :             nRes = p->nLong ? SbxTRUE : SbxFALSE; break;
      46             :         case SbxULONG:
      47           0 :             nRes = p->nULong ? SbxTRUE : SbxFALSE; break;
      48             :         case SbxSINGLE:
      49           0 :             nRes = p->nSingle ? SbxTRUE : SbxFALSE; break;
      50             :         case SbxDATE:
      51             :         case SbxDOUBLE:
      52           0 :             nRes = p->nDouble ? SbxTRUE : SbxFALSE; break;
      53             :         case SbxDECIMAL:
      54             :         case SbxBYREF | SbxDECIMAL:
      55             :             {
      56           0 :             double dVal = 0.0;
      57           0 :             if( p->pDecimal )
      58           0 :                 p->pDecimal->getDouble( dVal );
      59           0 :             nRes = dVal ? SbxTRUE : SbxFALSE;
      60             :             }
      61           0 :             break;
      62             :         case SbxSALINT64:
      63             :         case SbxCURRENCY:
      64           0 :             nRes = p->nInt64 ? SbxTRUE : SbxFALSE; break;
      65             :         case SbxSALUINT64:
      66           0 :             nRes = p->uInt64 ? SbxTRUE : SbxFALSE; break;
      67             :         case SbxBYREF | SbxSTRING:
      68             :         case SbxSTRING:
      69             :         case SbxLPSTR:
      70           0 :             nRes = SbxFALSE;
      71           0 :             if ( p->pOUString )
      72             :             {
      73           0 :                 if( p->pOUString->equalsIgnoreAsciiCase( SbxRes( STRING_TRUE ) ) )
      74           0 :                     nRes = SbxTRUE;
      75           0 :                 else if( !p->pOUString->equalsIgnoreAsciiCase( SbxRes( STRING_FALSE ) ) )
      76             :                 {
      77             :                     // it can be convertible to a number
      78           0 :                     bool bError = true;
      79             :                     double n;
      80             :                     SbxDataType t;
      81           0 :                     sal_uInt16 nLen = 0;
      82           0 :                     if( ImpScan( *p->pOUString, n, t, &nLen ) == SbxERR_OK )
      83             :                     {
      84           0 :                         if( nLen == p->pOUString->getLength() )
      85             :                         {
      86           0 :                             bError = false;
      87           0 :                             if( n != 0.0 )
      88           0 :                                 nRes = SbxTRUE;
      89             :                         }
      90             :                     }
      91           0 :                     if( bError )
      92           0 :                         SbxBase::SetError( SbxERR_CONVERSION );
      93             :                 }
      94             :             }
      95           0 :             break;
      96             :         case SbxOBJECT:
      97             :         {
      98           0 :             SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
      99           0 :             if( pVal )
     100           0 :                 nRes = pVal->GetBool() ? SbxTRUE : SbxFALSE;
     101             :             else
     102             :             {
     103           0 :                 SbxBase::SetError( SbxERR_NO_OBJECT ); nRes = SbxFALSE;
     104             :             }
     105           0 :             break;
     106             :         }
     107             : 
     108             :         case SbxBYREF | SbxCHAR:
     109           0 :             nRes = *p->pChar ? SbxTRUE : SbxFALSE; break;
     110             :         case SbxBYREF | SbxBYTE:
     111           0 :             nRes = *p->pByte ? SbxTRUE : SbxFALSE; break;
     112             :         case SbxBYREF | SbxINTEGER:
     113             :         case SbxBYREF | SbxBOOL:
     114           0 :             nRes = *p->pInteger ? SbxTRUE : SbxFALSE; break;
     115             :         case SbxBYREF | SbxLONG:
     116           0 :             nRes = *p->pLong ? SbxTRUE : SbxFALSE; break;
     117             :         case SbxBYREF | SbxULONG:
     118           0 :             nRes = *p->pULong ? SbxTRUE : SbxFALSE; break;
     119             :         case SbxBYREF | SbxERROR:
     120             :         case SbxBYREF | SbxUSHORT:
     121           0 :             nRes = *p->pUShort ? SbxTRUE : SbxFALSE; break;
     122             :         case SbxBYREF | SbxSINGLE:
     123           0 :             nRes = ( *p->pSingle != 0 ) ? SbxTRUE : SbxFALSE; break;
     124             :         case SbxBYREF | SbxDATE:
     125             :         case SbxBYREF | SbxDOUBLE:
     126           0 :             nRes = ( *p->pDouble != 0 ) ? SbxTRUE : SbxFALSE; break;
     127             :         case SbxBYREF | SbxCURRENCY:
     128             :         case SbxBYREF | SbxSALINT64:
     129           0 :             nRes = ( *p->pnInt64 ) ? SbxTRUE : SbxFALSE; break;
     130             :         case SbxBYREF | SbxSALUINT64:
     131           0 :             nRes = ( *p->puInt64 ) ? SbxTRUE : SbxFALSE; break;
     132             :         default:
     133           0 :             SbxBase::SetError( SbxERR_CONVERSION ); nRes = SbxFALSE;
     134             :     }
     135        5594 :     return nRes;
     136             : }
     137             : 
     138        8784 : void ImpPutBool( SbxValues* p, sal_Int16 n )
     139             : {
     140        8784 :     if( n )
     141        4006 :         n = SbxTRUE;
     142        8784 :     switch( +p->eType )
     143             :     {
     144             :         case SbxCHAR:
     145           0 :             p->nChar = (sal_Unicode) n; break;
     146             :         case SbxUINT:
     147           0 :             p->nByte = (sal_uInt8) n; break;
     148             :         case SbxINTEGER:
     149             :         case SbxBOOL:
     150        8564 :             p->nInteger = n; break;
     151             :         case SbxLONG:
     152           0 :             p->nLong = n; break;
     153             :         case SbxULONG:
     154           0 :             p->nULong = (sal_uInt32) n; break;
     155             :         case SbxERROR:
     156             :         case SbxUSHORT:
     157           0 :             p->nUShort = (sal_uInt16) n; break;
     158             :         case SbxSINGLE:
     159           0 :             p->nSingle = n; break;
     160             :         case SbxDATE:
     161             :         case SbxDOUBLE:
     162           0 :             p->nDouble = n; break;
     163             :         case SbxCURRENCY:
     164             :         case SbxSALINT64:
     165           0 :             p->nInt64 = (sal_Int64) n; break;
     166             :         case SbxSALUINT64:
     167           0 :             p->uInt64 = (sal_uInt64) n; break;
     168             :         case SbxDECIMAL:
     169             :         case SbxBYREF | SbxDECIMAL:
     170           0 :             ImpCreateDecimal( p )->setInt( (sal_Int16)n );
     171           0 :             break;
     172             : 
     173             :         case SbxBYREF | SbxSTRING:
     174             :         case SbxSTRING:
     175             :         case SbxLPSTR:
     176         220 :             if ( !p->pOUString )
     177           0 :                 p->pOUString = new OUString( SbxRes( n ? STRING_TRUE : STRING_FALSE ) );
     178             :             else
     179         220 :                 *p->pOUString = SbxRes( n ? STRING_TRUE : STRING_FALSE );
     180         220 :             break;
     181             : 
     182             :         case SbxOBJECT:
     183             :         {
     184           0 :             SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
     185           0 :             if( pVal )
     186           0 :                 pVal->PutBool( n != 0 );
     187             :             else
     188           0 :                 SbxBase::SetError( SbxERR_NO_OBJECT );
     189           0 :             break;
     190             :         }
     191             :         case SbxBYREF | SbxCHAR:
     192           0 :             *p->pChar = (sal_Unicode) n; break;
     193             :         case SbxBYREF | SbxBYTE:
     194           0 :             *p->pByte = (sal_uInt8) n; break;
     195             :         case SbxBYREF | SbxINTEGER:
     196             :         case SbxBYREF | SbxBOOL:
     197           0 :             *p->pInteger = (sal_Int16) n; break;
     198             :         case SbxBYREF | SbxERROR:
     199             :         case SbxBYREF | SbxUSHORT:
     200           0 :             *p->pUShort = (sal_uInt16) n; break;
     201             :         case SbxBYREF | SbxLONG:
     202           0 :             *p->pLong = n; break;
     203             :         case SbxBYREF | SbxULONG:
     204           0 :             *p->pULong = (sal_uInt32) n; break;
     205             :         case SbxBYREF | SbxSINGLE:
     206           0 :             *p->pSingle = n; break;
     207             :         case SbxBYREF | SbxDATE:
     208             :         case SbxBYREF | SbxDOUBLE:
     209           0 :             *p->pDouble = n; break;
     210             :         case SbxBYREF | SbxCURRENCY:
     211             :         case SbxBYREF | SbxSALINT64:
     212           0 :             *p->pnInt64 = (sal_Int64) n; break;
     213             :         case SbxBYREF | SbxSALUINT64:
     214           0 :             *p->puInt64 = (sal_uInt64) n; break;
     215             :         default:
     216           0 :             SbxBase::SetError( SbxERR_CONVERSION );
     217             :     }
     218        8784 : }
     219             : 
     220             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10