CFactionTest.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * CFactionTest.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 "../../lib/CTownHandler.h"
  12. namespace test
  13. {
  14. using namespace ::testing;
  15. class CFactionTest : public Test
  16. {
  17. public:
  18. MOCK_METHOD3(registarCb, void(int32_t, const std::string &, const std::string &));
  19. protected:
  20. std::shared_ptr<CFaction> subject;
  21. void SetUp() override
  22. {
  23. subject = std::make_shared<CFaction>();
  24. }
  25. };
  26. TEST_F(CFactionTest, HasTown)
  27. {
  28. EXPECT_FALSE(subject->hasTown());
  29. subject->town = new CTown();
  30. EXPECT_TRUE(subject->hasTown());
  31. vstd::clear_pointer(subject->town);
  32. EXPECT_FALSE(subject->hasTown());
  33. }
  34. TEST_F(CFactionTest, RegistersNoIconsIfNoTown)
  35. {
  36. auto cb = std::bind(&CFactionTest::registarCb, this, _1, _2, _3);
  37. subject->registerIcons(cb);
  38. }
  39. TEST_F(CFactionTest, RegistersIcons)
  40. {
  41. auto cb = std::bind(&CFactionTest::registarCb, this, _1, _2, _3);
  42. subject->town = new CTown();
  43. CTown::ClientInfo & info = subject->town->clientInfo;
  44. info.icons[0][0] = 10;
  45. info.icons[0][1] = 11;
  46. info.icons[1][0] = 12;
  47. info.icons[1][1] = 13;
  48. info.iconLarge[0][0] = "Test1";
  49. info.iconLarge[0][1] = "Test2";
  50. info.iconLarge[1][0] = "Test3";
  51. info.iconLarge[1][1] = "Test4";
  52. info.iconSmall[0][0] = "Test10";
  53. info.iconSmall[0][1] = "Test20";
  54. info.iconSmall[1][0] = "Test30";
  55. info.iconSmall[1][1] = "Test40";
  56. EXPECT_CALL(*this, registarCb(Eq(10), "ITPT", "Test1"));
  57. EXPECT_CALL(*this, registarCb(Eq(11), "ITPT", "Test2"));
  58. EXPECT_CALL(*this, registarCb(Eq(12), "ITPT", "Test3"));
  59. EXPECT_CALL(*this, registarCb(Eq(13), "ITPT", "Test4"));
  60. EXPECT_CALL(*this, registarCb(Eq(12), "ITPA", "Test10"));
  61. EXPECT_CALL(*this, registarCb(Eq(13), "ITPA", "Test20"));
  62. EXPECT_CALL(*this, registarCb(Eq(14), "ITPA", "Test30"));
  63. EXPECT_CALL(*this, registarCb(Eq(15), "ITPA", "Test40"));
  64. subject->registerIcons(cb);
  65. }
  66. }