LCOV - code coverage report
Current view: top level - basic/source/sbx - sbxuint.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 129 0.0 %
Date: 2012-08-25 Functions: 0 2 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 176 0.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                 :            : #include <tools/errcode.hxx>
      21                 :            : #include <basic/sbx.hxx>
      22                 :            : #include "sbxconv.hxx"
      23                 :            : 
      24                 :          0 : sal_uInt16 ImpGetUShort( const SbxValues* p )
      25                 :            : {
      26                 :          0 :     SbxValues aTmp;
      27                 :            :     sal_uInt16 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 > SbxMAXUINT )
      55                 :            :             {
      56         [ #  # ]:          0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXUINT;
      57                 :            :             }
      58         [ #  # ]:          0 :             else if( p->nLong < 0 )
      59                 :            :             {
      60         [ #  # ]:          0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = 0;
      61                 :            :             }
      62                 :            :             else
      63                 :          0 :                 nRes = (sal_uInt16) p->nLong;
      64                 :          0 :             break;
      65                 :            :         case SbxULONG:
      66         [ #  # ]:          0 :             if( p->nULong > SbxMAXUINT )
      67                 :            :             {
      68         [ #  # ]:          0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXUINT;
      69                 :            :             }
      70                 :            :             else
      71                 :          0 :                 nRes = (sal_uInt16) p->nULong;
      72                 :          0 :             break;
      73                 :            :         case SbxCURRENCY:
      74         [ #  # ]:          0 :             if( p->nInt64 / CURRENCY_FACTOR > SbxMAXUINT )
      75                 :            :             {
      76         [ #  # ]:          0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXUINT;
      77                 :            :             }
      78         [ #  # ]:          0 :             else if( p->nInt64 < 0 )
      79                 :            :             {
      80         [ #  # ]:          0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = 0;
      81                 :            :             }
      82                 :            :             else
      83                 :          0 :                 nRes = (sal_uInt16) (p->nInt64 / CURRENCY_FACTOR);
      84                 :          0 :             break;
      85                 :            :         case SbxSALINT64:
      86         [ #  # ]:          0 :             if( p->nInt64 > SbxMAXUINT )
      87                 :            :             {
      88         [ #  # ]:          0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXUINT;
      89                 :            :             }
      90         [ #  # ]:          0 :             else if( p->nInt64 < 0 )
      91                 :            :             {
      92         [ #  # ]:          0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = 0;
      93                 :            :             }
      94                 :            :             else
      95                 :          0 :                 nRes = (sal_uInt16) p->nInt64;
      96                 :          0 :             break;
      97                 :            :         case SbxSALUINT64:
      98         [ #  # ]:          0 :             if( p->uInt64 > SbxMAXUINT )
      99                 :            :             {
     100         [ #  # ]:          0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXUINT;
     101                 :            :             }
     102                 :            :             else
     103                 :          0 :                 nRes = (sal_uInt16) p->uInt64;
     104                 :          0 :             break;
     105                 :            :         case SbxSINGLE:
     106         [ #  # ]:          0 :             if( p->nSingle > SbxMAXUINT )
     107                 :            :             {
     108         [ #  # ]:          0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXUINT;
     109                 :            :             }
     110         [ #  # ]:          0 :             else if( p->nSingle < 0 )
     111                 :            :             {
     112         [ #  # ]:          0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = 0;
     113                 :            :             }
     114                 :            :             else
     115                 :          0 :                 nRes = (sal_uInt16) ( p->nSingle + 0.5 );
     116                 :          0 :             break;
     117                 :            :         case SbxDATE:
     118                 :            :         case SbxDOUBLE:
     119                 :            :         case SbxDECIMAL:
     120                 :            :         case SbxBYREF | SbxDECIMAL:
     121                 :            :             {
     122                 :            :             double dVal;
     123         [ #  # ]:          0 :             if( p->eType == SbxDECIMAL )
     124                 :            :             {
     125                 :          0 :                 dVal = 0.0;
     126         [ #  # ]:          0 :                 if( p->pDecimal )
     127         [ #  # ]:          0 :                     p->pDecimal->getDouble( dVal );
     128                 :            :             }
     129                 :            :             else
     130                 :          0 :                 dVal = p->nDouble;
     131                 :            : 
     132         [ #  # ]:          0 :             if( dVal > SbxMAXUINT )
     133                 :            :             {
     134         [ #  # ]:          0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXUINT;
     135                 :            :             }
     136         [ #  # ]:          0 :             else if( dVal < 0 )
     137                 :            :             {
     138         [ #  # ]:          0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); nRes = 0;
     139                 :            :             }
     140                 :            :             else
     141                 :          0 :                 nRes = (sal_uInt16) ( dVal + 0.5 );
     142                 :            :             break;
     143                 :            :             }
     144                 :            :         case SbxBYREF | SbxSTRING:
     145                 :            :         case SbxSTRING:
     146                 :            :         case SbxLPSTR:
     147         [ #  # ]:          0 :             if( !p->pOUString )
     148                 :          0 :                 nRes = 0;
     149                 :            :             else
     150                 :            :             {
     151                 :            :                 double d;
     152                 :            :                 SbxDataType t;
     153 [ #  # ][ #  # ]:          0 :                 if( ImpScan( *p->pOUString, d, t, NULL ) != SbxERR_OK )
     154                 :          0 :                     nRes = 0;
     155         [ #  # ]:          0 :                 else if( d > SbxMAXUINT )
     156                 :            :                 {
     157         [ #  # ]:          0 :                     SbxBase::SetError( SbxERR_OVERFLOW ); nRes = SbxMAXUINT;
     158                 :            :                 }
     159         [ #  # ]:          0 :                 else if( d < 0 )
     160                 :            :                 {
     161         [ #  # ]:          0 :                     SbxBase::SetError( SbxERR_OVERFLOW ); nRes = 0;
     162                 :            :                 }
     163                 :            :                 else
     164                 :          0 :                     nRes = (sal_uInt16) ( d + 0.5 );
     165                 :            :             }
     166                 :          0 :             break;
     167                 :            :         case SbxOBJECT:
     168                 :            :         {
     169 [ #  # ][ #  # ]:          0 :             SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
         [ #  # ][ #  # ]
     170         [ #  # ]:          0 :             if( pVal )
     171         [ #  # ]:          0 :                 nRes = pVal->GetUShort();
     172                 :            :             else
     173                 :            :             {
     174         [ #  # ]:          0 :                 SbxBase::SetError( SbxERR_NO_OBJECT ); nRes = 0;
     175                 :            :             }
     176                 :          0 :             break;
     177                 :            :         }
     178                 :            : 
     179                 :            :         case SbxBYREF | SbxBYTE:
     180                 :          0 :             nRes = *p->pByte; break;
     181                 :            :         case SbxBYREF | SbxERROR:
     182                 :            :         case SbxBYREF | SbxUSHORT:
     183                 :          0 :             nRes = *p->pUShort; break;
     184                 :            : 
     185                 :            :         // from here on will be tested
     186                 :            :         case SbxBYREF | SbxCHAR:
     187                 :          0 :             aTmp.nChar = *p->pChar; goto ref;
     188                 :            :         case SbxBYREF | SbxINTEGER:
     189                 :            :         case SbxBYREF | SbxBOOL:
     190                 :          0 :             aTmp.nInteger = *p->pInteger; goto ref;
     191                 :            :         case SbxBYREF | SbxLONG:
     192                 :          0 :             aTmp.nLong = *p->pLong; goto ref;
     193                 :            :         case SbxBYREF | SbxULONG:
     194                 :          0 :             aTmp.nULong = *p->pULong; goto ref;
     195                 :            :         case SbxBYREF | SbxSINGLE:
     196                 :          0 :             aTmp.nSingle = *p->pSingle; goto ref;
     197                 :            :         case SbxBYREF | SbxDATE:
     198                 :            :         case SbxBYREF | SbxDOUBLE:
     199                 :          0 :             aTmp.nDouble = *p->pDouble; goto ref;
     200                 :            :         case SbxBYREF | SbxCURRENCY:
     201                 :            :         case SbxBYREF | SbxSALINT64:
     202                 :          0 :             aTmp.nInt64 = *p->pnInt64; goto ref;
     203                 :            :         case SbxBYREF | SbxSALUINT64:
     204                 :          0 :             aTmp.uInt64 = *p->puInt64; goto ref;
     205                 :            :         ref:
     206                 :          0 :             aTmp.eType = SbxDataType( p->eType & 0x0FFF );
     207                 :          0 :             p = &aTmp; goto start;
     208                 :            : 
     209                 :            :         default:
     210         [ #  # ]:          0 :             SbxBase::SetError( SbxERR_CONVERSION ); nRes = 0;
     211                 :            :     }
     212                 :          0 :     return nRes;
     213                 :            : }
     214                 :            : 
     215                 :          0 : void ImpPutUShort( SbxValues* p, sal_uInt16 n )
     216                 :            : {
     217                 :          0 :     SbxValues aTmp;
     218                 :            : 
     219                 :            : start:
     220   [ #  #  #  #  :          0 :     switch( +p->eType )
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     221                 :            :     {
     222                 :            :         case SbxERROR:
     223                 :            :         case SbxUSHORT:
     224                 :          0 :             p->nUShort = n; break;
     225                 :            :         case SbxLONG:
     226                 :          0 :             p->nLong = n; break;
     227                 :            :         case SbxULONG:
     228                 :          0 :             p->nULong = n; break;
     229                 :            :         case SbxSINGLE:
     230                 :          0 :             p->nSingle = n; break;
     231                 :            :         case SbxDATE:
     232                 :            :         case SbxDOUBLE:
     233                 :          0 :             p->nDouble = n; break;
     234                 :            :         case SbxCURRENCY:
     235                 :          0 :             p->nInt64 = n * CURRENCY_FACTOR; break;
     236                 :            :         case SbxSALINT64:
     237                 :          0 :             p->nInt64 = n; break;
     238                 :            :         case SbxSALUINT64:
     239                 :          0 :             p->uInt64 = n; break;
     240                 :            :         case SbxDECIMAL:
     241                 :            :         case SbxBYREF | SbxDECIMAL:
     242 [ #  # ][ #  # ]:          0 :             ImpCreateDecimal( p )->setUInt( n );
     243                 :          0 :             break;
     244                 :            : 
     245                 :            :         // from here on tests
     246                 :            :         case SbxCHAR:
     247                 :          0 :             aTmp.pChar = &p->nChar; goto direct;
     248                 :            :         case SbxBYTE:
     249                 :          0 :             aTmp.pByte = &p->nByte; goto direct;
     250                 :            :         case SbxINTEGER:
     251                 :            :         case SbxBOOL:
     252                 :          0 :             aTmp.pInteger = &p->nInteger;
     253                 :            :         direct:
     254                 :          0 :             aTmp.eType = SbxDataType( p->eType | SbxBYREF );
     255                 :          0 :             p = &aTmp; goto start;
     256                 :            : 
     257                 :            :         case SbxBYREF | SbxSTRING:
     258                 :            :         case SbxSTRING:
     259                 :            :         case SbxLPSTR:
     260         [ #  # ]:          0 :             if( !p->pOUString )
     261         [ #  # ]:          0 :                 p->pOUString = new ::rtl::OUString;
     262         [ #  # ]:          0 :             ImpCvtNum( (double) n, 0, *p->pOUString );
     263                 :          0 :             break;
     264                 :            :         case SbxOBJECT:
     265                 :            :         {
     266 [ #  # ][ #  # ]:          0 :             SbxValue* pVal = PTR_CAST(SbxValue,p->pObj);
         [ #  # ][ #  # ]
     267         [ #  # ]:          0 :             if( pVal )
     268         [ #  # ]:          0 :                 pVal->PutUShort( n );
     269                 :            :             else
     270         [ #  # ]:          0 :                 SbxBase::SetError( SbxERR_NO_OBJECT );
     271                 :          0 :             break;
     272                 :            :         }
     273                 :            : 
     274                 :            :         case SbxBYREF | SbxCHAR:
     275                 :          0 :             *p->pChar = (xub_Unicode) n; break;
     276                 :            :         case SbxBYREF | SbxBYTE:
     277         [ #  # ]:          0 :             if( n > SbxMAXBYTE )
     278                 :            :             {
     279         [ #  # ]:          0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXBYTE;
     280                 :            :             }
     281                 :          0 :             *p->pByte = (sal_uInt8) n; break;
     282                 :            :         case SbxBYREF | SbxINTEGER:
     283                 :            :         case SbxBYREF | SbxBOOL:
     284         [ #  # ]:          0 :             if( n > SbxMAXINT )
     285                 :            :             {
     286         [ #  # ]:          0 :                 SbxBase::SetError( SbxERR_OVERFLOW ); n = SbxMAXINT;
     287                 :            :             }
     288                 :          0 :             *p->pInteger = (sal_Int16) n; break;
     289                 :            :         case SbxBYREF | SbxERROR:
     290                 :            :         case SbxBYREF | SbxUSHORT:
     291                 :          0 :             *p->pUShort = n; break;
     292                 :            :         case SbxBYREF | SbxLONG:
     293                 :          0 :             *p->pLong = n; break;
     294                 :            :         case SbxBYREF | SbxULONG:
     295                 :          0 :             *p->pULong = n; break;
     296                 :            :         case SbxBYREF | SbxSINGLE:
     297                 :          0 :             *p->pSingle = n; break;
     298                 :            :         case SbxBYREF | SbxDATE:
     299                 :            :         case SbxBYREF | SbxDOUBLE:
     300                 :          0 :             *p->pDouble = n; break;
     301                 :            :         case SbxBYREF | SbxCURRENCY:
     302                 :          0 :             *p->pnInt64 = n * CURRENCY_FACTOR; break;
     303                 :            :         case SbxBYREF | SbxSALINT64:
     304                 :          0 :             *p->pnInt64 = n; break;
     305                 :            :         case SbxBYREF | SbxSALUINT64:
     306                 :          0 :             *p->puInt64 = n; break;
     307                 :            : 
     308                 :            :         default:
     309         [ #  # ]:          0 :             SbxBase::SetError( SbxERR_CONVERSION );
     310                 :            :     }
     311                 :          0 : }
     312                 :            : 
     313                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10