PityTest11 is a very flexible C++11 peer-to-peer test framework supporting hierarchically structured test suites, multi-processing, logging, IPC, synchronization and more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.2 KiB

  1. // This file is under GNU General Public License 3.0
  2. // see LICENSE.txt
  3. #ifndef PITYTEST_PITYUNIT_HH
  4. #define PITYTEST_PITYUNIT_HH
  5. #include <pEp/pEpLog.hh>
  6. #include <pEp/std_utils.hh>
  7. #include "AbstractPityUnit.hh"
  8. #include "fs_mutex.hh"
  9. #include "PityTransport.hh"
  10. #include <string>
  11. #include <memory>
  12. #include <functional>
  13. namespace pEp {
  14. namespace PityTest11 {
  15. //TODO We need a context basetype
  16. class PityBaseCTX {
  17. };
  18. template<class TestContext = PityBaseCTX>
  19. class PityUnit : public AbstractPityUnit {
  20. public:
  21. // Test success if TestFunction:
  22. // * does not throw
  23. // * returns 0
  24. using TestFunction = std::function<int(PityUnit<TestContext>&, TestContext*)>;
  25. // Constructors
  26. PityUnit() = delete;
  27. explicit PityUnit<TestContext>(
  28. const std::string& name,
  29. TestFunction test_func = nullptr,
  30. TestContext* ctx = nullptr,
  31. ExecutionMode exec_mode = ExecutionMode::FUNCTION);
  32. explicit PityUnit<TestContext>(
  33. AbstractPityUnit& parent,
  34. const std::string& name,
  35. TestFunction test_func = nullptr,
  36. TestContext* ctx = nullptr,
  37. ExecutionMode exec_mode = ExecutionMode::FUNCTION);
  38. PityUnit<TestContext>(const PityUnit<TestContext>& rhs);
  39. // copy-assign
  40. PityUnit<TestContext>& operator=(const PityUnit<TestContext>& rhs);
  41. PityUnit<TestContext>* getSelf() override;
  42. // clone
  43. PityUnit<TestContext>* clone() override;
  44. void setContext(TestContext* ctx);
  45. void setContext(TestContext ctx);
  46. TestContext* getContext() const;
  47. protected:
  48. void _runSelf() override;
  49. private:
  50. void _copyContext(const PityUnit<TestContext>& rhs);
  51. // Fields
  52. // nullptr if inherited
  53. TestContext* _ctx;
  54. std::shared_ptr<TestContext> _owned_ctx; // if you copy
  55. TestFunction _test_func;
  56. };
  57. }; // namespace PityTest11
  58. }; // namespace pEp
  59. #include "PityUnit.hxx"
  60. #endif // PITYTEST_PITYUNIT_HH