Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Meng jianing #157

Merged
merged 4 commits into from
Mar 3, 2024
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
24 changes: 12 additions & 12 deletions App/bll_polychat.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,53 +42,53 @@ static QHostAddress getIPAddress()
*/
static bool initLocalUser(QString name, QString groupNumber)
{
localUserName = name;
localUserGroupNumber = groupNumber;
localIpAddress = getIPAddress();
::localUserName = name;
::localUserGroupNumber = groupNumber;
::localIpAddress = getIPAddress();

return true;
}

static QString getLocalUserName()
{
return localUserName;
return ::localUserName;
}
static void setLocalUserName(QString localUserName)
{
localUserName = localUserName;
::localUserName = localUserName;
}

static QString getLocalUserGroupNumber()
{
return localUserGroupNumber;
return ::localUserGroupNumber;
}
static void setLocalUserGroupNumber(QString localUserGroupNumber)
{
localUserGroupNumber = localUserGroupNumber;
::localUserGroupNumber = localUserGroupNumber;
}


static QHostAddress getLocalIpAddress()
{
return localIpAddress;
return ::localIpAddress;
}
static void setLocalIpAddress(QHostAddress localIpAddress)
{
localIpAddress = localIpAddress;
::localIpAddress = localIpAddress;
}

static qint16 getPortChatList()
{
return PORT_CHAT_LIST;
return ::PORT_CHAT_LIST;
}

/** Show ChatList Widget
* @brief initAndShowChatList
*/
static void initAndShowChatList(QWidget* parent)
{
chatList = new ChatList(parent, localUserName, localUserGroupNumber, localIpAddress);
chatList->show();
::chatList = new ChatList(parent, ::localUserName, ::localUserGroupNumber, ::localIpAddress);
::chatList->show();
}

}
Expand Down
8 changes: 4 additions & 4 deletions App/dal_polychat.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace DAL
* @return false in name or group have error,
* if not init local user and return true
*/
static bool initLocalUser(const QString name, const QString groupNumber)
static bool initLocalUser(const QString &name, const QString &groupNumber)
{
if (name.isEmpty() || groupNumber.isEmpty())
{
Expand All @@ -31,7 +31,7 @@ static QString getLocalUserName()
{
return BLL::getLocalUserName();
}
static void setLocalUserName(QString localUserName)
static void setLocalUserName(const QString &localUserName)
{
BLL::setLocalUserName(localUserName);
}
Expand All @@ -41,7 +41,7 @@ static QString getLocalUserGroupNumber()
{
return BLL::getLocalUserGroupNumber();
}
static void setLocalUserGroupNumber(QString localUserGroupNumber)
static void setLocalUserGroupNumber(const QString &localUserGroupNumber)
{
BLL::setLocalUserGroupNumber(localUserGroupNumber);
}
Expand All @@ -51,7 +51,7 @@ static QHostAddress getLocalIpAddress()
{
return BLL::getLocalIpAddress();
}
static void setLocalIpAddress(QHostAddress localIpAddress)
static void setLocalIpAddress(const QHostAddress &localIpAddress)
{
BLL::setLocalIpAddress(localIpAddress);
}
Expand Down
2 changes: 2 additions & 0 deletions App/db_localdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "uil_chatlist.h"
#include "chat.h"

#define ENABLE_UNUSED_FUNCTION 0 // 是否编译未使用的函数

/**
* 在此修改配置
*/
Expand Down
5 changes: 3 additions & 2 deletions App/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
#include "tcpserver.h"

#include "db_localdata.h"
QString localUserName = ""; // User Name (get in user login)
QString localUserGroupNumber = ""; // Group number (get in user login)

QString localUserName = ""; // User Name (will get in user login)
QString localUserGroupNumber = ""; // Group number (will get in user login)
QHostAddress localIpAddress = QHostAddress();
ChatList* chatList = nullptr; // Widget ChatList (Only one)

Expand Down
2 changes: 1 addition & 1 deletion App/tcpclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void TcpClient::connectTcpServerAndOpenFile()
bool isFileOpen = file.open(QIODevice::WriteOnly);
if (!isFileOpen)
{
appendTextBrowser(Qt::red, QString("[ERROR] Can not write file %1 to file: %2").arg(fileName, savePath));
appendTextBrowser(Qt::red, QString("[ERROR] Can not write file %1 to %2").arg(fileName, savePath));
return;
}

Expand Down
7 changes: 5 additions & 2 deletions App/uil_chatlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <QMessageBox>


ChatList::ChatList(QWidget* parent, QString localUserName, QString localUserGroupNumber, QHostAddress localIpAddress) :
QWidget(parent),
ui(new Ui::ChatList)
Expand Down Expand Up @@ -197,6 +198,7 @@ bool ChatList::isChatExist(const QString &name)
* @param name
* @return
*/
#if ENABLE_UNUSED_FUNCTION
bool ChatList::isChatExist_But_BtnNotExist(const QString &name)
{
if (!isChatExist(name)) return false;
Expand All @@ -210,6 +212,7 @@ bool ChatList::isChatExist_But_BtnNotExist(const QString &name)
return std::any_of(this->vPair_OChat_BtnChat.begin(), this->vPair_OChat_BtnChat.end(),
[&](const auto &pair) { return (name == pair.first->name) && (nullptr == pair.second); });
}
#endif

/** 查找一个端口号是否被占用
* @brief isPortExist
Expand Down Expand Up @@ -338,7 +341,7 @@ bool ChatList::setChatState(const QString &name, bool state)
return false;
}


#if ENABLE_UNUSED_FUNCTION
bool ChatList::updateBtnInvPair(const QString &name, QToolButton* btn)
{
// for (auto i : this->vPair_OChat_BtnChat)
Expand All @@ -364,7 +367,7 @@ bool ChatList::updateBtnInvPair(const QString &name, QToolButton* btn)
qDebug() << "[ERROR] Fail to update btn, ChatBox named" << name << "do not exits in local vPair_OChat_BtnChat";
return false;
}

#endif

/** 根据搜索框中的内容,并使用正则表达式,判断是否需要隐藏按钮
* @brief isNeedHideBtn
Expand Down
6 changes: 3 additions & 3 deletions App/uil_chatlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ChatList : public QWidget
void receiveMessage(); // 接收 UDP 消息

bool isPortExist(const qint16 port); // 查找一个端口号是否被占用
bool isChatExist_But_BtnNotExist(const QString &name);
bool isChatExist_But_BtnNotExist(const QString &name); // UNUSED
bool isChatExist(const QString &name); // 查找一个名称的群聊是否已经存在
bool isChatOpen(const QString &name);

Expand All @@ -38,13 +38,13 @@ class ChatList : public QWidget
qint16 getRandomPort(); //获取一个不重复的随机端口号

bool setChatState(const QString &name, bool state); // 设置聊天窗口为打开或者关闭
bool updateBtnInvPair(const QString &name, QToolButton* btn);
bool updateBtnInvPair(const QString &name, QToolButton* btn); // UNUSED

bool isNeedHideBtn(QString textOnBtn); // 根据正则表达式,判断是否需要隐藏按钮


private:
Ui::ChatList *ui;
Ui::ChatList* ui;

QUdpSocket* udpSocket;

Expand Down
3 changes: 2 additions & 1 deletion Tester/Tester.pro
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ FORMS += \
../App/tcpclient.ui \
../App/tcpserver.ui

QMAKE_CXXFLAGS += -w
QMAKE_CXXFLAGS += -w -fprofile-arcs -ftest-coverage
QMAKE_LFLAGS += -fprofile-arcs -ftest-coverage
57 changes: 51 additions & 6 deletions Tester/tst_PolyChatTester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <QTableWidget>

#include "../App/db_localdata.h"
#include "../App/bll_polychat.h"
#include "../App/dal_polychat.h"
#include "../App/uil_loginwidget.h"
#include "../App/uil_addchat.h"
Expand All @@ -26,17 +25,24 @@
#include "../App/tcpclient.h"
#include "../App/tcpserver.h"

/* 是否启用对应测试 */
#define ENABLE_UT 1 // 激活单元测试
#define ENABLE_MT 1
#define ENABLE_PT 1
#define ENABLE_LT 1
#define ENABLE_CT 1
#define ENABLE_E2E 1

QString localUserName = ""; // User Name (get in user login)
QString localUserGroupNumber = ""; // Group number (get in user login)
QHostAddress localIpAddress = QHostAddress();
ChatList* chatList = nullptr; // Widget ChatList (Only one)

unsigned int const TIMER_STEP = 1000; // 对话框弹出市场,缩短此项只会影响展示效果。不会影响测试的最终结果
unsigned int const TIMER_STEP = 1000; // 对话框弹出时长,缩短此项只会影响展示效果。不会影响测试的最终结果

class PolyChatTester : public QObject
{
Q_OBJECT
Q_OBJECT // 要想使用 QTestlib 工具,必须包含 Q_OBJECT 工具

public:
PolyChatTester();
Expand All @@ -46,6 +52,7 @@ private slots:
void initTestCase();
void cleanupTestCase();

#if ENABLE_UT
void ut_login_login_empty ();
void ut_login_group_empty ();
void ut_login_login_group_empty ();
Expand Down Expand Up @@ -130,7 +137,9 @@ private slots:
void ut_chatbox_closeEvent_emit ();
void ut_chatbox_tbUser ();
void ut_chatbox_lbNumberOnlineUse ();
#endif

#if ENABLE_MT
void mt_login_init_success ();
void mt_login_leUserName ();
void mt_login_leUserGroupNumber ();
Expand All @@ -151,7 +160,9 @@ private slots:
void mt_chatbox_send_success ();
void mt_tcpclient ();
void mt_tcpserver ();
#endif

#if ENABLE_PT
void pt_Login_load ();
void pt_AddChat_load ();
void pt_ChatList_load ();
Expand All @@ -163,14 +174,22 @@ private slots:
void pt_ChatBox_msgTextEdit_input();
void pt_Login_to_system ();
void pt_AddChat_ui ();
#endif

#if ENABLE_LT
void lt_ChatBox_x100 ();
void lt_ChatBox_200user ();
void lt_ChatBox_2000char ();
void lt_ChatBox_msg_change ();
void lt_TcpServer_x10 ();
void lt_TcpClient_x10 ();
#endif

#if ENABLE_CT
void ct_ChatBox_code_normal ();
#endif

#if ENABLE_E2E
void e2e_add_new_chat ();
void e2e_join_chat ();
void e2e_search_chat ();
Expand All @@ -181,6 +200,8 @@ private slots:
void e2e_clean_chat ();
void e2e_save_chat ();
void e2e_leave_chat ();
#endif

#if 0
void e2e_Login_normal ();
void e2e_Login_empty_all ();
Expand Down Expand Up @@ -247,6 +268,8 @@ void PolyChatTester::cleanupTestCase()
qDebug() << "End of all test runs";
}

#if ENABLE_UT

/** 登录失败(用户名不能为空)
* Сбой входа в систему (имя пользователя не может быть пустым).
* @brief PolyChatTester::ut_login_login_empty
Expand Down Expand Up @@ -1290,6 +1313,11 @@ void PolyChatTester::ut_chatbox_lbNumberOnlineUse()
}


#endif

#if ENABLE_MT


/** 登陆成功,本地用户信息被正确初始化
* Имитация использования пользователем клавиатуры для ввода текста в поле ввода, а затем нажатие кнопки входа в систему (вход выполнен успешно, и информация о локальном пользователе правильно инициализирована).
* @brief PolyChatTester::mt_login_init_success
Expand Down Expand Up @@ -1375,8 +1403,10 @@ void PolyChatTester::mt_chatlist_getNewBtn()
QPair<Chat*, QToolButton*> pair(new Chat("3530904/90102", 6666, false), btn);
widget.vPair_OChat_BtnChat.push_front(pair);

#if ENABLE_UNUSED_FUNCTION
widget.updateBtnInvPair("3530904/90102", btn);
QCOMPARE(widget.isChatOpen("3530904/90102"), false);
#endif
}

/** 当增加新的聊天群组时,ui 界面正确刷新
Expand All @@ -1393,9 +1423,10 @@ void PolyChatTester::mt_chatlist_btnchat_exist()
QPair<Chat*, QToolButton*> pair(new Chat("3530904/90102", 6666, false), btn);
widget.vPair_OChat_BtnChat.push_front(pair);

#if ENABLE_UNUSED_FUNCTION
widget.updateBtnInvPair("3530904/90102", btn);
QCOMPARE(widget.isChatOpen("3530904/90102"), false);

#endif
}

/** 用户加入(用户列表正确刷新)
Expand Down Expand Up @@ -1694,6 +1725,9 @@ void PolyChatTester::mt_tcpserver()
QCOMPARE(textBrowser->isReadOnly(), true);
}

#endif

#if ENABLE_PT

/** 窗口加载/调用的性能
* Производительность загрузки/вызова окон.
Expand Down Expand Up @@ -2020,6 +2054,10 @@ void PolyChatTester::lt_TcpClient_x10()
}
}

#endif

#if ENABLE_CT

/** 模拟用户通过键盘在 msgTextEdit 输入英文、中文、俄文。且 ui 显示正常,不乱码
* Имитация ввода пользователем английского, китайского и русского языков в msgTextEdit с клавиатуры. При этом ui отображается корректно, без искажений.
* @brief PolyChatTester::ct_ChatBox_code_normal
Expand All @@ -2042,6 +2080,10 @@ void PolyChatTester::ct_ChatBox_code_normal()
textBrowser->clear();
}

#endif

#if ENABLE_E2E

void PolyChatTester::e2e_add_new_chat()
{
LoginWidget loginWidget;
Expand Down Expand Up @@ -2104,8 +2146,10 @@ void PolyChatTester::e2e_join_chat()
QPair<Chat*, QToolButton*> pair(new Chat("3530904/90102", 6666, false), btn);
chatList.vPair_OChat_BtnChat.push_front(pair);

chatList.updateBtnInvPair("3530904/90102", btn);
QCOMPARE(chatList.isChatOpen("3530904/90102"), false);
#if ENABLE_UNUSED_FUNCTION
widget.updateBtnInvPair("3530904/90102", btn);
QCOMPARE(widget.isChatOpen("3530904/90102"), false);
#endif

QTest::mouseClick(btn, Qt::LeftButton);
}
Expand Down Expand Up @@ -2607,6 +2651,7 @@ void PolyChatTester::e2e_leave_chat()
}


#endif



Expand Down
Loading