LCOV - code coverage report
Current view: top level - configmgr/source - type.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 37 66 56.1 %
Date: 2012-08-25 Functions: 4 4 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 22 69 31.9 %

           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 "sal/config.h"
      21                 :            : 
      22                 :            : #include <cassert>
      23                 :            : 
      24                 :            : #include "com/sun/star/uno/Any.hxx"
      25                 :            : #include "com/sun/star/uno/Reference.hxx"
      26                 :            : #include "com/sun/star/uno/RuntimeException.hpp"
      27                 :            : #include "com/sun/star/uno/Sequence.hxx"
      28                 :            : #include "com/sun/star/uno/Type.hxx"
      29                 :            : #include "com/sun/star/uno/TypeClass.hpp"
      30                 :            : #include "com/sun/star/uno/XInterface.hpp"
      31                 :            : #include "cppu/unotype.hxx"
      32                 :            : #include "rtl/string.h"
      33                 :            : #include "rtl/ustring.h"
      34                 :            : #include "rtl/ustring.hxx"
      35                 :            : #include "sal/types.h"
      36                 :            : 
      37                 :            : #include "type.hxx"
      38                 :            : 
      39                 :            : namespace configmgr {
      40                 :            : 
      41                 :            : namespace {
      42                 :            : 
      43                 :            : namespace css = com::sun::star;
      44                 :            : 
      45                 :            : }
      46                 :            : 
      47                 :      34044 : bool isListType(Type type) {
      48                 :      34044 :     return type >= TYPE_BOOLEAN_LIST;
      49                 :            : }
      50                 :            : 
      51                 :      34044 : Type elementType(Type type) {
      52   [ -  -  -  -  :      34044 :     switch (type) {
             -  +  -  - ]
      53                 :            :     case TYPE_BOOLEAN_LIST:
      54                 :          0 :         return TYPE_BOOLEAN;
      55                 :            :     case TYPE_SHORT_LIST:
      56                 :          0 :         return TYPE_SHORT;
      57                 :            :     case TYPE_INT_LIST:
      58                 :          0 :         return TYPE_INT;
      59                 :            :     case TYPE_LONG_LIST:
      60                 :          0 :         return TYPE_LONG;
      61                 :            :     case TYPE_DOUBLE_LIST:
      62                 :          0 :         return TYPE_DOUBLE;
      63                 :            :     case TYPE_STRING_LIST:
      64                 :      34044 :         return TYPE_STRING;
      65                 :            :     case TYPE_HEXBINARY_LIST:
      66                 :          0 :         return TYPE_HEXBINARY;
      67                 :            :     default:
      68                 :            :         assert(false);
      69                 :            :         throw css::uno::RuntimeException(
      70                 :            :             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("this cannot happen")),
      71 [ #  # ][ #  # ]:      34044 :             css::uno::Reference< css::uno::XInterface >());
      72                 :            :     }
      73                 :            : }
      74                 :            : 
      75                 :     101188 : css::uno::Type mapType(Type type) {
      76   [ -  +  +  +  :     101188 :     switch (type) {
          -  -  +  -  -  
          -  +  -  -  +  
                   -  - ]
      77                 :            :     case TYPE_ANY:
      78                 :          0 :         return cppu::UnoType< css::uno::Any >::get();
      79                 :            :     case TYPE_BOOLEAN:
      80                 :      54805 :         return cppu::UnoType< sal_Bool >::get();
      81                 :            :     case TYPE_SHORT:
      82                 :       1760 :         return cppu::UnoType< sal_Int16 >::get();
      83                 :            :     case TYPE_INT:
      84                 :       8966 :         return cppu::UnoType< sal_Int32 >::get();
      85                 :            :     case TYPE_LONG:
      86                 :          0 :         return cppu::UnoType< sal_Int64 >::get();
      87                 :            :     case TYPE_DOUBLE:
      88                 :          0 :         return cppu::UnoType< double >::get();
      89                 :            :     case TYPE_STRING:
      90                 :      35149 :         return cppu::UnoType< rtl::OUString >::get();
      91                 :            :     case TYPE_HEXBINARY:
      92                 :          0 :         return cppu::UnoType< css::uno::Sequence< sal_Int8 > >::get();
      93                 :            :     case TYPE_BOOLEAN_LIST:
      94                 :          0 :         return cppu::UnoType< css::uno::Sequence< sal_Bool > >::get();
      95                 :            :     case TYPE_SHORT_LIST:
      96                 :          0 :         return cppu::UnoType< css::uno::Sequence< sal_Int16 > >::get();
      97                 :            :     case TYPE_INT_LIST:
      98                 :          1 :         return cppu::UnoType< css::uno::Sequence< sal_Int32 > >::get();
      99                 :            :     case TYPE_LONG_LIST:
     100                 :          0 :         return cppu::UnoType< css::uno::Sequence< sal_Int64 > >::get();
     101                 :            :     case TYPE_DOUBLE_LIST:
     102                 :          0 :         return cppu::UnoType< css::uno::Sequence< double > >::get();
     103                 :            :     case TYPE_STRING_LIST:
     104                 :        507 :         return cppu::UnoType< css::uno::Sequence< rtl::OUString > >::get();
     105                 :            :     case TYPE_HEXBINARY_LIST:
     106                 :            :         return cppu::UnoType<
     107                 :          0 :             css::uno::Sequence< css::uno::Sequence< sal_Int8 > > >::get();
     108                 :            :     default:
     109                 :            :         assert(false);
     110                 :            :         throw css::uno::RuntimeException(
     111                 :            :             rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("this cannot happen")),
     112 [ #  # ][ #  # ]:     101188 :             css::uno::Reference< css::uno::XInterface >());
     113                 :            :     }
     114                 :            : }
     115                 :            : 
     116                 :     866288 : Type getDynamicType(css::uno::Any const & value) {
     117   [ +  +  -  +  :     866288 :     switch (value.getValueType().getTypeClass()) {
          -  +  -  -  -  
             -  +  +  - ]
     118                 :            :     case css::uno::TypeClass_VOID:
     119                 :      22360 :         return TYPE_NIL;
     120                 :            :     case css::uno::TypeClass_BOOLEAN:
     121                 :      85361 :         return TYPE_BOOLEAN;
     122                 :            :     case css::uno::TypeClass_BYTE:
     123                 :          0 :         return TYPE_SHORT;
     124                 :            :     case css::uno::TypeClass_SHORT:
     125                 :      10511 :         return TYPE_SHORT;
     126                 :            :     case css::uno::TypeClass_UNSIGNED_SHORT:
     127         [ #  # ]:          0 :         return value.has< sal_Int16 >() ? TYPE_SHORT : TYPE_INT;
     128                 :            :     case css::uno::TypeClass_LONG:
     129                 :      22194 :         return TYPE_INT;
     130                 :            :     case css::uno::TypeClass_UNSIGNED_LONG:
     131         [ #  # ]:          0 :         return value.has< sal_Int32 >() ? TYPE_INT : TYPE_LONG;
     132                 :            :     case css::uno::TypeClass_HYPER:
     133                 :          0 :         return TYPE_LONG;
     134                 :            :     case css::uno::TypeClass_UNSIGNED_HYPER:
     135         [ #  # ]:          0 :         return value.has< sal_Int64 >() ? TYPE_LONG : TYPE_ERROR;
     136                 :            :     case css::uno::TypeClass_FLOAT:
     137                 :            :     case css::uno::TypeClass_DOUBLE:
     138                 :          0 :         return TYPE_DOUBLE;
     139                 :            :     case css::uno::TypeClass_STRING:
     140                 :      79399 :         return TYPE_STRING;
     141                 :            :     case css::uno::TypeClass_SEQUENCE: //TODO
     142                 :            :         {
     143                 :     646463 :             rtl::OUString name(value.getValueType().getTypeName());
     144         [ -  + ]:     646463 :             if ( name == "[]byte" ) {
     145                 :          0 :                 return TYPE_HEXBINARY;
     146         [ -  + ]:     646463 :             } else if (name.equalsAsciiL(
     147                 :     646463 :                            RTL_CONSTASCII_STRINGPARAM("[]boolean")))
     148                 :            :             {
     149                 :          0 :                 return TYPE_BOOLEAN_LIST;
     150         [ -  + ]:     646463 :             } else if ( name == "[]short" )
     151                 :            :             {
     152                 :          0 :                 return TYPE_SHORT_LIST;
     153         [ +  + ]:     646463 :             } else if ( name == "[]long" )
     154                 :            :             {
     155                 :          2 :                 return TYPE_INT_LIST;
     156         [ -  + ]:     646461 :             } else if ( name == "[]hyper" )
     157                 :            :             {
     158                 :          0 :                 return TYPE_LONG_LIST;
     159         [ -  + ]:     646461 :             } else if (name.equalsAsciiL(
     160                 :     646461 :                            RTL_CONSTASCII_STRINGPARAM("[]double")))
     161                 :            :             {
     162                 :          0 :                 return TYPE_DOUBLE_LIST;
     163         [ +  - ]:     646461 :             } else if (name.equalsAsciiL(
     164                 :     646461 :                            RTL_CONSTASCII_STRINGPARAM("[]string")))
     165                 :            :             {
     166                 :     646461 :                 return TYPE_STRING_LIST;
     167         [ #  # ]:          0 :             } else if (name.equalsAsciiL(
     168                 :          0 :                            RTL_CONSTASCII_STRINGPARAM("[][]byte")))
     169                 :            :             {
     170                 :          0 :                 return TYPE_HEXBINARY_LIST;
     171         [ -  + ]:     646463 :             }
     172                 :            :         }
     173                 :            :         // fall through
     174                 :            :     default:
     175                 :     866288 :         return TYPE_ERROR;
     176                 :            :     }
     177                 :            : }
     178                 :            : 
     179                 :            : }
     180                 :            : 
     181                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10