squad_sense_test.cpp 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include <array>
  2. #include <cassert>
  3. #include "../Sunrise/src/server/activity/mission/mission_script_squad_sense.h"
  4. int main() {
  5. using sunrise::middleware::bap::activity_message::sense_update::DecodedValue;
  6. using sunrise::server::activity::mission::read_squad_alive;
  7. using namespace sunrise::server::activity::mission;
  8. std::array<std::int32_t, 8> consumed{};
  9. std::array<DecodedValue, 4> accounting{};
  10. accounting[0].schemaRow = 0x80807ECF;
  11. accounting[0].unsignedValue = 2;
  12. accounting[1].schemaRow = accounting[2].schemaRow = 0x80809491;
  13. accounting[1].signedValue = 1;
  14. accounting[2].signedValue = 3;
  15. accounting[2].occurrence = 1;
  16. // A cost value or unrelated field with the same wire width is not accounting.
  17. accounting[3].schemaRow = 0x80807ECD;
  18. accounting[3].width = 32;
  19. accounting[3].signedValue = 999;
  20. assert(read_squad_consumed_counts(accounting, consumed) == 2);
  21. assert(consumed[0] == 1 && consumed[1] == 3 && consumed[2] == 0);
  22. accounting[2].present = false;
  23. assert(read_squad_consumed_counts(accounting, consumed) == 0);
  24. assert(consumed[1] == 3); // Partial/absent accounting must retain the prior level.
  25. accounting[2].present = true;
  26. accounting[2].signedValue = -1;
  27. assert(read_squad_consumed_counts(accounting, consumed) == 0);
  28. SquadObjectiveCosts costs{};
  29. std::array<DecodedValue,2> report{};
  30. report[0].schemaRow=0x80807ECD; report[0].occurrence=2; report[0].realValue=120;
  31. report[1].schemaRow=7; report[1].fieldOrdinal=1; report[1].signedValue=1;
  32. assert(update_squad_objective_costs(costs,report,7));
  33. assert(costs.revision==1 && costs.known==4 && costs.values[2]==120);
  34. assert(!update_squad_objective_costs(costs,report,7));
  35. report[0].present=false; report[0].realValue=0;
  36. assert(!update_squad_objective_costs(costs,report,7) && costs.values[2]==120);
  37. report[0].present=true; report[0].occurrence=24;
  38. assert(!update_squad_objective_costs(costs,report,7));
  39. report[0].occurrence=2; report[0].realValue=2040;
  40. assert(update_squad_objective_costs(costs,report,7) && costs.values[2]==2040);
  41. std::array<DecodedValue, 2> body{};
  42. body[0].schemaRow = 7;
  43. body[0].fieldOrdinal = 3;
  44. body[0].present = false;
  45. std::int32_t alive = 5;
  46. assert(!read_squad_alive({}, 7, alive) && alive == 5);
  47. assert(!read_squad_alive(body, 7, alive) && alive == 5);
  48. body[1].schemaRow = 8; // A present nested field cannot supply the root count.
  49. body[1].fieldOrdinal = 3;
  50. body[1].present = true;
  51. assert(!read_squad_alive(body, 7, alive) && alive == 5);
  52. body[0].present = true;
  53. body[0].signedValue = 4;
  54. assert(read_squad_alive(body, 7, alive) && alive == 4);
  55. body[0].present = false;
  56. body[0].signedValue = 0;
  57. assert(!read_squad_alive(body, 7, alive) && alive == 4);
  58. body[0].present = true;
  59. assert(read_squad_alive(body, 7, alive) && alive == 0);
  60. body[0].signedValue = -1;
  61. assert(!read_squad_alive(body, 7, alive));
  62. body[0].signedValue = 64;
  63. assert(!read_squad_alive(body, 7, alive));
  64. }