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

Generated by: LCOV version 1.11