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

Generated by: LCOV version 1.10