LCOV - code coverage report
Current view: top level - basic/source/sbx - sbxdbl.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 33 130 25.4 %
Date: 2015-06-13 12:38:46 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 <config_features.h>
      21             : 
      22             : #include <tools/errcode.hxx>
      23             : #include <basic/sbx.hxx>
      24             : #include "sbxconv.hxx"
      25             : #include "runtime.hxx"
      26             : 
      27        9814 : double ImpGetDouble( const SbxValues* p )
      28             : {
      29             :     double nRes;
      30        9814 :     switch( +p->eType )
      31             :     {
      32             :         case SbxNULL:
      33           0 :             SbxBase::SetError( SbxERR_CONVERSION );
      34             :         case SbxEMPTY:
      35          12 :             nRes = 0; break;
      36             :         case SbxCHAR:
      37           0 :             nRes = p->nChar; break;
      38             :         case SbxBYTE:
      39           0 :             nRes = p->nByte; break;
      40             :         case SbxINTEGER:
      41             :         case SbxBOOL:
      42        6863 :             nRes = p->nInteger; break;
      43             :         case SbxERROR:
      44             :         case SbxUSHORT:
      45           0 :             nRes = p->nUShort; break;
      46             :         case SbxLONG:
      47         800 :             nRes = p->nLong; break;
      48             :         case SbxULONG:
      49           0 :             nRes = p->nULong; break;
      50             :         case SbxSINGLE:
      51          15 :             nRes = p->nSingle; break;
      52             :         case SbxDATE:
      53             :         case SbxDOUBLE:
      54        2091 :             nRes = p->nDouble; break;
      55             :         case SbxCURRENCY:
      56           3 :             nRes = ImpCurrencyToDouble( p->nInt64 ); break;
      57             :         case SbxSALINT64:
      58           0 :             nRes = static_cast< double >(p->nInt64); break;
      59             :         case SbxSALUINT64:
      60           0 :             nRes = ImpSalUInt64ToDouble( p->uInt64 ); break;
      61             :         case SbxDECIMAL:
      62             :         case SbxBYREF | SbxDECIMAL:
      63           0 :             if( p->pDecimal )
      64           0 :                 p->pDecimal->getDouble( nRes );
      65             :             else
      66           0 :                 nRes = 0.0;
      67           0 :             break;
      68             :         case SbxBYREF | SbxSTRING:
      69             :         case SbxSTRING:
      70             :         case SbxLPSTR:
      71          30 :             if( !p->pOUString )
      72             :             {
      73           6 :                 nRes = 0;
      74             : #if HAVE_FEATURE_SCRIPTING
      75           6 :                 if ( SbiRuntime::isVBAEnabled() )// VBA only behaviour
      76           6 :                     SbxBase::SetError( SbxERR_CONVERSION );
      77             : #endif
      78             :             }
      79             :             else
      80             :             {
      81             :                 double d;
      82             :                 SbxDataType t;
      83          24 :                 if( ImpScan( *p->pOUString, d, t, NULL ) != SbxERR_OK )
      84             :                 {
      85          10 :                     nRes = 0;
      86             : #if HAVE_FEATURE_SCRIPTING
      87          10 :                     if ( SbiRuntime::isVBAEnabled() )// VBA only behaviour
      88          10 :                         SbxBase::SetError( SbxERR_CONVERSION );
      89             : #endif
      90             :                 }
      91             :                 else
      92          14 :                     nRes = d;
      93             :             }
      94          30 :             break;
      95             :         case SbxOBJECT:
      96             :         {
      97           0 :             SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
      98           0 :             if( pVal )
      99           0 :                 nRes = pVal->GetDouble();
     100             :             else
     101             :             {
     102           0 :                 SbxBase::SetError( SbxERR_NO_OBJECT ); nRes = 0;
     103             :             }
     104           0 :             break;
     105             :         }
     106             : 
     107             :         case SbxBYREF | SbxCHAR:
     108           0 :             nRes = *p->pChar; break;
     109             :         case SbxBYREF | SbxBYTE:
     110           0 :             nRes = *p->pByte; break;
     111             :         case SbxBYREF | SbxINTEGER:
     112             :         case SbxBYREF | SbxBOOL:
     113           0 :             nRes = *p->pInteger; break;
     114             :         case SbxBYREF | SbxLONG:
     115           0 :             nRes = *p->pLong; break;
     116             :         case SbxBYREF | SbxULONG:
     117           0 :             nRes = *p->pULong; break;
     118             :         case SbxBYREF | SbxERROR:
     119             :         case SbxBYREF | SbxUSHORT:
     120           0 :             nRes = *p->pUShort; break;
     121             :         case SbxBYREF | SbxSINGLE:
     122           0 :             nRes = *p->pSingle; break;
     123             :         case SbxBYREF | SbxDATE:
     124             :         case SbxBYREF | SbxDOUBLE:
     125           0 :             nRes = *p->pDouble; break;
     126             :         case SbxBYREF | SbxCURRENCY:
     127           0 :             nRes = ImpCurrencyToDouble( *p->pnInt64 ); break;
     128             :         case SbxBYREF | SbxSALINT64:
     129           0 :             nRes = static_cast< double >(*p->pnInt64); break;
     130             :         case SbxBYREF | SbxSALUINT64:
     131           0 :             nRes = ImpSalUInt64ToDouble( *p->puInt64 ); break;
     132             : 
     133             :         default:
     134           0 :             SbxBase::SetError( SbxERR_CONVERSION ); nRes = 0;
     135             :     }
     136        9814 :     return nRes;
     137             : }
     138             : 
     139        8969 : void ImpPutDouble( SbxValues* p, double n, bool bCoreString )
     140             : {
     141        8969 :     SbxValues aTmp;
     142             : start:
     143        9196 :     switch( +p->eType )
     144             :     {
     145             :         // Here are tests necessary
     146             :         case SbxCHAR:
     147           0 :             aTmp.pChar = &p->nChar; goto direct;
     148             :         case SbxBYTE:
     149           0 :             aTmp.pByte = &p->nByte; goto direct;
     150             :         case SbxINTEGER:
     151             :         case SbxBOOL:
     152         227 :             aTmp.pInteger = &p->nInteger; goto direct;
     153             :         case SbxLONG:
     154           0 :             aTmp.pLong = &p->nLong; goto direct;
     155             :         case SbxULONG:
     156           0 :             aTmp.pULong = &p->nULong; goto direct;
     157             :         case SbxERROR:
     158             :         case SbxUSHORT:
     159           0 :             aTmp.pUShort = &p->nUShort; goto direct;
     160             :         case SbxSINGLE:
     161           0 :             aTmp.pSingle = &p->nSingle; goto direct;
     162             :         case SbxDECIMAL:
     163             :         case SbxBYREF | SbxDECIMAL:
     164             :             {
     165           0 :             SbxDecimal* pDec = ImpCreateDecimal( p );
     166           0 :             if( !pDec->setDouble( n ) )
     167           0 :                 SbxBase::SetError( SbxERR_OVERFLOW );
     168           0 :             break;
     169             :             }
     170             :         direct:
     171         227 :             aTmp.eType = SbxDataType( p->eType | SbxBYREF );
     172         227 :             p = &aTmp; goto start;
     173             : 
     174             :         case SbxCURRENCY:
     175           0 :             if( n > SbxMAXCURR )
     176             :             {
     177           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXCURR;
     178             :             }
     179           0 :             else if( n < SbxMINCURR )
     180             :             {
     181           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMINCURR;
     182             :             }
     183           0 :             p->nInt64 = ImpDoubleToCurrency( n );
     184           0 :             break;
     185             : 
     186             :             // from here on no longer
     187             :         case SbxSALINT64:
     188           0 :             p->nInt64 = ImpDoubleToSalInt64( n ); break;
     189             :         case SbxSALUINT64:
     190           0 :             p->uInt64 = ImpDoubleToSalUInt64( n ); break;
     191             :         case SbxDATE:
     192             :         case SbxDOUBLE:
     193        8550 :             p->nDouble = n; break;
     194             : 
     195             :         case SbxBYREF | SbxSTRING:
     196             :         case SbxSTRING:
     197             :         case SbxLPSTR:
     198         192 :             if( !p->pOUString )
     199           0 :                 p->pOUString = new OUString;
     200         192 :             ImpCvtNum( (double) n, 14, *p->pOUString, bCoreString );
     201         192 :             break;
     202             :         case SbxOBJECT:
     203             :         {
     204           0 :             SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
     205           0 :             if( pVal )
     206           0 :                 pVal->PutDouble( n );
     207             :             else
     208           0 :                 SbxBase::SetError( SbxERR_NO_OBJECT );
     209           0 :             break;
     210             :         }
     211             :         case SbxBYREF | SbxCHAR:
     212           0 :             if( n > SbxMAXCHAR )
     213             :             {
     214           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXCHAR;
     215             :             }
     216           0 :             else if( n < SbxMINCHAR )
     217             :             {
     218           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMINCHAR;
     219             :             }
     220           0 :             *p->pChar = (sal_Unicode) n; break;
     221             :         case SbxBYREF | SbxBYTE:
     222           0 :             if( n > SbxMAXBYTE )
     223             :             {
     224           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXBYTE;
     225             :             }
     226           0 :             else if( n < 0 )
     227             :             {
     228           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); n = 0;
     229             :             }
     230           0 :             *p->pByte = (sal_uInt8) n; break;
     231             :         case SbxBYREF | SbxINTEGER:
     232             :         case SbxBYREF | SbxBOOL:
     233         227 :             if( n > SbxMAXINT )
     234             :             {
     235           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXINT;
     236             :             }
     237         227 :             else if( n < SbxMININT )
     238             :             {
     239           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMININT;
     240             :             }
     241         227 :             *p->pInteger = (sal_Int16) n; break;
     242             :         case SbxBYREF | SbxERROR:
     243             :         case SbxBYREF | SbxUSHORT:
     244           0 :             if( n > SbxMAXUINT )
     245             :             {
     246           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXUINT;
     247             :             }
     248           0 :             else if( n < 0 )
     249             :             {
     250           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); n = 0;
     251             :             }
     252           0 :             *p->pUShort = (sal_uInt16) n; break;
     253             :         case SbxBYREF | SbxLONG:
     254           0 :             if( n > SbxMAXLNG )
     255             :             {
     256           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXLNG;
     257             :             }
     258           0 :             else if( n < SbxMINLNG )
     259             :             {
     260           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMINLNG;
     261             :             }
     262           0 :             *p->pLong = (sal_Int32) n; break;
     263             :         case SbxBYREF | SbxULONG:
     264           0 :             if( n > SbxMAXULNG )
     265             :             {
     266           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXULNG;
     267             :             }
     268           0 :             else if( n < 0 )
     269             :             {
     270           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); n = 0;
     271             :             }
     272           0 :             *p->pULong = (sal_uInt32) n; break;
     273             :         case SbxBYREF | SbxSINGLE:
     274           0 :             if( n > SbxMAXSNG )
     275             :             {
     276           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXSNG;
     277             :             }
     278           0 :             else if( n < SbxMINSNG )
     279             :             {
     280           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMINSNG;
     281             :             }
     282           0 :             else if( n > 0 && n < SbxMAXSNG2 )
     283             :             {
     284           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXSNG2;
     285             :             }
     286           0 :             else if( n < 0 && n > SbxMINSNG2 )
     287             :             {
     288           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMINSNG2;
     289             :             }
     290           0 :             *p->pSingle = (float) n; break;
     291             :         case SbxBYREF | SbxSALINT64:
     292           0 :             *p->pnInt64 = ImpDoubleToSalInt64( n ); break;
     293             :         case SbxBYREF | SbxSALUINT64:
     294           0 :             *p->puInt64 = ImpDoubleToSalUInt64( n ); break;
     295             :         case SbxBYREF | SbxDATE:
     296             :         case SbxBYREF | SbxDOUBLE:
     297           0 :             *p->pDouble = (double) n; break;
     298             :         case SbxBYREF | SbxCURRENCY:
     299           0 :             if( n > SbxMAXCURR )
     300             :             {
     301           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXCURR;
     302             :             }
     303           0 :             else if( n < SbxMINCURR )
     304             :             {
     305           0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMINCURR;
     306             :             }
     307           0 :             *p->pnInt64 = ImpDoubleToCurrency( n ); break;
     308             : 
     309             :         default:
     310           0 :             SbxBase::SetError( SbxERR_CONVERSION );
     311             :     }
     312        8969 : }
     313             : 
     314             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11