Test.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "../../DFPSR/includeFramework.h"
  2. struct TestContext;
  3. using DrawContextCallback = std::function<void(dsr::AlignedImageRgbaU8 &canvas, TestContext &context)>;
  4. using MouseContextCallback = std::function<void(const dsr::MouseEvent &event, TestContext &context)>;
  5. using KeyboardContextCallback = std::function<void(const dsr::KeyboardEvent &event, TestContext &context)>;
  6. enum class Grade {
  7. Waiting,
  8. Passed,
  9. Skipped,
  10. Failed
  11. };
  12. dsr::String& string_toStreamIndented(dsr::String& target, const Grade& grade, const dsr::ReadableString& indentation);
  13. struct Test {
  14. dsr::String name;
  15. DrawContextCallback drawEvent;
  16. MouseContextCallback mouseCallback;
  17. KeyboardContextCallback keyboardCallback;
  18. bool activeDrawing;
  19. Grade result = Grade::Waiting;
  20. Test(const dsr::ReadableString& name, const DrawContextCallback &drawEvent, const MouseContextCallback &mouseCallback, const KeyboardContextCallback &keyboardCallback, bool activeDrawing)
  21. : name(name), drawEvent(drawEvent), mouseCallback(mouseCallback), keyboardCallback(keyboardCallback), activeDrawing(activeDrawing) {}
  22. };
  23. struct TestContext {
  24. dsr::List<Test> tests;
  25. // Each test consists of one or more tasks to pass.
  26. int testIndex = 0; // Each test index refers to a Test in tests to be completed.
  27. int taskIndex = 0; // To avoid cluttering the summary with lots of small tests, tests are divided into smaller tasks.
  28. // Call when completing a task but not a whole test.
  29. void passTask();
  30. // Call when completing a test.
  31. void finishTest(Grade result);
  32. void drawAides(dsr::AlignedImageRgbaU8 &canvas);
  33. bool leftMouseDown = false;
  34. bool middleMouseDown = false;
  35. bool rightMouseDown = false;
  36. dsr::IVector2D lastPosition;
  37. TestContext() {}
  38. };