LCOV - code coverage report
Current view: top level - src - noui.cpp (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 10 59 16.9 %
Date: 2023-11-10 23:46:46 Functions: 1 15 6.7 %
Branches: 6 76 7.9 %

           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                 :          2 : boost::signals2::connection noui_ThreadSafeMessageBoxConn;
      19                 :          2 : boost::signals2::connection noui_ThreadSafeQuestionConn;
      20                 :          2 : 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 :         break;
      32                 :            :     case CClientUIInterface::MSG_WARNING:
      33         [ #  # ]:          0 :         strCaption = "Warning: ";
      34                 :          0 :         break;
      35                 :            :     case CClientUIInterface::MSG_INFORMATION:
      36         [ #  # ]:          0 :         strCaption = "Information: ";
      37                 :          0 :         break;
      38                 :            :     default:
      39         [ #  # ]:          0 :         strCaption = caption + ": "; // Use supplied caption (can be empty)
      40                 :          0 :     }
      41                 :            : 
      42         [ #  # ]:          0 :     if (!fSecure) {
      43 [ #  # ][ #  # ]:          0 :         LogPrintf("%s%s\n", strCaption, message.original);
                 [ #  # ]
      44                 :          0 :     }
      45         [ #  # ]:          0 :     tfm::format(std::cerr, "%s%s\n", strCaption, message.original);
      46                 :            :     return false;
      47                 :          0 : }
      48                 :            : 
      49                 :          0 : bool noui_ThreadSafeQuestion(const bilingual_str& /* ignored interactive message */, const std::string& message, const std::string& caption, unsigned int style)
      50                 :            : {
      51 [ #  # ][ #  # ]:          0 :     return noui_ThreadSafeMessageBox(Untranslated(message), caption, style);
      52                 :          0 : }
      53         [ #  # ]:          0 : 
      54                 :          0 : void noui_InitMessage(const std::string& message)
      55                 :            : {
      56 [ #  # ][ #  # ]:          0 :     LogPrintf("init message: %s\n", message);
                 [ #  # ]
      57                 :          0 : }
      58                 :            : 
      59                 :          1 : void noui_connect()
      60                 :            : {
      61 [ +  - ][ +  - ]:          1 :     noui_ThreadSafeMessageBoxConn = uiInterface.ThreadSafeMessageBox_connect(noui_ThreadSafeMessageBox);
      62 [ +  - ][ +  - ]:          1 :     noui_ThreadSafeQuestionConn = uiInterface.ThreadSafeQuestion_connect(noui_ThreadSafeQuestion);
      63 [ +  - ][ -  + ]:          1 :     noui_InitMessageConn = uiInterface.InitMessage_connect(noui_InitMessage);
      64                 :          1 : }
      65                 :            : 
      66                 :          0 : bool noui_ThreadSafeMessageBoxRedirect(const bilingual_str& message, const std::string& caption, unsigned int style)
      67                 :            : {
      68 [ #  # ][ #  # ]:          0 :     LogPrintf("%s: %s\n", caption, message.original);
                 [ #  # ]
      69                 :          0 :     return false;
      70                 :          0 : }
      71                 :            : 
      72                 :          0 : bool noui_ThreadSafeQuestionRedirect(const bilingual_str& /* ignored interactive message */, const std::string& message, const std::string& caption, unsigned int style)
      73                 :            : {
      74 [ #  # ][ #  # ]:          0 :     LogPrintf("%s: %s\n", caption, message);
                 [ #  # ]
      75                 :          0 :     return false;
      76                 :          0 : }
      77                 :            : 
      78                 :          0 : void noui_InitMessageRedirect(const std::string& message)
      79                 :            : {
      80 [ #  # ][ #  # ]:          0 :     LogPrintf("init message: %s\n", message);
                 [ #  # ]
      81                 :          0 : }
      82                 :            : 
      83                 :          0 : void noui_test_redirect()
      84                 :            : {
      85                 :          0 :     noui_ThreadSafeMessageBoxConn.disconnect();
      86                 :          0 :     noui_ThreadSafeQuestionConn.disconnect();
      87                 :          0 :     noui_InitMessageConn.disconnect();
      88 [ #  # ][ #  # ]:          0 :     noui_ThreadSafeMessageBoxConn = uiInterface.ThreadSafeMessageBox_connect(noui_ThreadSafeMessageBoxRedirect);
      89 [ #  # ][ #  # ]:          0 :     noui_ThreadSafeQuestionConn = uiInterface.ThreadSafeQuestion_connect(noui_ThreadSafeQuestionRedirect);
      90 [ #  # ][ #  # ]:          0 :     noui_InitMessageConn = uiInterface.InitMessage_connect(noui_InitMessageRedirect);
      91                 :          2 : }
      92                 :            : 
      93                 :          0 : void noui_reconnect()
      94                 :            : {
      95                 :          0 :     noui_ThreadSafeMessageBoxConn.disconnect();
      96                 :          0 :     noui_ThreadSafeQuestionConn.disconnect();
      97                 :          0 :     noui_InitMessageConn.disconnect();
      98                 :          0 :     noui_connect();
      99                 :          2 : }

Generated by: LCOV version 1.14