diff --git a/src/commands/Kick.cpp b/src/commands/Kick.cpp index bce9227..b074e77 100644 --- a/src/commands/Kick.cpp +++ b/src/commands/Kick.cpp @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* Kick.cpp :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: yde-goes +#+ +:+ +#+ */ +/* By: gilmar +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/21 08:30:47 by gilmar #+# #+# */ -/* Updated: 2024/05/30 13:06:19 by yde-goes ### ########.fr */ +/* Updated: 2024/05/30 16:15:26 by gilmar ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,6 +18,19 @@ * Reference: https://datatracker.ietf.org/doc/html/rfc1459#section-4.2.8 */ +/* + * Cenários de Teste: + * 1. O comando KICK é recebido sem parâmetros suficientes. + * 2. O comando KICK é recebido e o canal não existe. + * 3. O comando KICK é recebido e o cliente não está no canal. + * 4. O comando KICK é recebido e o cliente não é um operador do canal. + * 5. O comando KICK é recebido e o cliente alvo não existe. + * 6. O comando KICK é recebido e o cliente alvo não está no canal. + * 7. O comando KICK é recebido e o cliente é expulso do canal com sucesso. + * 8. O comando KICK é recebido e o cliente é expulso do canal com sucesso e um comentário é enviado. + * +*/ + /** * @brief Handles the KICK command received from the client. * diff --git a/src/commands/Mode.cpp b/src/commands/Mode.cpp index df8ae05..b3ae584 100644 --- a/src/commands/Mode.cpp +++ b/src/commands/Mode.cpp @@ -6,7 +6,7 @@ /* By: gilmar +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/21 08:30:34 by gilmar #+# #+# */ -/* Updated: 2024/05/28 22:01:53 by gilmar ### ########.fr */ +/* Updated: 2024/05/30 17:00:18 by gilmar ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,6 +20,16 @@ * Reference: https://datatracker.ietf.org/doc/html/rfc1459#section-4.2.3 */ +/* + * Cenários de Teste: + * 1. O comando MODE é recebido sem parâmetros suficientes. + * 2. O comando MODE é recebido e o canal não existe. + * 3. O comando MODE é recebido e o cliente não tem privilégios de operador no canal. + * 4. O comando MODE é recebido e o cliente tem privilégios de operador no canal. + * 5. O comando MODE é recebido e o modo do canal é alterado com sucesso. + * +*/ + /** * @brief Handles the MODE command received from the client. * diff --git a/src/commands/Part.cpp b/src/commands/Part.cpp index 09b77c0..66c3e03 100644 --- a/src/commands/Part.cpp +++ b/src/commands/Part.cpp @@ -6,7 +6,7 @@ /* By: gilmar +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/21 08:30:20 by gilmar #+# #+# */ -/* Updated: 2024/05/26 11:52:13 by gilmar ### ########.fr */ +/* Updated: 2024/05/30 17:00:05 by gilmar ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,6 +18,14 @@ * Link: https://datatracker.ietf.org/doc/html/rfc1459#section-4.2.2 */ +/* + * Test Cases: + * 1. The PART command is received without enough parameters. + * 2. The PART command is received and the channel does not exist. + * 3. The PART command is received and the client is not in the channel. + * 4. The PART command is received and the client leaves the channel successfully. +*/ + /** * @brief Handles the PART command received from the client. * diff --git a/src/commands/User.cpp b/src/commands/User.cpp index be3e1e6..30c643b 100644 --- a/src/commands/User.cpp +++ b/src/commands/User.cpp @@ -6,21 +6,18 @@ /* By: gilmar +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/21 08:32:16 by gilmar #+# #+# */ -/* Updated: 2024/05/30 15:19:14 by gilmar ### ########.fr */ +/* Updated: 2024/05/30 16:47:25 by gilmar ### ########.fr */ /* */ /* ************************************************************************** */ #include "Server.hpp" -#define USER_CMD "USER" - /* * Command: USER * Parameters: * Link: https://datatracker.ietf.org/doc/html/rfc1459#section-4.1.3 */ - /* * Cenários de Teste: * 1. O comando USER é recebido sem parâmetros suficientes. diff --git a/tests/Makefile b/tests/Makefile index ebbcd49..c4db1e3 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,6 +1,6 @@ # Insert the test rules here TESTS := user nick invite join kick part topic privmsg quit -TESTS += marvinbot +TESTS += marvinbot mode CYAN := \33[1;36m RESET := \033[0m @@ -75,6 +75,10 @@ quit: $(OBJS) TestQuit.cpp marvinbot: $(OBJS) TestMarvinBot.cpp @$(call run, "$^") +.PHONY: mode +mode: $(OBJS) TestMode.cpp + @$(call run, "$^") + # Insert the test rules here, follwing the example above. # Makefile rules to clean stdin/stdout/stderr test's files diff --git a/tests/TestMode.cpp b/tests/TestMode.cpp new file mode 100644 index 0000000..6423546 --- /dev/null +++ b/tests/TestMode.cpp @@ -0,0 +1,12 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* TestMode.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gilmar +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/05/30 16:51:31 by gilmar #+# #+# */ +/* Updated: 2024/05/30 16:59:55 by gilmar ### ########.fr */ +/* */ +/* ************************************************************************** */ + diff --git a/tests/TestNick.cpp b/tests/TestNick.cpp index 6e07a16..97ef00c 100644 --- a/tests/TestNick.cpp +++ b/tests/TestNick.cpp @@ -6,7 +6,7 @@ /* By: gilmar +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/24 18:03:34 by yde-goes #+# #+# */ -/* Updated: 2024/05/30 16:06:39 by gilmar ### ########.fr */ +/* Updated: 2024/05/30 16:48:25 by gilmar ### ########.fr */ /* */ /* ************************************************************************** */ @@ -183,7 +183,6 @@ Test(NickCommand, success_readytologin) Server server; server._clients.push_back(*client); - server._handler_client_username("Username", 4); server._handler_client_nickname("Nickname", 4); cr_assert(eq(int, server._reply_code, 001)); } diff --git a/tests/TestUser.cpp b/tests/TestUser.cpp index ec04408..8ad2712 100644 --- a/tests/TestUser.cpp +++ b/tests/TestUser.cpp @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* TestUser.cpp :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: yde-goes +#+ +:+ +#+ */ +/* By: gilmar +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/05/24 18:03:11 by yde-goes #+# #+# */ -/* Updated: 2024/05/30 14:55:00 by yde-goes ### ########.fr */ +/* Updated: 2024/05/30 16:53:44 by gilmar ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,19 +17,32 @@ #define private public #include "Server.hpp" +/* + * Cenários de Teste: + * 1. O comando USER é recebido sem parâmetros suficientes. + * 2. O comando USER é recebido e o cliente não está registrado. + * 3. O comando USER é recebido e o cliente já está registrado. + * 4. O comando USER é recebido e o cliente está pronto para fazer login. + * 5. O comando USER é recebido e o cliente não está pronto para fazer login. + * +*/ + Client *mockClient() { Client *client = new Client(); client->set_fd(4); - client->set_username("username"); - client->set_nickname("oldNickname"); - client->set_password("password"); - client->set_buffer("USER new_username"); + client->set_username("Username"); + client->set_nickname("Nickname"); + client->set_password("Password"); + client->set_buffer("USER Username"); client->set_is_logged(true); client->set_is_authenticated(true); return client; } +/* + * 1. O comando USER é recebido sem parâmetros suficientes. +*/ Test(UserCommand, err_needmoreparams) { Client* client = mockClient(); @@ -38,9 +51,12 @@ Test(UserCommand, err_needmoreparams) server._clients.push_back(*client); server._handler_client_username("", 4); - cr_assert(eq(int, server._reply_code, 461)); // Assuming 461 is the reply code for ERR_NEEDMOREPARAMS + cr_assert(eq(int, server._reply_code, 461)); } +/* + * 2. O comando USER é recebido e o cliente não está registrado. +*/ Test(UserCommand, err_notregistered) { Client* client = mockClient(); @@ -50,58 +66,55 @@ Test(UserCommand, err_notregistered) Server server; server._clients.push_back(*client); - server._handler_client_username("new_username", 4); - cr_assert(eq(int, server._reply_code, 451)); // Assuming 451 is the reply code for ERR_NOTREGISTERED + server._handler_client_username(client->get_username(), 4); + cr_assert(eq(int, server._reply_code, 451)); } -Test(UserCommand, success_setusername_1) +/* + * 3. O comando USER é recebido e o cliente já está registrado. +*/ +Test(UserCommand, err_alreadyregistered) { Client* client = mockClient(); - client->set_username(""); Server server; server._clients.push_back(*client); - server._handler_client_username("new_username", 4); - cr_assert(eq(int, server._reply_code, 200)); // Assuming 200 is the reply code for a successful username change + server._handler_client_username(client->get_username(), 4); + cr_assert(eq(int, server._reply_code, 462)); } -Test(UserCommand, success_setusername_2) +/* + * 4. O comando USER é recebido e o cliente está pronto para fazer login. +*/ +Test(UserCommand, success_readytologin) { Client* client = mockClient(); - client->set_username("withUsername"); + client->set_username(""); + client->set_is_authenticated(true); + client->set_is_logged(false); Server server; server._clients.push_back(*client); - server._handler_client_username("newUsername", 4); - cr_assert(eq(int, server._reply_code, 462)); // Assuming 200 is the reply code for a successful username change + server._handler_client_username("Username", 4); + cr_assert(eq(int, server._reply_code, 001)); } -Test(UserCommand, err_alreadyregistered) +/* + * 5. O comando USER é recebido e o cliente não está pronto para fazer login. +*/ +Test(UserCommand, success_notreadytologin) { Client* client = mockClient(); + client->set_username(""); + client->set_nickname(""); + client->set_is_authenticated(true); + client->set_is_logged(false); Server server; server._clients.push_back(*client); - server._handler_client_username("username", 4); - cr_assert(eq(int, server._reply_code, 462)); // Assuming 462 is the reply code for ERR_ALREADYREGISTERED + server._handler_client_username("Username", 4); + cr_assert(eq(int, server._reply_code, 200)); } - - -/* -Using the opened tabs as context, write 8 unit tests using criterion framework, one for each of the following criteria: - -The USER command is received without sufficient parameters. -The USER command is received and the client is not registered. -The USER command is received and the client is already registered. -The USER command is received and the client is ready to log in. -The USER command is received and the client is not ready to log in. -The USER command is received and the client is already logged in. -The USER command is received and the client is not authenticated. -The USER command is received and the client is authenticated. -*/ - - -