LCOV - code coverage report
Current view: top level - common-lib - exception.cpp (source / functions) Coverage Total Hit
Test: QtApplicationManager Lines: 54.2 % 59 32
Test Date: 2024-12-07 10:07:01 Functions: 56.2 % 16 9
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 42.9 % 28 12

             Branch data     Line data    Source code
       1                 :             : // Copyright (C) 2021 The Qt Company Ltd.
       2                 :             : // Copyright (C) 2019 Luxoft Sweden AB
       3                 :             : // Copyright (C) 2018 Pelagicore AG
       4                 :             : // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
       5                 :             : 
       6                 :             : #include <QFile>
       7                 :             : #include <errno.h>
       8                 :             : 
       9                 :             : #include "exception.h"
      10                 :             : 
      11                 :             : QT_BEGIN_NAMESPACE_AM
      12                 :             : 
      13                 :          19 : Exception::Exception(const char *errorString) noexcept
      14         [ +  - ]:          19 :     : m_errorCode(Error::System)
      15         [ +  - ]:          38 :     , m_errorString(errorString ? QString::fromLatin1(errorString) : QString())
      16                 :          19 : { }
      17                 :             : 
      18                 :           0 : Exception::Exception(const QString &errorString) noexcept
      19                 :           0 :     : m_errorCode(Error::System)
      20                 :           0 :     , m_errorString(errorString)
      21                 :           0 : { }
      22                 :             : 
      23                 :          96 : Exception::Exception(Error errorCode, const char *errorString) noexcept
      24         [ +  + ]:          96 :     : m_errorCode(errorCode)
      25         [ +  + ]:         180 :     , m_errorString(errorString ? QString::fromLatin1(errorString) : QString())
      26                 :          96 : { }
      27                 :             : 
      28                 :          14 : Exception::Exception(Error errorCode, const QString &errorString) noexcept
      29                 :          14 :     : m_errorCode(errorCode)
      30                 :          14 :     , m_errorString(errorString)
      31                 :          14 : { }
      32                 :             : 
      33                 :           0 : Exception::Exception(int _errno, const char *errorString) noexcept
      34         [ #  # ]:           0 :     : m_errorCode(_errno == EACCES ? Error::Permissions : Error::IO)
      35   [ #  #  #  #  :           0 :     , m_errorString(QString::fromLatin1(errorString) + u": " + QString::fromLocal8Bit(strerror(_errno)))
                   #  # ]
      36                 :           0 : { }
      37                 :             : 
      38                 :           3 : Exception::Exception(const QFileDevice &file, const char *errorString) noexcept
      39         [ +  - ]:           3 :     : m_errorCode(file.error() == QFileDevice::PermissionsError ? Error::Permissions : Error::IO)
      40         [ +  - ]:          15 :     , m_errorString(QString::fromLatin1(errorString) + u" (" + file.fileName() + u"): " + file.errorString())
      41                 :           3 : { }
      42                 :             : 
      43                 :          68 : Exception::Exception(const Exception &copy) noexcept
      44                 :             :     : QException(copy)
      45                 :          68 :     , m_errorCode(copy.m_errorCode)
      46                 :          68 :     , m_errorString(copy.m_errorString)
      47                 :          68 : { }
      48                 :             : 
      49                 :           0 : Exception &Exception::operator=(const Exception &copy) noexcept
      50                 :             : {
      51         [ #  # ]:           0 :     if (this != &copy) {
      52                 :           0 :         QException::operator=(copy);
      53                 :           0 :         m_errorCode = copy.m_errorCode;
      54                 :           0 :         m_errorString = copy.m_errorString;
      55                 :             :     }
      56                 :           0 :     return *this;
      57                 :             : }
      58                 :             : 
      59                 :           0 : Exception::Exception(Exception &&move) noexcept
      60                 :             :     : QException(move)
      61                 :           0 :     , m_errorCode(move.m_errorCode)
      62                 :           0 :     , m_errorString(move.m_errorString)
      63                 :           0 : { }
      64                 :             : 
      65                 :           0 : Exception &Exception::operator=(Exception &&move) noexcept
      66                 :             : {
      67                 :           0 :     QException::operator=(move);
      68                 :           0 :     m_errorCode = move.m_errorCode;
      69                 :           0 :     m_errorString = move.m_errorString;
      70                 :           0 :     return *this;
      71                 :             : }
      72                 :             : 
      73                 :         199 : Exception::~Exception() noexcept
      74                 :             : {
      75         [ +  + ]:         213 :     delete m_whatBuffer;
      76                 :         199 : }
      77                 :             : 
      78                 :          50 : Error Exception::errorCode() const noexcept
      79                 :             : {
      80                 :          50 :     return m_errorCode;
      81                 :             : }
      82                 :             : 
      83                 :          96 : QString Exception::errorString() const noexcept
      84                 :             : {
      85                 :          96 :     return m_errorString;
      86                 :             : }
      87                 :             : 
      88                 :           0 : void Exception::raise() const
      89                 :             : {
      90                 :           0 :     throw *this;
      91                 :             : }
      92                 :             : 
      93                 :           0 : Exception *Exception::clone() const noexcept
      94                 :             : {
      95                 :           0 :     return new Exception(*this);
      96                 :             : }
      97                 :             : 
      98                 :          14 : const char *Exception::what() const noexcept
      99                 :             : {
     100         [ +  - ]:          14 :     if (!m_whatBuffer)
     101                 :          14 :         m_whatBuffer = new QByteArray;
     102                 :          14 :     *m_whatBuffer = m_errorString.toLocal8Bit();
     103         [ +  - ]:          14 :     return m_whatBuffer->constData();
     104                 :             : }
     105                 :             : 
     106                 :             : QT_END_NAMESPACE_AM
        

Generated by: LCOV version 2.0-1