apptests.h raw

   1  // Copyright (c) 2018-present The Bitcoin Core developers
   2  // Distributed under the MIT software license, see the accompanying
   3  // file COPYING or http://www.opensource.org/licenses/mit-license.php.
   4  
   5  #ifndef BITCOIN_QT_TEST_APPTESTS_H
   6  #define BITCOIN_QT_TEST_APPTESTS_H
   7  
   8  #include <QObject>
   9  #include <set>
  10  #include <string>
  11  #include <utility>
  12  
  13  class BitcoinApplication;
  14  class BitcoinGUI;
  15  class RPCConsole;
  16  
  17  class AppTests : public QObject
  18  {
  19      Q_OBJECT
  20  public:
  21      explicit AppTests(BitcoinApplication& app) : m_app(app) {}
  22  
  23  private Q_SLOTS:
  24      void appTests();
  25      void guiTests(BitcoinGUI* window);
  26      void consoleTests(RPCConsole* console);
  27  
  28  private:
  29      //! Add expected callback name to list of pending callbacks.
  30      void expectCallback(std::string callback) { m_callbacks.emplace(std::move(callback)); }
  31  
  32      //! RAII helper to remove no-longer-pending callback.
  33      struct HandleCallback
  34      {
  35          std::string m_callback;
  36          AppTests& m_app_tests;
  37          ~HandleCallback();
  38      };
  39  
  40      //! Bitcoin application.
  41      BitcoinApplication& m_app;
  42  
  43      //! Set of pending callback names. Used to track expected callbacks and shut
  44      //! down the app after the last callback has been handled and all tests have
  45      //! either run or thrown exceptions. This could be a simple int counter
  46      //! instead of a set of names, but the names might be useful for debugging.
  47      std::multiset<std::string> m_callbacks;
  48  };
  49  
  50  #endif // BITCOIN_QT_TEST_APPTESTS_H
  51