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