GameEventsTest.cc 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include <fcntl.h>
  2. #include <fstream>
  3. #include <gtest/gtest.h>
  4. #include <gflags/gflags.h>
  5. #include <glog/logging.h>
  6. #include <google/protobuf/text_format.h>
  7. #include "Event/GameEvents.h"
  8. #include "Event/NodeFactories.h"
  9. #include "Event/EventConf.pb.h"
  10. #include "Event/SpellBuff.h"
  11. #include "Event/CombatContex.h"
  12. namespace Egametang {
  13. class GameEventsTest: public testing::Test
  14. {
  15. protected:
  16. NodeFactories factories;
  17. GameEvents game_events;
  18. public:
  19. GameEventsTest():factories(), game_events(factories)
  20. {
  21. }
  22. virtual ~GameEventsTest()
  23. {
  24. }
  25. };
  26. static void FileToString(const std::string& file, std::string& string)
  27. {
  28. std::ifstream in(file.c_str());
  29. std::ostringstream os;
  30. os << in.rdbuf();
  31. string = os.str();
  32. in.close();
  33. }
  34. TEST_F(GameEventsTest, DotChangeHealth)
  35. {
  36. std::string file = "../Cpp/Game/Event/DotFirstDamage.txt";
  37. std::string string;
  38. FileToString(file, string);
  39. EventConf conf;
  40. google::protobuf::TextFormat::ParseFromString(string, &conf);
  41. game_events.AddEvent(conf);
  42. Unit caster;
  43. Unit victim;
  44. caster.health = 1000;
  45. victim.health = 2000;
  46. Spell spell;
  47. Buff buff;
  48. spell.caster = &caster;
  49. spell.victim = &victim;
  50. CombatContex contex(&spell, &buff);
  51. game_events.Excute(5, &contex);
  52. ASSERT_EQ(2000, victim.health);
  53. buff.buff_type = 2;
  54. game_events.Excute(5, &contex);
  55. ASSERT_EQ(1900, victim.health);
  56. }
  57. } // namespace Egametang
  58. int main(int argc, char* argv[])
  59. {
  60. testing::InitGoogleTest(&argc, argv);
  61. google::ParseCommandLineFlags(&argc, &argv, true);
  62. google::InitGoogleLogging(argv[0]);
  63. return RUN_ALL_TESTS();
  64. }