2
0

ERMPersistenceTest.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * ERMPersistenceTest.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "../scripting/ScriptFixture.h"
  12. namespace test
  13. {
  14. using namespace ::testing;
  15. using namespace ::scripting;
  16. class ERMPersistenceTest : public Test, public ScriptFixture
  17. {
  18. public:
  19. ERMPersistenceTest()
  20. : ScriptFixture()
  21. {
  22. }
  23. protected:
  24. void SetUp() override
  25. {
  26. ScriptFixture::setUp();
  27. }
  28. };
  29. TEST_F(ERMPersistenceTest, Empty)
  30. {
  31. std::stringstream source;
  32. source << "VERM" << std::endl;
  33. source << "!#VRj:S2;" << std::endl;
  34. loadScript(VLC->scriptHandler->erm, source.str());
  35. JsonNode actualState = runClientServer();
  36. SCOPED_TRACE("\n" + subject->code);
  37. JsonNode state;
  38. state["ERM"]["Q"]["j"].Float() = 2;
  39. state["ERM"]["instructionsCalled"].Bool() = true;
  40. JsonComparer c(false);
  41. c.compare("state", actualState, state);
  42. }
  43. TEST_F(ERMPersistenceTest, QuickVar)
  44. {
  45. const int VALUE = 5678;
  46. JsonNode state;
  47. state["foo"].String() = "foo";
  48. state["ERM"]["Q"]["m"].Integer() = VALUE;
  49. std::stringstream source;
  50. source << "VERM" << std::endl;
  51. source << "!#VRm:+2;" << std::endl;
  52. loadScript(VLC->scriptHandler->erm, source.str());
  53. JsonNode actualState = runClientServer(state);
  54. SCOPED_TRACE("\n" + subject->code);
  55. state["ERM"]["Q"]["m"].Float() = VALUE + 2;
  56. state["ERM"]["instructionsCalled"].Bool() = true;
  57. JsonComparer c(false);
  58. c.compare("state", actualState, state);
  59. }
  60. TEST_F(ERMPersistenceTest, RegularVar)
  61. {
  62. const int VALUE = 4242;
  63. JsonNode state;
  64. state["ERM"]["v"]["57"].Integer() = VALUE;
  65. std::stringstream builder;
  66. builder << "VERM" << std::endl;
  67. builder << "!#VRv57:-28;" << std::endl;
  68. loadScript(VLC->scriptHandler->erm, builder.str());
  69. JsonNode actualState = runClientServer(state);
  70. SCOPED_TRACE("\n" + subject->code);
  71. state["ERM"]["v"]["57"].Float() = VALUE - 28;
  72. state["ERM"]["instructionsCalled"].Bool() = true;
  73. JsonComparer c(false);
  74. c.compare("state", actualState, state);
  75. }
  76. }