test_modchannels.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. Minetest
  3. Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #include "test.h"
  17. #include "gamedef.h"
  18. #include "modchannels.h"
  19. class TestModChannels : public TestBase
  20. {
  21. public:
  22. TestModChannels() { TestManager::registerTestModule(this); }
  23. const char *getName() { return "TestModChannels"; }
  24. void runTests(IGameDef *gamedef);
  25. void testJoinChannel(IGameDef *gamedef);
  26. void testLeaveChannel(IGameDef *gamedef);
  27. void testSendMessageToChannel(IGameDef *gamedef);
  28. };
  29. static TestModChannels g_test_instance;
  30. void TestModChannels::runTests(IGameDef *gamedef)
  31. {
  32. TEST(testJoinChannel, gamedef);
  33. TEST(testLeaveChannel, gamedef);
  34. TEST(testSendMessageToChannel, gamedef);
  35. }
  36. void TestModChannels::testJoinChannel(IGameDef *gamedef)
  37. {
  38. // Test join
  39. UASSERT(gamedef->joinModChannel("test_join_channel"));
  40. // Test join (fail, already join)
  41. UASSERT(!gamedef->joinModChannel("test_join_channel"));
  42. }
  43. void TestModChannels::testLeaveChannel(IGameDef *gamedef)
  44. {
  45. // Test leave (not joined)
  46. UASSERT(!gamedef->leaveModChannel("test_leave_channel"));
  47. UASSERT(gamedef->joinModChannel("test_leave_channel"));
  48. // Test leave (joined)
  49. UASSERT(gamedef->leaveModChannel("test_leave_channel"));
  50. }
  51. void TestModChannels::testSendMessageToChannel(IGameDef *gamedef)
  52. {
  53. // Test sendmsg (not joined)
  54. UASSERT(!gamedef->sendModChannelMessage(
  55. "test_sendmsg_channel", "testmsgchannel"));
  56. UASSERT(gamedef->joinModChannel("test_sendmsg_channel"));
  57. // Test sendmsg (joined)
  58. UASSERT(gamedef->sendModChannelMessage("test_sendmsg_channel", "testmsgchannel"));
  59. }