Browse Source

add test/testmodulecommextrecv.

yuchuli 3 years ago
parent
commit
ae50113da9

+ 73 - 0
src/test/testmodulecommextrecv/.gitignore

@@ -0,0 +1,73 @@
+# This file is used to ignore files which are generated
+# ----------------------------------------------------------------------------
+
+*~
+*.autosave
+*.a
+*.core
+*.moc
+*.o
+*.obj
+*.orig
+*.rej
+*.so
+*.so.*
+*_pch.h.cpp
+*_resource.rc
+*.qm
+.#*
+*.*#
+core
+!core/
+tags
+.DS_Store
+.directory
+*.debug
+Makefile*
+*.prl
+*.app
+moc_*.cpp
+ui_*.h
+qrc_*.cpp
+Thumbs.db
+*.res
+*.rc
+/.qmake.cache
+/.qmake.stash
+
+# qtcreator generated files
+*.pro.user*
+
+# xemacs temporary files
+*.flc
+
+# Vim temporary files
+.*.swp
+
+# Visual Studio generated files
+*.ib_pdb_index
+*.idb
+*.ilk
+*.pdb
+*.sln
+*.suo
+*.vcproj
+*vcproj.*.*.user
+*.ncb
+*.sdf
+*.opensdf
+*.vcxproj
+*vcxproj.*
+
+# MinGW generated files
+*.Debug
+*.Release
+
+# Python byte code
+*.pyc
+
+# Binaries
+# --------
+*.dll
+*.exe
+

+ 18 - 0
src/test/testmodulecommextrecv/main.cpp

@@ -0,0 +1,18 @@
+#include <QCoreApplication>
+
+#include "testshmrecv.h"
+#include "testfastrtpsrecv.h"
+#include "testfastrtpstcprecv.h"
+
+int main(int argc, char *argv[])
+{
+    QCoreApplication a(argc, argv);
+
+    testshmrecv * pshmrecv = new testshmrecv();
+
+    testfastrtpsrecv * prtpsrecv  = new  testfastrtpsrecv();
+
+//    testfastrtpstcprecv * prtpstcprecv = new testfastrtpstcprecv();
+
+    return a.exec();
+}

+ 15 - 0
src/test/testmodulecommextrecv/testfastrtpsrecv.cpp

@@ -0,0 +1,15 @@
+#include "testfastrtpsrecv.h"
+
+testfastrtpsrecv::testfastrtpsrecv()
+{
+    mpa = new iv::modulecommext::modulecommmsg<iv::testmodulecommext>();
+    ModuleExtFun funext = std::bind(&testfastrtpsrecv::ListenMsg,this,std::placeholders::_1);
+    mpa->RegisterRecvPlus("test",funext,iv::modulecomm::ModuleComm_FASTRTPS);
+}
+
+void testfastrtpsrecv::ListenMsg(google::protobuf::Message &xmsg)
+{
+    iv::testmodulecommext  xdata;
+    xdata.CopyFrom(xmsg);
+    qDebug("fastrtps: %lld",xdata.time());
+}

+ 19 - 0
src/test/testmodulecommextrecv/testfastrtpsrecv.h

@@ -0,0 +1,19 @@
+#ifndef TESTFASTRTPSRECV_H
+#define TESTFASTRTPSRECV_H
+
+#include "modulecommext.h"
+
+#include "testmodulecommext.pb.h"
+
+class testfastrtpsrecv
+{
+public:
+    testfastrtpsrecv();
+
+    iv::modulecommext::modulecommmsg<iv::testmodulecommext> * mpa;
+
+private:
+    void ListenMsg(google::protobuf::Message & xmsg);
+};
+
+#endif // TESTFASTRTPSRECV_H

+ 15 - 0
src/test/testmodulecommextrecv/testfastrtpstcprecv.cpp

@@ -0,0 +1,15 @@
+#include "testfastrtpstcprecv.h"
+
+testfastrtpstcprecv::testfastrtpstcprecv()
+{
+    mpa = new iv::modulecommext::modulecommmsg<iv::testmodulecommext>();
+    ModuleExtFun funext = std::bind(&testfastrtpstcprecv::ListenMsg,this,std::placeholders::_1);
+    mpa->RegisterRecvPlus("test",funext,iv::modulecomm::ModuleComm_FASTRTPS_TCP,"192.168.14.98",5101);
+}
+
+void testfastrtpstcprecv::ListenMsg(google::protobuf::Message &xmsg)
+{
+    iv::testmodulecommext  xdata;
+    xdata.CopyFrom(xmsg);
+    qDebug("rtps_tcp: %lld",xdata.time());
+}

+ 18 - 0
src/test/testmodulecommextrecv/testfastrtpstcprecv.h

@@ -0,0 +1,18 @@
+#ifndef TESTFASTRTPSTCPRECV_H
+#define TESTFASTRTPSTCPRECV_H
+
+#include "modulecommext.h"
+
+#include "testmodulecommext.pb.h"
+
+class testfastrtpstcprecv
+{
+public:
+    testfastrtpstcprecv();
+    iv::modulecommext::modulecommmsg<iv::testmodulecommext> * mpa;
+
+private:
+    void ListenMsg(google::protobuf::Message & xmsg);
+};
+
+#endif // TESTFASTRTPSTCPRECV_H

+ 35 - 0
src/test/testmodulecommextrecv/testmodulecommextrecv.pro

@@ -0,0 +1,35 @@
+QT -= gui
+
+CONFIG += c++11 console
+CONFIG -= app_bundle
+
+# The following define makes your compiler emit warnings if you use
+# any feature of Qt which as been marked deprecated (the exact warnings
+# depend on your compiler). Please consult the documentation of the
+# deprecated API in order to know how to port your code away from it.
+DEFINES += QT_DEPRECATED_WARNINGS
+
+# You can also make your code fail to compile if you use deprecated APIs.
+# In order to do so, uncomment the following line.
+# You can also select to disable deprecated APIs only up to a certain version of Qt.
+#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
+
+SOURCES += main.cpp \
+    ../../include/msgtype/testmodulecommext.pb.cc \
+    testshmrecv.cpp \
+    testfastrtpsrecv.cpp \
+    testfastrtpstcprecv.cpp
+
+!include(../../../include/common.pri ) {
+    error( "Couldn't find the common.pri file!" )
+}
+
+!include(../../../include/ivprotobuf.pri ) {
+    error( "Couldn't find the ivprotobuf.pri file!" )
+}
+
+HEADERS += \
+    ../../include/msgtype/testmodulecommext.pb.h \
+    testshmrecv.h \
+    testfastrtpsrecv.h \
+    testfastrtpstcprecv.h

+ 15 - 0
src/test/testmodulecommextrecv/testshmrecv.cpp

@@ -0,0 +1,15 @@
+#include "testshmrecv.h"
+
+testshmrecv::testshmrecv()
+{
+    mpa = new iv::modulecommext::modulecommmsg<iv::testmodulecommext>();
+    ModuleExtFun funext = std::bind(&testshmrecv::ListenMsg,this,std::placeholders::_1);
+    mpa->RegisterRecvPlus("test",funext,iv::modulecomm::ModuleComm_SHAREMEM);
+}
+
+void testshmrecv::ListenMsg(google::protobuf::Message &xmsg)
+{
+    iv::testmodulecommext  xdata;
+    xdata.CopyFrom(xmsg);
+    qDebug("shm: %lld",xdata.time());
+}

+ 20 - 0
src/test/testmodulecommextrecv/testshmrecv.h

@@ -0,0 +1,20 @@
+#ifndef TESTSHMRECV_H
+#define TESTSHMRECV_H
+
+#include "modulecommext.h"
+
+#include "testmodulecommext.pb.h"
+
+
+class testshmrecv
+{
+public:
+    testshmrecv();
+
+    iv::modulecommext::modulecommmsg<iv::testmodulecommext> * mpa;
+
+private:
+    void ListenMsg(google::protobuf::Message & xmsg);
+};
+
+#endif // TESTSHMRECV_H

+ 9 - 0
src/test/testmodulecommextsend/main.cpp

@@ -5,6 +5,9 @@
 
 #include "testshmsend.h"
 
+#include "testfastrtpssend.h"
+#include "testfastrtpstcpsend.h"
+
 int main(int argc, char *argv[])
 {
     QCoreApplication a(argc, argv);
@@ -16,5 +19,11 @@ int main(int argc, char *argv[])
     testshmsend xshmsend;
     xshmsend.start();
 
+    testfastrtpssend xrtpssend;
+    xrtpssend.start();
+
+    testfastrtpstcpsend xrtpstcpsend;
+    xrtpstcpsend.start();
+
     return a.exec();
 }

+ 20 - 0
src/test/testmodulecommextsend/testfastrtpssend.cpp

@@ -0,0 +1,20 @@
+#include "testfastrtpssend.h"
+
+testfastrtpssend::testfastrtpssend()
+{
+    mpa = new iv::modulecommext::modulecommmsg<iv::testmodulecommext>();
+
+    mpa->RegisterSend("test",1000,1,iv::modulecomm::ModuleComm_FASTRTPS);
+}
+
+void testfastrtpssend::run()
+{
+    while (!QThread::isInterruptionRequested()) {
+        iv::testmodulecommext xmsg;
+        xmsg.set_a(1);
+        xmsg.set_b(2);
+        xmsg.set_time(QDateTime::currentMSecsSinceEpoch());
+        mpa->ModuleSendMsg(xmsg);
+        msleep(1000);
+    }
+}

+ 22 - 0
src/test/testmodulecommextsend/testfastrtpssend.h

@@ -0,0 +1,22 @@
+#ifndef TESTFASTRTPSSEND_H
+#define TESTFASTRTPSSEND_H
+
+#include <QThread>
+
+#include "modulecommext.h"
+
+#include "testmodulecommext.pb.h"
+
+#include "testinteriorsend.h"
+
+class testfastrtpssend : public QThread
+{
+public:
+    testfastrtpssend();
+    iv::modulecommext::modulecommmsg<iv::testmodulecommext> * mpa;
+
+private:
+    void run();
+};
+
+#endif // TESTFASTRTPSSEND_H

+ 20 - 0
src/test/testmodulecommextsend/testfastrtpstcpsend.cpp

@@ -0,0 +1,20 @@
+#include "testfastrtpstcpsend.h"
+
+testfastrtpstcpsend::testfastrtpstcpsend()
+{
+    mpa = new iv::modulecommext::modulecommmsg<iv::testmodulecommext>();
+
+    mpa->RegisterSend("test",1000,1,iv::modulecomm::ModuleComm_FASTRTPS_TCP,5101);
+}
+
+void testfastrtpstcpsend::run()
+{
+    while (!QThread::isInterruptionRequested()) {
+        iv::testmodulecommext xmsg;
+        xmsg.set_a(1);
+        xmsg.set_b(2);
+        xmsg.set_time(QDateTime::currentMSecsSinceEpoch());
+        mpa->ModuleSendMsg(xmsg);
+        msleep(1000);
+    }
+}

+ 22 - 0
src/test/testmodulecommextsend/testfastrtpstcpsend.h

@@ -0,0 +1,22 @@
+#ifndef TESTFASTRTPSTCPSEND_H
+#define TESTFASTRTPSTCPSEND_H
+
+#include <QThread>
+
+#include "modulecommext.h"
+
+#include "testmodulecommext.pb.h"
+
+#include "testinteriorsend.h"
+
+class testfastrtpstcpsend : public QThread
+{
+public:
+    testfastrtpstcpsend();
+    iv::modulecommext::modulecommmsg<iv::testmodulecommext> * mpa;
+
+private:
+    void run();
+};
+
+#endif // TESTFASTRTPSTCPSEND_H

+ 6 - 2
src/test/testmodulecommextsend/testmodulecommextsend.pro

@@ -18,7 +18,9 @@ SOURCES += main.cpp \
     ../../include/msgtype/testmodulecommext.pb.cc \
     testinteriorsend.cpp \
     testinteriorrecv.cpp \
-    testshmsend.cpp
+    testshmsend.cpp \
+    testfastrtpssend.cpp \
+    testfastrtpstcpsend.cpp
 
 !include(../../../include/common.pri ) {
     error( "Couldn't find the common.pri file!" )
@@ -32,4 +34,6 @@ HEADERS += \
     ../../include/msgtype/testmodulecommext.pb.h \
     testinteriorsend.h \
     testinteriorrecv.h \
-    testshmsend.h
+    testshmsend.h \
+    testfastrtpssend.h \
+    testfastrtpstcpsend.h

+ 1 - 1
src/test/testmodulecommextsend/testshmsend.cpp

@@ -4,7 +4,7 @@ testshmsend::testshmsend()
 {
     mpa = new iv::modulecommext::modulecommmsg<iv::testmodulecommext>();
 
-    mpa->RegisterSend("test3",1000,1,iv::modulecomm::ModuleComm_SHAREMEM);
+    mpa->RegisterSend("test",1000,1,iv::modulecomm::ModuleComm_SHAREMEM);
 }
 
 void testshmsend::run()