LCOV - code coverage report
Current view: top level - src - noui.cpp (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 11 59 18.6 %
Date: 2024-05-24 10:43:37 Functions: 7 16 43.8 %
Branches: 6 100 6.0 %

           Branch data     Line data    Source code
       1                 :            : // Copyright (c) 2010 Satoshi Nakamoto
       2                 :            : // Copyright (c) 2009-2022 The Bitcoin Core developers
       3                 :            : // Distributed under the MIT software license, see the accompanying
       4                 :            : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       5                 :            : 
       6                 :            : #include <noui.h>
       7                 :            : 
       8                 :            : #include <logging.h>
       9                 :            : #include <node/interface_ui.h>
      10                 :            : #include <util/translation.h>
      11                 :            : 
      12                 :            : #include <string>
      13                 :            : 
      14                 :            : #include <boost/signals2/connection.hpp>
      15                 :            : #include <boost/signals2/signal.hpp>
      16                 :            : 
      17                 :            : /** Store connections so we can disconnect them when suppressing output */
      18                 :          3 : boost::signals2::connection noui_ThreadSafeMessageBoxConn;
      19                 :          3 : boost::signals2::connection noui_ThreadSafeQuestionConn;
      20                 :          3 : boost::signals2::connection noui_InitMessageConn;
      21                 :            : 
      22                 :          0 : bool noui_ThreadSafeMessageBox(const bilingual_str& message, const std::string& caption, unsigned int style)
      23                 :            : {
      24                 :          0 :     bool fSecure = style & CClientUIInterface::SECURE;
      25                 :          0 :     style &= ~CClientUIInterface::SECURE;
      26                 :            : 
      27                 :          0 :     std::string strCaption;
      28   [ #  #  #  # ]:          0 :     switch (style) {
      29                 :            :     case CClientUIInterface::MSG_ERROR:
      30         [ #  # ]:          0 :         strCaption = "Error: ";
      31   [ #  #  #  #  :          0 :         if (!fSecure) LogError("%s\n", message.original);
             #  #  #  # ]
      32                 :          0 :         break;
      33                 :            :     case CClientUIInterface::MSG_WARNING:
      34         [ #  # ]:          0 :         strCaption = "Warning: ";
      35   [ #  #  #  #  :          0 :         if (!fSecure) LogWarning("%s\n", message.original);
             #  #  #  # ]
      36                 :          0 :         break;
      37                 :            :     case CClientUIInterface::MSG_INFORMATION:
      38         [ #  # ]:          0 :         strCaption = "Information: ";
      39   [ #  #  #  #  :          0 :         if (!fSecure) LogInfo("%s\n", message.original);
             #  #  #  # ]
      40                 :          0 :         break;
      41                 :            :     default:
      42         [ #  # ]:          0 :         strCaption = caption + ": "; // Use supplied caption (can be empty)
      43   [ #  #  #  #  :          0 :         if (!fSecure) LogInfo("%s%s\n", strCaption, message.original);
             #  #  #  # ]
      44                 :          0 :     }
      45                 :            : 
      46         [ #  # ]:          0 :     tfm::format(std::cerr, "%s%s\n", strCaption, message.original);
      47                 :            :     return false;
      48                 :          0 : }
      49                 :            : 
      50                 :          0 : bool noui_ThreadSafeQuestion(const bilingual_str& /* ignored interactive message */, const std::string& message, const std::string& caption, unsigned int style)
      51                 :            : {
      52   [ #  #  #  # ]:          0 :     return noui_ThreadSafeMessageBox(Untranslated(message), caption, style);
      53         [ #  # ]:          0 : }
      54                 :            : 
      55                 :          0 : void noui_InitMessage(const std::string& message)
      56                 :            : {
      57   [ #  #  #  #  :          0 :     LogPrintf("init message: %s\n", message);
                   #  # ]
      58                 :          0 : }
      59                 :            : 
      60                 :          2 : void noui_connect()
      61                 :            : {
      62   [ +  -  +  - ]:          2 :     noui_ThreadSafeMessageBoxConn = uiInterface.ThreadSafeMessageBox_connect(noui_ThreadSafeMessageBox);
      63   [ +  -  +  - ]:          2 :     noui_ThreadSafeQuestionConn = uiInterface.ThreadSafeQuestion_connect(noui_ThreadSafeQuestion);
      64   [ +  -  -  + ]:          2 :     noui_InitMessageConn = uiInterface.InitMessage_connect(noui_InitMessage);
      65                 :          2 : }
      66                 :            : 
      67                 :          0 : bool noui_ThreadSafeMessageBoxRedirect(const bilingual_str& message, const std::string& caption, unsigned int style)
      68                 :            : {
      69   [ #  #  #  #  :          0 :     LogPrintf("%s: %s\n", caption, message.original);
                   #  # ]
      70                 :          0 :     return false;
      71                 :          0 : }
      72                 :            : 
      73                 :          0 : bool noui_ThreadSafeQuestionRedirect(const bilingual_str& /* ignored interactive message */, const std::string& message, const std::string& caption, unsigned int style)
      74                 :          3 : {
      75   [ #  #  #  #  :          0 :     LogPrintf("%s: %s\n", caption, message);
                   #  # ]
      76                 :          0 :     return false;
      77                 :          0 : }
      78                 :            : 
      79                 :          0 : void noui_InitMessageRedirect(const std::string& message)
      80                 :            : {
      81   [ #  #  #  #  :          0 :     LogPrintf("init message: %s\n", message);
                   #  # ]
      82                 :          0 : }
      83                 :            : 
      84                 :          0 : void noui_test_redirect()
      85                 :            : {
      86                 :          0 :     noui_ThreadSafeMessageBoxConn.disconnect();
      87                 :          0 :     noui_ThreadSafeQuestionConn.disconnect();
      88                 :          0 :     noui_InitMessageConn.disconnect();
      89   [ #  #  #  # ]:          0 :     noui_ThreadSafeMessageBoxConn = uiInterface.ThreadSafeMessageBox_connect(noui_ThreadSafeMessageBoxRedirect);
      90   [ #  #  #  # ]:          0 :     noui_ThreadSafeQuestionConn = uiInterface.ThreadSafeQuestion_connect(noui_ThreadSafeQuestionRedirect);
      91   [ #  #  #  # ]:          3 :     noui_InitMessageConn = uiInterface.InitMessage_connect(noui_InitMessageRedirect);
      92                 :          0 : }
      93                 :            : 
      94                 :          0 : void noui_reconnect()
      95                 :            : {
      96                 :          0 :     noui_ThreadSafeMessageBoxConn.disconnect();
      97                 :          0 :     noui_ThreadSafeQuestionConn.disconnect();
      98                 :          0 :     noui_InitMessageConn.disconnect();
      99                 :          3 :     noui_connect();
     100                 :          0 : }

Generated by: LCOV version 1.16