From ffbf4458585f336999fba3421a37c772ec4240e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B0=E7=B3=96=E9=9B=AA=E7=8B=B8?= Date: Mon, 26 Feb 2024 17:45:39 +0300 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E8=B5=8B=E5=80=BC?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E5=B9=B6=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App/bll_polychat.h | 24 ++++++++++++------------ App/main.cpp | 4 ++-- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/App/bll_polychat.h b/App/bll_polychat.h index c41d387..2d40283 100644 --- a/App/bll_polychat.h +++ b/App/bll_polychat.h @@ -42,44 +42,44 @@ 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 @@ -87,8 +87,8 @@ static qint16 getPortChatList() */ static void initAndShowChatList(QWidget* parent) { - chatList = new ChatList(parent, localUserName, localUserGroupNumber, localIpAddress); - chatList->show(); + ::chatList = new ChatList(parent, ::localUserName, ::localUserGroupNumber, ::localIpAddress); + ::chatList->show(); } } diff --git a/App/main.cpp b/App/main.cpp index 4e9a036..991e38a 100644 --- a/App/main.cpp +++ b/App/main.cpp @@ -6,8 +6,8 @@ #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) From 467dc4cc7b99ecb5018a7344abf8b303992d0758 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B0=E7=B3=96=E9=9B=AA=E7=8B=B8?= Date: Fri, 1 Mar 2024 15:45:33 +0300 Subject: [PATCH 2/4] =?UTF-8?q?=E8=BF=9B=E4=B8=80=E6=AD=A5=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E4=BB=A3=E7=A0=81=E4=B8=AD=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App/dal_polychat.h | 8 ++++---- App/db_localdata.h | 1 + App/main.cpp | 3 +++ App/tcpclient.cpp | 2 +- App/uil_chatlist.cpp | 7 +++++-- App/uil_chatlist.h | 6 +++--- Tester/Tester.pro | 3 ++- Tester/tst_PolyChatTester.cpp | 14 +++++++++----- 8 files changed, 28 insertions(+), 16 deletions(-) diff --git a/App/dal_polychat.h b/App/dal_polychat.h index 0867d61..dfb9e0b 100644 --- a/App/dal_polychat.h +++ b/App/dal_polychat.h @@ -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()) { @@ -31,7 +31,7 @@ static QString getLocalUserName() { return BLL::getLocalUserName(); } -static void setLocalUserName(QString localUserName) +static void setLocalUserName(const QString &localUserName) { BLL::setLocalUserName(localUserName); } @@ -41,7 +41,7 @@ static QString getLocalUserGroupNumber() { return BLL::getLocalUserGroupNumber(); } -static void setLocalUserGroupNumber(QString localUserGroupNumber) +static void setLocalUserGroupNumber(const QString &localUserGroupNumber) { BLL::setLocalUserGroupNumber(localUserGroupNumber); } @@ -51,7 +51,7 @@ static QHostAddress getLocalIpAddress() { return BLL::getLocalIpAddress(); } -static void setLocalIpAddress(QHostAddress localIpAddress) +static void setLocalIpAddress(const QHostAddress &localIpAddress) { BLL::setLocalIpAddress(localIpAddress); } diff --git a/App/db_localdata.h b/App/db_localdata.h index 88e621f..a96b09b 100644 --- a/App/db_localdata.h +++ b/App/db_localdata.h @@ -7,6 +7,7 @@ #include "uil_chatlist.h" #include "chat.h" + /** * 在此修改配置 */ diff --git a/App/main.cpp b/App/main.cpp index 991e38a..3f8799c 100644 --- a/App/main.cpp +++ b/App/main.cpp @@ -6,6 +6,9 @@ #include "tcpserver.h" #include "db_localdata.h" + +#define ENABLE_UNUSED_FUNCTION 0 // 是否编译未使用的函数 + QString localUserName = ""; // User Name (will get in user login) QString localUserGroupNumber = ""; // Group number (will get in user login) QHostAddress localIpAddress = QHostAddress(); diff --git a/App/tcpclient.cpp b/App/tcpclient.cpp index 61a04c3..ab7cfb7 100644 --- a/App/tcpclient.cpp +++ b/App/tcpclient.cpp @@ -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; } diff --git a/App/uil_chatlist.cpp b/App/uil_chatlist.cpp index c6d2792..bbdcabf 100644 --- a/App/uil_chatlist.cpp +++ b/App/uil_chatlist.cpp @@ -7,6 +7,7 @@ #include + ChatList::ChatList(QWidget* parent, QString localUserName, QString localUserGroupNumber, QHostAddress localIpAddress) : QWidget(parent), ui(new Ui::ChatList) @@ -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; @@ -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 @@ -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) @@ -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 diff --git a/App/uil_chatlist.h b/App/uil_chatlist.h index 37ce282..205be9f 100644 --- a/App/uil_chatlist.h +++ b/App/uil_chatlist.h @@ -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); @@ -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; diff --git a/Tester/Tester.pro b/Tester/Tester.pro index dd663f2..56083f5 100644 --- a/Tester/Tester.pro +++ b/Tester/Tester.pro @@ -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 diff --git a/Tester/tst_PolyChatTester.cpp b/Tester/tst_PolyChatTester.cpp index 6a98ec8..7ce67e7 100644 --- a/Tester/tst_PolyChatTester.cpp +++ b/Tester/tst_PolyChatTester.cpp @@ -17,7 +17,6 @@ #include #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" @@ -32,7 +31,7 @@ QString localUserGroupNumber = ""; // Group number (get in 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 { @@ -1375,8 +1374,10 @@ void PolyChatTester::mt_chatlist_getNewBtn() QPair 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 界面正确刷新 @@ -1393,9 +1394,10 @@ void PolyChatTester::mt_chatlist_btnchat_exist() QPair 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 } /** 用户加入(用户列表正确刷新) @@ -2104,8 +2106,10 @@ void PolyChatTester::e2e_join_chat() QPair 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); } From a2fc9e75e4fd9aa9b6331a0ed40be0e422c03cd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B0=E7=B3=96=E9=9B=AA=E7=8B=B8?= Date: Fri, 1 Mar 2024 16:34:19 +0300 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BC=98=E5=8C=96=20=E5=AE=8F=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App/db_localdata.h | 1 + App/main.cpp | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/App/db_localdata.h b/App/db_localdata.h index a96b09b..83533ce 100644 --- a/App/db_localdata.h +++ b/App/db_localdata.h @@ -7,6 +7,7 @@ #include "uil_chatlist.h" #include "chat.h" +#define ENABLE_UNUSED_FUNCTION 0 // 是否编译未使用的函数 /** * 在此修改配置 diff --git a/App/main.cpp b/App/main.cpp index 3f8799c..5db51f4 100644 --- a/App/main.cpp +++ b/App/main.cpp @@ -7,8 +7,6 @@ #include "db_localdata.h" -#define ENABLE_UNUSED_FUNCTION 0 // 是否编译未使用的函数 - QString localUserName = ""; // User Name (will get in user login) QString localUserGroupNumber = ""; // Group number (will get in user login) QHostAddress localIpAddress = QHostAddress(); From 627596c692d1bca1dfa08c937086636dc80b33d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B0=E7=B3=96=E9=9B=AA=E7=8B=B8?= Date: Sat, 2 Mar 2024 15:02:56 +0300 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BC=98=E5=8C=96=20=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tester/tst_PolyChatTester.cpp | 43 ++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/Tester/tst_PolyChatTester.cpp b/Tester/tst_PolyChatTester.cpp index 7ce67e7..bf29b20 100644 --- a/Tester/tst_PolyChatTester.cpp +++ b/Tester/tst_PolyChatTester.cpp @@ -25,6 +25,13 @@ #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) @@ -35,7 +42,7 @@ unsigned int const TIMER_STEP = 1000; // 对话框弹出时 class PolyChatTester : public QObject { - Q_OBJECT + Q_OBJECT // 要想使用 QTestlib 工具,必须包含 Q_OBJECT 工具 public: PolyChatTester(); @@ -45,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 (); @@ -129,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 (); @@ -150,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 (); @@ -162,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 (); @@ -180,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 (); @@ -246,6 +268,8 @@ void PolyChatTester::cleanupTestCase() qDebug() << "End of all test runs"; } +#if ENABLE_UT + /** 登录失败(用户名不能为空) * Сбой входа в систему (имя пользователя не может быть пустым). * @brief PolyChatTester::ut_login_login_empty @@ -1289,6 +1313,11 @@ void PolyChatTester::ut_chatbox_lbNumberOnlineUse() } +#endif + +#if ENABLE_MT + + /** 登陆成功,本地用户信息被正确初始化 * Имитация использования пользователем клавиатуры для ввода текста в поле ввода, а затем нажатие кнопки входа в систему (вход выполнен успешно, и информация о локальном пользователе правильно инициализирована). * @brief PolyChatTester::mt_login_init_success @@ -1696,6 +1725,9 @@ void PolyChatTester::mt_tcpserver() QCOMPARE(textBrowser->isReadOnly(), true); } +#endif + +#if ENABLE_PT /** 窗口加载/调用的性能 * Производительность загрузки/вызова окон. @@ -2022,6 +2054,10 @@ void PolyChatTester::lt_TcpClient_x10() } } +#endif + +#if ENABLE_CT + /** 模拟用户通过键盘在 msgTextEdit 输入英文、中文、俄文。且 ui 显示正常,不乱码 * Имитация ввода пользователем английского, китайского и русского языков в msgTextEdit с клавиатуры. При этом ui отображается корректно, без искажений. * @brief PolyChatTester::ct_ChatBox_code_normal @@ -2044,6 +2080,10 @@ void PolyChatTester::ct_ChatBox_code_normal() textBrowser->clear(); } +#endif + +#if ENABLE_E2E + void PolyChatTester::e2e_add_new_chat() { LoginWidget loginWidget; @@ -2611,6 +2651,7 @@ void PolyChatTester::e2e_leave_chat() } +#endif