tests.inc 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. static
  2. YSI_g_sValue;
  3. hook OnRconCommand00(cmd[])
  4. {
  5. // We test using OnRconCommand because it is the least likely to cause
  6. // problems when called unexpectedly at mode start. Other callbacks use
  7. // players and probably expect that player to be connected.
  8. ++YSI_g_sValue;
  9. return YSI_g_sValue;
  10. }
  11. hook OnRconCommand01(cmd[])
  12. {
  13. // Called second due to forced orderings.
  14. ++YSI_g_sValue;
  15. return 1;
  16. }
  17. public OnRconCommand(cmd[])
  18. {
  19. // Called second due to forced orderings.
  20. if (YSI_g_sValue) return YSI_g_sValue - 7;
  21. #if defined y_hooks_OnRconCommand
  22. return y_hooks_OnRconCommand(cmd);
  23. #else
  24. return 1;
  25. #endif
  26. }
  27. #if defined _ALS_OnRconCommand
  28. #undef OnRconCommand
  29. #else
  30. #define _ALS_OnRconCommand
  31. #endif
  32. #define OnRconCommand y_hooks_OnRconCommand
  33. #if defined y_hooks_OnRconCommand
  34. forward OnRconCommand(cmd[]);
  35. #endif
  36. Test:y_hooks_OnRconCommand()
  37. {
  38. // Check both hooks are called.
  39. YSI_g_sValue = 0;
  40. call OnRconCommand("IGNORE_ME");
  41. ASSERT(YSI_g_sValue == 2);
  42. YSI_g_sValue = 0;
  43. }
  44. Test:y_hooks_ReturnM1()
  45. {
  46. // Using -1 as a return should stop all processing.
  47. YSI_g_sValue = -2;
  48. new
  49. ret = call OnRconCommand("IGNORE_ME");
  50. ASSERT(ret == 0);
  51. ASSERT(YSI_g_sValue == -1);
  52. YSI_g_sValue = 0;
  53. }
  54. Test:y_hooks_ReturnM2()
  55. {
  56. // Using -1 as a return should stop all processing.
  57. YSI_g_sValue = -3;
  58. new
  59. ret = call OnRconCommand("IGNORE_ME");
  60. ASSERT(ret == -1);
  61. ASSERT(YSI_g_sValue == -2);
  62. YSI_g_sValue = 0;
  63. }
  64. Test:y_hooks_Callback()
  65. {
  66. // Using -1 as a return should stop all processing.
  67. YSI_g_sValue = 10;
  68. new
  69. ret = call OnRconCommand("IGNORE_ME");
  70. ASSERT(ret == 5);
  71. ASSERT(YSI_g_sValue == 12);
  72. YSI_g_sValue = 0;
  73. }