CFactionTest.cpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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/entities/faction/CTown.h"
  12. #include "../../lib/entities/faction/CFaction.h"
  13. namespace test
  14. {
  15. using namespace ::testing;
  16. class CFactionTest : public Test
  17. {
  18. public:
  19. MOCK_METHOD4(registarCb, void(int32_t, int32_t, const std::string &, const std::string &));
  20. protected:
  21. std::shared_ptr<CFaction> subject;
  22. void SetUp() override
  23. {
  24. subject = std::make_shared<CFaction>();
  25. }
  26. };
  27. TEST_F(CFactionTest, HasTown)
  28. {
  29. EXPECT_FALSE(subject->hasTown());
  30. subject->town = new CTown();
  31. EXPECT_TRUE(subject->hasTown());
  32. vstd::clear_pointer(subject->town);
  33. EXPECT_FALSE(subject->hasTown());
  34. }
  35. TEST_F(CFactionTest, RegistersNoIconsIfNoTown)
  36. {
  37. auto cb = [this](auto && PH1, auto && PH2, auto && PH3, auto && PH4)
  38. {
  39. registarCb(std::forward<decltype(PH1)>(PH1), std::forward<decltype(PH2)>(PH2), std::forward<decltype(PH3)>(PH3), std::forward<decltype(PH4)>(PH4));
  40. };
  41. subject->registerIcons(cb);
  42. }
  43. TEST_F(CFactionTest, RegistersIcons)
  44. {
  45. auto cb = [this](auto && PH1, auto && PH2, auto && PH3, auto && PH4)
  46. {
  47. registarCb(std::forward<decltype(PH1)>(PH1), std::forward<decltype(PH2)>(PH2), std::forward<decltype(PH3)>(PH3), std::forward<decltype(PH4)>(PH4));
  48. };
  49. subject->town = new CTown();
  50. CTown::ClientInfo & info = subject->town->clientInfo;
  51. info.icons[0][0] = 10;
  52. info.icons[0][1] = 11;
  53. info.icons[1][0] = 12;
  54. info.icons[1][1] = 13;
  55. info.iconLarge[0][0] = "Test1";
  56. info.iconLarge[0][1] = "Test2";
  57. info.iconLarge[1][0] = "Test3";
  58. info.iconLarge[1][1] = "Test4";
  59. info.iconSmall[0][0] = "Test10";
  60. info.iconSmall[0][1] = "Test20";
  61. info.iconSmall[1][0] = "Test30";
  62. info.iconSmall[1][1] = "Test40";
  63. info.towerIconSmall = "Test5";
  64. info.towerIconLarge = "Test6";
  65. EXPECT_CALL(*this, registarCb(Eq(10), Eq(0), "ITPT", "Test1"));
  66. EXPECT_CALL(*this, registarCb(Eq(11), Eq(0), "ITPT", "Test2"));
  67. EXPECT_CALL(*this, registarCb(Eq(12), Eq(0), "ITPT", "Test3"));
  68. EXPECT_CALL(*this, registarCb(Eq(13), Eq(0), "ITPT", "Test4"));
  69. EXPECT_CALL(*this, registarCb(Eq(12), Eq(0), "ITPA", "Test10"));
  70. EXPECT_CALL(*this, registarCb(Eq(13), Eq(0), "ITPA", "Test20"));
  71. EXPECT_CALL(*this, registarCb(Eq(14), Eq(0), "ITPA", "Test30"));
  72. EXPECT_CALL(*this, registarCb(Eq(15), Eq(0), "ITPA", "Test40"));
  73. EXPECT_CALL(*this, registarCb(Eq(subject->getIconIndex()), Eq(1), "CPRSMALL", "Test5"));
  74. EXPECT_CALL(*this, registarCb(Eq(subject->getIconIndex()), Eq(1), "TWCRPORT", "Test6"));
  75. subject->registerIcons(cb);
  76. }
  77. }