-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
113 lines (88 loc) · 2.95 KB
/
test.cpp
File metadata and controls
113 lines (88 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// -------------------------------------------------------------------------- //
#include <cstdlib> // needed for MACROS
#include <sstream> // needed for std::stringstream
#include <iostream> // needed for std::cout, std::endl
#include "include/Server.hpp" // needed for Server class
#define GREEN "\033[32m"
#define RESET "\033[0m"
/* Past test cases */
// log("Appending some content to UserBuffer");
// log("Adding channels to server");
// log("Listing Channels");
// log("Erasing and listing channel");
// log("ChannelInfo");
// log("Adding Users to channel");
// log("Erasing User from Channel");
// log("Erasing User from Server who is part of a Channel");
Server s;
static inline void log(std::string const& message)
{
std::cerr << GREEN << "\n>> " << message << " <<" << RESET << std::endl;
}
void t_incoming_message(std::string const& message, int socket){
s.parseIncomingMessage(message.c_str(), socket);
}
void t_command(std::string const& message, int socket){
log("TESTING COMMAND");
s.parseIncomingMessage(message.c_str(), socket);
s.sendMessages(socket);
}
void t_show_users(size_t no_users){
log("LISTING USERS");
for (size_t socket = 1; socket <= no_users; ++socket){
std::cout << s.um.getNickname(socket)
<< "(" << s.um.getUsername(socket) << ")";
if (socket != no_users){
std::cout << ", ";
}
}
std::cout << std::endl;
}
void t_connect(std::string const& username,
std::string const& nickname,
int socket){
std::stringstream ss;
ss << socket;
log("ADDING USER/CLIENT TO SOCKET #" + ss.str());
s.um.addUser(socket);
std::string msg = "NICK " + nickname + "\r\n";
std::string msg2 = "USER " + username + "\r\n";
t_incoming_message(msg.c_str(), socket);
t_incoming_message(msg2.c_str(), socket);
s.sendMessages(socket);
}
void t_bool(bool is, std::string const& message){
if (is == true){
std::cout << message << " is true!" << std::endl;
}
else{
std::cout << message << " is false!" << std::endl;
}
}
void t_populate_channel(){
s.um.addChannel("a1");
Channel * a1 = s.um.getChannel("a1");
a1->setPassword("123");
a1->toggleChannelKey();
s.um.addChannel("b2");
s.um.addChannel("c3");
}
void t_show_channel(){
log("LISTING CHANNELS");
std::cout << "\nChannelnames: " << s.um.getChannelNames() << std::endl;
}
int main(void)
{
/* USAGE: */
/* t_command(<full_message>, socket) <-- needs \r\n */
int no_users = 0;
t_connect("Dummy-User", "Dummy-Nick", ++no_users);
t_connect("Test-User", "Test-Nick", ++no_users);
t_connect("Foo-User", "Foo-Nick", ++no_users);
t_show_users(no_users);
t_populate_channel();
t_show_channel();
t_command("JOIN #abc 123\r\n", 1);
return (EXIT_SUCCESS);
}
// -------------------------------------------------------------------------- //