hook.cpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include "hook.h"
  2. namespace {
  3. NTesting::THook* BeforeInitHead = nullptr;
  4. NTesting::THook* BeforeRunHead = nullptr;
  5. NTesting::THook* AfterRunHead = nullptr;
  6. void RegisterHook(NTesting::THook*& head, NTesting::THook* hook) {
  7. hook->Next = head;
  8. head = hook;
  9. }
  10. void CallHooks(NTesting::THook* head) {
  11. while (nullptr != head) {
  12. if (nullptr != head->Fn) {
  13. (*head->Fn)();
  14. }
  15. head = head->Next;
  16. }
  17. }
  18. }
  19. void NTesting::THook::RegisterBeforeInit(NTesting::THook* hook) noexcept {
  20. RegisterHook(BeforeInitHead, hook);
  21. }
  22. void NTesting::THook::CallBeforeInit() {
  23. CallHooks(BeforeInitHead);
  24. }
  25. void NTesting::THook::RegisterBeforeRun(NTesting::THook* hook) noexcept {
  26. RegisterHook(BeforeRunHead, hook);
  27. }
  28. void NTesting::THook::CallBeforeRun() {
  29. CallHooks(BeforeRunHead);
  30. }
  31. void NTesting::THook::RegisterAfterRun(NTesting::THook* hook) noexcept {
  32. RegisterHook(AfterRunHead, hook);
  33. }
  34. void NTesting::THook::CallAfterRun() {
  35. CallHooks(AfterRunHead);
  36. }