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] =?UTF-8?q?=E8=BF=9B=E4=B8=80=E6=AD=A5=E4=BC=98=E5=8C=96?= =?UTF-8?q?=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); }