Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
CXX = c++
CXXFLAGS = -Wall -Wextra -Werror -std=c++98
OBJDIR = obj
SRCS = $(shell find . -name "*.cpp")
SRCS = $(shell find srcs -name "*.cpp")
OBJS = $(patsubst %.cpp,$(OBJDIR)/%.o,$(SRCS))
NAME = ircserv

Expand All @@ -19,9 +19,16 @@ clean:

fclean: clean
rm -f $(NAME)
$(MAKE) -C tests/bdd fclean

re: fclean all

test:
$(MAKE) -C tests/bdd test

test-valgrind:
$(MAKE) -C tests/bdd test-valgrind

# The following commands are used for containerized builds in the macOS environment.
# Ensure you have the 'container' command available, which is a native macOS Docker,
# realeased in june 2025.
Expand All @@ -43,3 +50,5 @@ container:

container-stop:
container stop --all && container system stop

.PHONY: all clean fclean re test test-valgrind container-build container-run container-shell container container-stop
3 changes: 3 additions & 0 deletions incs/server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ class Server
void addPollFd(const struct pollfd& NewFd);
void addDccServer(DccServer* NewDccServer);
void addDccClient(DccClient* NewDccClient);

// tests only
std::vector<std::string> GetQueuedMessages(int fd) const;
};

#endif
12 changes: 12 additions & 0 deletions srcs/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,18 @@ void Server::SendWelcomeMessage(int fd)
SendToClient(fd, welcomeMsg);
}

// tests only
std::vector<std::string> Server::GetQueuedMessages(int fd) const
{
std::vector<std::string> messages;
std::map<int, std::deque<std::string> >::const_iterator it = outQueues.find(fd);
if (it != outQueues.end()) {
const std::deque<std::string>& queue = it->second;
messages.assign(queue.begin(), queue.end());
}
return messages;
}

Client* Server::FindClientByFd(int fd) {
for (size_t i = 0; i < clients.size(); i++) {
if (clients[i].GetFd() == fd) {
Expand Down
4 changes: 4 additions & 0 deletions tests/bdd/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
test_runner
obj/

valgrind_bdd.log
87 changes: 87 additions & 0 deletions tests/bdd/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
CXX = c++
CXXFLAGS = -Wall -Wextra -Werror -std=c++11
INCLUDES = -I../../incs -I.

PROJECT_CXXFLAGS = -Wall -Wextra -Werror -std=c++98

PROJECT_ROOT = ../..
OBJ_DIR = ../../obj
TEST_OBJ_DIR = obj
STEP_DEFS_DIR = step_definitions
SUPPORT_DIR = support

TEST_RUNNER = test_runner

TEST_SOURCES = main.cpp \
$(STEP_DEFS_DIR)/authentication_steps.cpp \
$(STEP_DEFS_DIR)/message_steps.cpp \
$(STEP_DEFS_DIR)/channel_steps.cpp \
$(SUPPORT_DIR)/test_helpers.cpp

TEST_OBJS = $(patsubst %.cpp,$(TEST_OBJ_DIR)/%.o,$(TEST_SOURCES))

PROJECT_OBJS = $(OBJ_DIR)/srcs/server.o \
$(OBJ_DIR)/srcs/client.o \
$(OBJ_DIR)/srcs/channel.o \
$(OBJ_DIR)/srcs/parsing.o \
$(OBJ_DIR)/srcs/DccServer.o \
$(OBJ_DIR)/srcs/DccClient.o \
$(OBJ_DIR)/srcs/utils/prompt.o \
$(OBJ_DIR)/srcs/commands/PassCommand.o \
$(OBJ_DIR)/srcs/commands/NickCommand.o \
$(OBJ_DIR)/srcs/commands/UserCommand.o \
$(OBJ_DIR)/srcs/commands/JoinCommand.o \
$(OBJ_DIR)/srcs/commands/PartCommand.o \
$(OBJ_DIR)/srcs/commands/KickCommand.o \
$(OBJ_DIR)/srcs/commands/InviteCommand.o \
$(OBJ_DIR)/srcs/commands/TopicCommand.o \
$(OBJ_DIR)/srcs/commands/ModeCommand.o \
$(OBJ_DIR)/srcs/commands/PrivmsgCommand.o

all: $(TEST_RUNNER)

build-project:
@echo "Compilando projeto principal..."
@cd $(PROJECT_ROOT) && $(MAKE)

$(TEST_RUNNER): build-project $(TEST_OBJS)
@echo "Linkando testes..."
$(CXX) $(CXXFLAGS) $(TEST_OBJS) $(PROJECT_OBJS) -o $(TEST_RUNNER)
@echo "✓ Testes compilados com sucesso: $(TEST_RUNNER)"

$(TEST_OBJ_DIR)/%.o: %.cpp
@mkdir -p $(dir $@)
@echo "Compilando teste: $<"
$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@

test: $(TEST_RUNNER)
@echo ""
@echo "================================"
@echo " Executando Testes BDD"
@echo "================================"
@echo ""
./$(TEST_RUNNER)
@echo ""
@echo "================================"
@echo " Testes Concluídos"
@echo "================================"


test-valgrind: $(TEST_RUNNER)
@echo ""
@echo "================================"
@echo " Testes BDD com Valgrind"
@echo "================================"
@bash test_valgrind_bdd.sh

clean:
rm -rf $(TEST_OBJ_DIR)
@echo "✓ Objetos de teste removidos"

fclean: clean
rm -f $(TEST_RUNNER)
@echo "✓ Executável de teste removido"

re: fclean all

.PHONY: all test clean fclean re build-project help test-valgrind
Loading