LCOV - code coverage report
Current view: top level - Accounts - utils.cpp (source / functions) Hit Total Coverage
Test: Code Coverage Lines: 26 41 63.4 %
Date: 2012-07-13 Functions: 2 2 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 7 14 50.0 %

           Branch data     Line data    Source code
       1                 :            : /* vi: set et sw=4 ts=4 cino=t0,(0: */
       2                 :            : /*
       3                 :            :  * This file is part of libaccounts-qt
       4                 :            :  *
       5                 :            :  * Copyright (C) 2012 Canonical Ltd.
       6                 :            :  *
       7                 :            :  * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
       8                 :            :  *
       9                 :            :  * This library is free software; you can redistribute it and/or
      10                 :            :  * modify it under the terms of the GNU Lesser General Public License
      11                 :            :  * version 2.1 as published by the Free Software Foundation.
      12                 :            :  *
      13                 :            :  * This library is distributed in the hope that it will be useful, but
      14                 :            :  * WITHOUT ANY WARRANTY; without even the implied warranty of
      15                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
      16                 :            :  * Lesser General Public License for more details.
      17                 :            :  *
      18                 :            :  * You should have received a copy of the GNU Lesser General Public
      19                 :            :  * License along with this library; if not, write to the Free Software
      20                 :            :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
      21                 :            :  * 02110-1301 USA
      22                 :            :  */
      23                 :            : 
      24                 :            : #include "accountscommon.h"
      25                 :            : #include "utils.h"
      26                 :            : 
      27                 :            : namespace Accounts {
      28                 :            : 
      29                 :         11 : QVariant gvalueToVariant(const GValue *value)
      30                 :            : {
      31                 :         11 :     GType type = G_VALUE_TYPE(value);
      32                 :            : 
      33                 :            :     QVariant variant;
      34                 :            : 
      35   [ +  +  -  -  :         11 :     switch (type)
                -  +  - ]
      36                 :            :     {
      37                 :            :     case G_TYPE_STRING:
      38                 :          5 :         variant = UTF8(g_value_get_string(value));
      39                 :          5 :         break;
      40                 :            :     case G_TYPE_INT:
      41                 :          5 :         variant = g_value_get_int(value);
      42                 :          5 :         break;
      43                 :            :     case G_TYPE_UINT:
      44                 :          0 :         variant = g_value_get_uint(value);
      45                 :          0 :         break;
      46                 :            :     case G_TYPE_INT64:
      47                 :          0 :         variant = qint64(g_value_get_int64(value));
      48                 :          0 :         break;
      49                 :            :     case G_TYPE_UINT64:
      50                 :          0 :         variant = quint64(g_value_get_uint64(value));
      51                 :          0 :         break;
      52                 :            :     case G_TYPE_BOOLEAN:
      53                 :          1 :         variant = bool(g_value_get_boolean(value));
      54                 :          1 :         break;
      55                 :            :     default:
      56                 :          0 :         qWarning() << "Unsupported type" << UTF8(G_VALUE_TYPE_NAME(value));
      57                 :          0 :         break;
      58                 :            :     }
      59                 :            : 
      60                 :         11 :     return variant;
      61                 :            : }
      62                 :            : 
      63                 :         29 : bool variantToGValue(const QVariant &variant, GValue *value)
      64                 :            : {
      65                 :            :     QByteArray tmpvalue;
      66                 :            : 
      67   [ +  +  +  -  :         29 :     switch (variant.type())
                -  +  - ]
      68                 :            :     {
      69                 :            :     case QVariant::String:
      70                 :         17 :         g_value_init(value, G_TYPE_STRING);
      71                 :         17 :         tmpvalue = variant.toString().toUtf8();
      72                 :         17 :         g_value_set_string(value, tmpvalue.constData());
      73                 :         17 :         break;
      74                 :            :     case QVariant::Int:
      75                 :          5 :         g_value_init(value, G_TYPE_INT);
      76                 :          5 :         g_value_set_int(value, variant.toInt());
      77                 :          5 :         break;
      78                 :            :     case QVariant::UInt:
      79                 :          3 :         g_value_init(value, G_TYPE_UINT);
      80                 :          3 :         g_value_set_uint(value, variant.toUInt());
      81                 :          3 :         break;
      82                 :            :     case QVariant::LongLong:
      83                 :          0 :         g_value_init(value, G_TYPE_INT64);
      84                 :          0 :         g_value_set_int64(value, variant.toLongLong());
      85                 :          0 :         break;
      86                 :            :     case QVariant::ULongLong:
      87                 :          0 :         g_value_init(value, G_TYPE_UINT64);
      88                 :          0 :         g_value_set_uint64(value, variant.toULongLong());
      89                 :          0 :         break;
      90                 :            :     case QVariant::Bool:
      91                 :          4 :         g_value_init(value, G_TYPE_BOOLEAN);
      92                 :          4 :         g_value_set_boolean(value, variant.toBool());
      93                 :          4 :         break;
      94                 :            :     default:
      95                 :          0 :         qWarning() << "Unsupported datatype" << variant.typeName();
      96                 :            :         return false;
      97                 :            :     }
      98                 :            : 
      99                 :         29 :     return true;
     100                 :            : }
     101                 :            : 
     102                 :            : }; // namespace

Generated by: LCOV version 1.9