CFactionTest.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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_METHOD4(registarCb, void(int32_t, 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 = [this](auto && PH1, auto && PH2, auto && PH3, auto && PH4)
  37. {
  38. registarCb(std::forward<decltype(PH1)>(PH1), std::forward<decltype(PH2)>(PH2), std::forward<decltype(PH3)>(PH3), std::forward<decltype(PH4)>(PH4));
  39. };
  40. subject->registerIcons(cb);
  41. }
  42. TEST_F(CFactionTest, RegistersIcons)
  43. {
  44. auto cb = [this](auto && PH1, auto && PH2, auto && PH3, auto && PH4)
  45. {
  46. registarCb(std::forward<decltype(PH1)>(PH1), std::forward<decltype(PH2)>(PH2), std::forward<decltype(PH3)>(PH3), std::forward<decltype(PH4)>(PH4));
  47. };
  48. subject->town = new CTown();
  49. CTown::ClientInfo & info = subject->town->clientInfo;
  50. info.icons[0][0] = 10;
  51. info.icons[0][1] = 11;
  52. info.icons[1][0] = 12;
  53. info.icons[1][1] = 13;
  54. info.iconLarge[0][0] = "Test1";
  55. info.iconLarge[0][1] = "Test2";
  56. info.iconLarge[1][0] = "Test3";
  57. info.iconLarge[1][1] = "Test4";
  58. info.iconSmall[0][0] = "Test10";
  59. info.iconSmall[0][1] = "Test20";
  60. info.iconSmall[1][0] = "Test30";
  61. info.iconSmall[1][1] = "Test40";
  62. info.towerIconSmall = "Test5";
  63. info.towerIconLarge = "Test6";
  64. EXPECT_CALL(*this, registarCb(Eq(10), Eq(0), "ITPT", "Test1"));
  65. EXPECT_CALL(*this, registarCb(Eq(11), Eq(0), "ITPT", "Test2"));
  66. EXPECT_CALL(*this, registarCb(Eq(12), Eq(0), "ITPT", "Test3"));
  67. EXPECT_CALL(*this, registarCb(Eq(13), Eq(0), "ITPT", "Test4"));
  68. EXPECT_CALL(*this, registarCb(Eq(12), Eq(0), "ITPA", "Test10"));
  69. EXPECT_CALL(*this, registarCb(Eq(13), Eq(0), "ITPA", "Test20"));
  70. EXPECT_CALL(*this, registarCb(Eq(14), Eq(0), "ITPA", "Test30"));
  71. EXPECT_CALL(*this, registarCb(Eq(15), Eq(0), "ITPA", "Test40"));
  72. EXPECT_CALL(*this, registarCb(Eq(subject->getIconIndex()), Eq(1), "CPRSMALL", "Test5"));
  73. EXPECT_CALL(*this, registarCb(Eq(subject->getIconIndex()), Eq(1), "TWCRPORT", "Test6"));
  74. subject->registerIcons(cb);
  75. }
  76. }