From ef272c91b09b5560796933207716a968735ef4ee Mon Sep 17 00:00:00 2001 From: xxxcucus Date: Sat, 25 Nov 2023 19:52:30 +0100 Subject: [PATCH] Added stomp frame parsing --- c_plus_plus/stomp/CMakeLists.txt | 2 + c_plus_plus/stomp/stompclient.cpp | 13 +- c_plus_plus/stomp/stompclient.h | 1 + c_plus_plus/stomp/stompframe.cpp | 92 +++++------- c_plus_plus/stomp/stompframe.h | 23 ++- c_plus_plus/stomp/stompframecreator.cpp | 2 +- c_plus_plus/stomp/stompframeparser.cpp | 141 ++++++++++++++++++ c_plus_plus/stomp/stompframeparser.h | 21 +++ c_plus_plus/tests/stomptests/CMakeLists.txt | 2 + c_plus_plus/tests/stomptests/main.cpp | 6 + .../tests/stomptests/stompframeparsertest.cpp | 105 +++++++++++++ .../tests/stomptests/stompframeparsertest.h | 24 +++ .../tests/stomptests/stompframetest.cpp | 50 +------ c_plus_plus/tests/stomptests/stompframetest.h | 6 - 14 files changed, 363 insertions(+), 125 deletions(-) create mode 100644 c_plus_plus/stomp/stompframeparser.cpp create mode 100644 c_plus_plus/stomp/stompframeparser.h create mode 100644 c_plus_plus/tests/stomptests/stompframeparsertest.cpp create mode 100644 c_plus_plus/tests/stomptests/stompframeparsertest.h diff --git a/c_plus_plus/stomp/CMakeLists.txt b/c_plus_plus/stomp/CMakeLists.txt index 9eb2e0af..4fca0b62 100644 --- a/c_plus_plus/stomp/CMakeLists.txt +++ b/c_plus_plus/stomp/CMakeLists.txt @@ -15,12 +15,14 @@ set(STOMP_HEADR stompframe.h stompclient.h stompframecreator.h + stompframeparser.h ) set(STOMP_SRCS stompframe.cpp stompclient.cpp stompframecreator.cpp + stompframeparser.cpp ) diff --git a/c_plus_plus/stomp/stompclient.cpp b/c_plus_plus/stomp/stompclient.cpp index e6093529..2e548ba1 100644 --- a/c_plus_plus/stomp/stompclient.cpp +++ b/c_plus_plus/stomp/stompclient.cpp @@ -1,4 +1,8 @@ #include "stompclient.h" +#include "stompframeparser.h" +#include "stompframe.h" + +#include StompClient::StompClient() { QObject::connect(&m_Socket, &QWebSocket::connected, this, &StompClient::socketConnected); @@ -28,8 +32,6 @@ void StompClient::setUrl(const QString& url) { void StompClient::socketConnected() { qDebug() << "Connected to socket"; - qDebug() << "Socket version " << m_Socket.version(); - qDebug() << "Max incoming message size " << QWebSocket::maxIncomingMessageSize(); emit clientConnected(); } @@ -65,6 +67,13 @@ void StompClient::binaryMessageReceived(const QByteArray& ba) { void StompClient::textMessageReceived(const QString& message) { qDebug() << "Received stomp text message " << message; + StompFrameParser parser; + + bool error = true; + std::shared_ptr stompFrame = parser.parseFromTextMessage(message, error); + if (error && stompFrame->getCommand() == StompFrame::HeaderTypes::MESSAGE) { + emit stompMessageReceived(stompFrame->getTextBody()); + } } void StompClient::textFrameReceived(const QString &frame, bool isLastFrame) { diff --git a/c_plus_plus/stomp/stompclient.h b/c_plus_plus/stomp/stompclient.h index 1e770321..3496eab5 100644 --- a/c_plus_plus/stomp/stompclient.h +++ b/c_plus_plus/stomp/stompclient.h @@ -19,6 +19,7 @@ class StompClient : public QObject { signals: void clientConnected(); + void stompMessageReceived(const QString& message); private slots: void socketConnected(); diff --git a/c_plus_plus/stomp/stompframe.cpp b/c_plus_plus/stomp/stompframe.cpp index f1e1017b..7f16be00 100644 --- a/c_plus_plus/stomp/stompframe.cpp +++ b/c_plus_plus/stomp/stompframe.cpp @@ -12,6 +12,18 @@ bool StompFrame::setCommand(HeaderTypes command) { return true; } +bool StompFrame::setCommand(const QString& command) { + m_Command = convertCommandFromString(command); + m_CommandString = command; + QByteArray convertedArray = convertCommandToQByteArray(m_Command); + m_CommandBA = convertedArray; + + if (convertedArray == QByteArray(1, 0)) + return false; + + return true; +} + QString StompFrame::convertCommandToQString(HeaderTypes command) const { switch(command) { case HeaderTypes::CONNECT: @@ -99,19 +111,11 @@ StompFrame::HeaderTypes StompFrame::convertCommandFromString(const QString& stri retVal = HeaderTypes::ERROR; else retVal = HeaderTypes::UNKNOWN; - - //check that the original command was really what was converted - QByteArray convertedRetVal = convertCommandToQByteArray(retVal); - - if (convertedRetVal == m_CommandBA) - return retVal; - - return HeaderTypes::UNKNOWN; + return retVal; } bool StompFrame::addHeader(const QString& key, const QString& value) { //escape the strings and create headers as QString - assert(m_HeadersBA.size() == m_ValuesBA.size()); assert(m_HeadersString.size() == m_ValuesString.size()); QByteArray baKey = escapeSpecialSymbols(key.toUtf8()); @@ -123,6 +127,18 @@ bool StompFrame::addHeader(const QString& key, const QString& value) { return true; } +bool StompFrame::addHeader(const QByteArray& key, const QByteArray& value) { + assert(m_HeadersBA.size() == m_ValuesBA.size()); + assert(m_HeadersString.size() == m_ValuesString.size()); + QByteArray baKey = escapeSpecialSymbols(key); + QByteArray baValue = escapeSpecialSymbols(value); + m_HeadersBA.push_back(baKey); + m_ValuesBA.push_back(baValue); + m_HeadersString.push_back(QString(baKey)); + m_ValuesString.push_back(QString(baValue)); + return true; +} + QByteArray StompFrame::escapeSpecialSymbols(const QByteArray& ba) { QByteArray::const_iterator it = ba.begin(); QByteArray retVal; @@ -149,50 +165,6 @@ QByteArray StompFrame::escapeSpecialSymbols(const QByteArray& ba) { return retVal; } - -std::pair StompFrame::unescapeSpecialSymbols(const QByteArray& ba) { - QByteArray::const_iterator it = ba.begin(); - QByteArray retVal; - - bool found92 = false; - while (it != ba.end()) { - if (*it == 92) { - if (found92) { - retVal.append(92); - found92 = false; - } else { - found92 = true; - } - } else if (*it == 110) { - if (found92) - retVal.append(10); - else - retVal.append(110); - found92 = false; - } else if (*it == 114) { - if (found92) - retVal.append(13); - else - retVal.append(114); - found92 = false; - } else if (*it == 99) { - if (found92) - retVal.append(58); - else - retVal.append(99); - found92 = false; - } else { - if (found92) - return std::make_pair(false, QByteArray(1, 0)); - retVal.append(*it); - } - it++; - } - - return std::make_pair(true, retVal); -} - - std::tuple StompFrame::getHeader(int i) const { if (i < 0 || i >= m_HeadersBA.size() || i >= m_ValuesBA.size()) return std::tuple(false, QString(), QString()); @@ -244,7 +216,7 @@ QByteArray StompFrame::convertToByteArray() { bool StompFrame::addTextBody(const QString& body) { - if (body.size() == 0) + if (body.isEmpty()) return true; if (m_BodyBA.size() > 0) @@ -264,3 +236,15 @@ bool StompFrame::addByteArrayBody(const QByteArray& body) { return true; } +QStringList StompFrame::getCommandQStringList() { + if(!m_CommandTypeStringList.isEmpty()) + return m_CommandTypeStringList; + for (auto headerType : m_HeaderTypesList) { + m_CommandTypeStringList.push_back(convertCommandToQString(headerType)); + } + return m_CommandTypeStringList; +} + +QString StompFrame::getTextBody() const { + return m_BodyString; +} diff --git a/c_plus_plus/stomp/stompframe.h b/c_plus_plus/stomp/stompframe.h index ebcd00ff..a02a593f 100644 --- a/c_plus_plus/stomp/stompframe.h +++ b/c_plus_plus/stomp/stompframe.h @@ -2,6 +2,7 @@ #define _STOMPFRAME_H #include +#include #include class StompFrame { @@ -13,23 +14,26 @@ class StompFrame { StompFrame() {} bool setCommand(HeaderTypes command); + bool setCommand(const QString& commannd); bool addHeader(const QString& key, const QString& value); + bool addHeader(const QByteArray& key, const QByteArray& value); HeaderTypes getCommand() const; std::tuple getHeader(int i) const; bool addTextBody(const QString& body); bool addByteArrayBody(const QByteArray& body); + QString getTextBody() const; QByteArray convertToByteArray(); QString convertToQString(); - bool isBinaryBody(); + QStringList getCommandQStringList(); + private: QString convertCommandToQString(HeaderTypes command) const; QByteArray convertCommandToQByteArray(HeaderTypes command) const; HeaderTypes convertCommandFromString(const QString& stringCommand) const; QByteArray escapeSpecialSymbols(const QByteArray& ba); - std::pair unescapeSpecialSymbols(const QByteArray& ba); private: //values as they are written in the frame @@ -42,21 +46,12 @@ class StompFrame { std::vector m_ValuesString; QByteArray m_BodyBA; QString m_BodyString; - bool m_BinaryBody = false; + QStringList m_CommandTypeStringList; + + const std::vector m_HeaderTypesList { HeaderTypes::CONNECT, HeaderTypes::STOMP, HeaderTypes::CONNECTED, HeaderTypes::SEND, HeaderTypes::SUBSCRIBE, HeaderTypes::UNSUBSCRIBE, HeaderTypes::ACK, HeaderTypes::NACK, HeaderTypes::BEGIN, HeaderTypes::COMMIT, HeaderTypes::ABORT, HeaderTypes::DISCONNECT, HeaderTypes::MESSAGE, HeaderTypes::RECEIPT, HeaderTypes::ERROR, HeaderTypes::UNKNOWN }; friend class StompFrameTest; }; - - - - - - - - - - - #endif diff --git a/c_plus_plus/stomp/stompframecreator.cpp b/c_plus_plus/stomp/stompframecreator.cpp index 212a3bfc..5ddf435e 100644 --- a/c_plus_plus/stomp/stompframecreator.cpp +++ b/c_plus_plus/stomp/stompframecreator.cpp @@ -49,7 +49,7 @@ std::shared_ptr StompFrameCreator::createSendTextFrame(const QString auto stompFrame = std::make_shared(); stompFrame->setCommand(StompFrame::HeaderTypes::SEND); stompFrame->addHeader("destination", destination); - stompFrame->addHeader("content-type", "application/json"); + stompFrame->addHeader("content-type", QString("application/json")); stompFrame->addTextBody(message); return stompFrame; } diff --git a/c_plus_plus/stomp/stompframeparser.cpp b/c_plus_plus/stomp/stompframeparser.cpp new file mode 100644 index 00000000..72e69e4e --- /dev/null +++ b/c_plus_plus/stomp/stompframeparser.cpp @@ -0,0 +1,141 @@ +#include "stompframeparser.h" +#include + +std::shared_ptr StompFrameParser::parseFromTextMessage(const QString& message, bool& error) { + + error = true; + + int posBodyDelimiter = -1; + QString bodyDelimiter; + bool errorParseBodyDelimiter = false; + + std::tie(posBodyDelimiter, bodyDelimiter, errorParseBodyDelimiter) = findBodyDelimiterWithRegex(message); + + if (errorParseBodyDelimiter) { + error = false; //no body + qDebug() << "Stomp frame parser error : No body delimiter found"; + return std::make_shared(); + } + + QString header = message.left(posBodyDelimiter); + QString body = message.last(message.size() - header.size() - bodyDelimiter.size()); + + QStringList headerParts = header.split(QRegularExpression("\r?\n")); + + if (headerParts.empty()) { + error = false; //no header + qDebug() << "Stomp frame parser error : No header found"; + return std::make_shared(); + } + + auto stompFrame = std::make_shared(); + + if (headerParts[0] == "UNKNOWN" || stompFrame->getCommandQStringList().indexOf(headerParts[0]) < 0) { + error = false; //unknown command + qDebug() << "Stomp frame parser error : Unknown command" << headerParts[0]; + return stompFrame; + } + + bool errSetCommand = stompFrame->setCommand(headerParts[0]); + + if (!errSetCommand) { + error = false; //unknown command + qDebug() << "Stomp frame parser error : Unknown command" << headerParts[0]; + return stompFrame; + } + + for (int i = 1; i < headerParts.size(); i++) { + QString curHeader = headerParts[i]; + QStringList curHeaderKeyAndValue = curHeader.split(":"); + if (curHeaderKeyAndValue.size() != 2) { + error = false; //falsely formatted key value pair + qDebug() << "Stomp frame parser error : Falsely formatted header line " << curHeader; + return stompFrame; + } + + QByteArray unescapedKeyBA; + QByteArray unescapedValueBA; + + bool errorUnescapeKey = true; + bool errorUnescapeValue = true; + + std::tie(errorUnescapeKey, unescapedKeyBA) = unescapeSpecialSymbols(curHeaderKeyAndValue[0].toUtf8()); + std::tie(errorUnescapeValue, unescapedValueBA) = unescapeSpecialSymbols(curHeaderKeyAndValue[1].toUtf8()); + + if (!errorUnescapeKey || !errorUnescapeValue) { + error = false; //falsely escape key or value + qDebug() << "Stomp frame parser error : Falsely escaped header or key " << curHeader; + return stompFrame; + } + + stompFrame->addHeader(unescapedKeyBA, unescapedValueBA); + } + + if (body.isEmpty() || body.back() != QChar(0)) { + error = false; //body empty + qDebug() << "Stomp frame parser error : False formatted body " << body; + return stompFrame; + } + + stompFrame->addTextBody(body.left(body.size() - 1)); + error = true; + + return stompFrame; +} + +std::tuple StompFrameParser::findBodyDelimiterWithRegex(const QString& message) { + + QRegularExpression regEx("\r?\n\r?\n"); + QRegularExpressionMatch match = regEx.match(message); + if (match.hasMatch()) { + QString matched = match.captured(0); + int startOffset = match.capturedStart(0); + return std::make_tuple(startOffset, matched, false); + } else { + return std::make_tuple(-1, QString(), true); + } +} + +std::pair StompFrameParser::unescapeSpecialSymbols(const QByteArray& ba) { + QByteArray::const_iterator it = ba.begin(); + QByteArray retVal; + + bool found92 = false; + while (it != ba.end()) { + if (*it == 92) { + if (found92) { + retVal.append(92); + found92 = false; + } else { + found92 = true; + } + } else if (*it == 110) { + if (found92) + retVal.append(10); + else + retVal.append(110); + found92 = false; + } else if (*it == 114) { + if (found92) + retVal.append(13); + else + retVal.append(114); + found92 = false; + } else if (*it == 99) { + if (found92) + retVal.append(58); + else + retVal.append(99); + found92 = false; + } else { + if (found92) + return std::make_pair(false, QByteArray(1, 0)); + retVal.append(*it); + } + it++; + } + + return std::make_pair(true, retVal); +} + + diff --git a/c_plus_plus/stomp/stompframeparser.h b/c_plus_plus/stomp/stompframeparser.h new file mode 100644 index 00000000..cc502caf --- /dev/null +++ b/c_plus_plus/stomp/stompframeparser.h @@ -0,0 +1,21 @@ +#ifndef __STOMPFRAMEPARSER_ +#define __STOMPFRAMEPARSER_ + +#include +#include +#include +#include "stompframe.h" + +class StompFrameParser { + +public: + std::shared_ptr parseFromTextMessage(const QString& message, bool& error); + +private: + std::tuple findBodyDelimiterWithRegex(const QString& message); + std::pair unescapeSpecialSymbols(const QByteArray& ba); + + friend class StompFrameParserTest; +}; + +#endif diff --git a/c_plus_plus/tests/stomptests/CMakeLists.txt b/c_plus_plus/tests/stomptests/CMakeLists.txt index 1d5b548f..41dfcdb4 100644 --- a/c_plus_plus/tests/stomptests/CMakeLists.txt +++ b/c_plus_plus/tests/stomptests/CMakeLists.txt @@ -15,10 +15,12 @@ include_directories( set(TEST_HEADR stompframetest.h + stompframeparsertest.h ) set(TEST_SRCS stompframetest.cpp + stompframeparsertest.cpp main.cpp) enable_testing(true) diff --git a/c_plus_plus/tests/stomptests/main.cpp b/c_plus_plus/tests/stomptests/main.cpp index a18f629b..071cacd9 100644 --- a/c_plus_plus/tests/stomptests/main.cpp +++ b/c_plus_plus/tests/stomptests/main.cpp @@ -1,4 +1,5 @@ #include "stompframetest.h" +#include "stompframeparsertest.h" #include @@ -10,5 +11,10 @@ int main(int argc, char** argv) status |= QTest::qExec(&tc, argc, argv); } + { + StompFrameParserTest tc; + status |= QTest::qExec(&tc, argc, argv); + } + return status; } diff --git a/c_plus_plus/tests/stomptests/stompframeparsertest.cpp b/c_plus_plus/tests/stomptests/stompframeparsertest.cpp new file mode 100644 index 00000000..74a71393 --- /dev/null +++ b/c_plus_plus/tests/stomptests/stompframeparsertest.cpp @@ -0,0 +1,105 @@ +#include "stompframeparsertest.h" +#include +#include "stompframeparser.h" + +void StompFrameParserTest::initTestCase() { + qDebug("StompFrameParserTest starts .."); +} + +void StompFrameParserTest::parseBodyDelimiterFromMessageDoesNotExist() { + StompFrameParser parser; + int pos = 0; + QString delim; + bool error = false; + + std::tie(pos, delim, error) = parser.findBodyDelimiterWithRegex("abcdefghtifs\\n\n"); + QVERIFY2(-1 == pos, "Found position is not correct"); + QVERIFY2(delim.isEmpty(), "Found delimiter is not correct"); + QVERIFY2(error == true, "An error is not found"); +} + +void StompFrameParserTest::parseBodyDelimiterFromMessageLongExists() { + StompFrameParser parser; + int pos = 0; + QString delim; + bool error = false; + + std::tie(pos, delim, error) = parser.findBodyDelimiterWithRegex("abcdefghtifs\r\n\r\n"); + QVERIFY2(12 == pos, "Found position is not correct"); + QVERIFY2("\r\n\r\n" == delim, "Found delimiter is not correct"); + QVERIFY2(error == false, "An error was found"); +} + +void StompFrameParserTest::parseBodyDelimiterFromMessageExists() { + StompFrameParser parser; + int pos = 0; + QString delim; + bool error = false; + + std::tie(pos, delim, error) = parser.findBodyDelimiterWithRegex("ab\\pcdefg\n\npkfhd"); + QVERIFY2(9 == pos, "Found position is not correct"); + QVERIFY2("\n\n" == delim, "Found delimiter is not correct"); + QVERIFY2(error == false, "An error was found"); +} + +void StompFrameParserTest::parseBodyDelimiterFromMessageDoubleExist() { + StompFrameParser parser; + int pos = 0; + QString delim; + bool error = false; + + std::tie(pos, delim, error) = parser.findBodyDelimiterWithRegex("ab\\pcdefg\r\n\r\n\npkfhd"); + QVERIFY2(9 == pos, "Found position is not correct"); + QVERIFY2("\r\n\r\n" == delim, "Found delimiter is not correct"); + QVERIFY2(error == false, "An error was not found"); +} + +void StompFrameParserTest::unescapeSpecialSymbolsTestColon() { + StompFrameParser parser; + auto res = parser.unescapeSpecialSymbols("test\\ctest"); + QVERIFY2(res.first, "Decoding of : failed"); + QString errorMsg = QString("Decoding of : failed ") + QString(res.second); + QVERIFY2(QString(res.second) == "test:test", errorMsg.toUtf8().data()); +} + +void StompFrameParserTest::unescapeSpecialSymbolsTestSlash() { + StompFrameParser parser; + auto res = parser.unescapeSpecialSymbols("test\\\\test"); + QVERIFY2(res.first, "Decoding of \\ failed "); + QString errorMsg = QString("Decoding of \\ failed ") + QString(res.second); + QVERIFY2(QString(res.second) == "test\\test", errorMsg.toUtf8().data()); +} + +void StompFrameParserTest::unescapeSpecialSymbolsTestCarriageReturn() { + StompFrameParser parser; + auto res = parser.unescapeSpecialSymbols("test\\rtest"); + QVERIFY2(res.first, "Decoding of \\r failed "); + QString errorMsg = QString("Decoding of \\r failed ") + QString(res.second); + QVERIFY2(QString(res.second) == "test\rtest", errorMsg.toUtf8().data()); +} + +void StompFrameParserTest::unescapeSpecialSymbolsTestLineFeed() { + StompFrameParser parser; + auto res = parser.unescapeSpecialSymbols("test\\ntest"); + QVERIFY2(res.first, "Decoding of \\n failed"); + QString errorMsg = QString("Decoding of \\n failed ") + QString(res.second); + QVERIFY2(QString(res.second) == "test\ntest", errorMsg.toUtf8().data()); +} + +void StompFrameParserTest::unescapeSpecialSymbolsTestWorks() { + StompFrameParser parser; + auto res = parser.unescapeSpecialSymbols("testtest"); + QVERIFY2(res.first, "Decoding of testtest failed"); + QString errorMsg = QString("Decoding of test failed ") + QString(res.second); + QVERIFY2(QString(res.second) == "testtest", errorMsg.toUtf8().data()); +} + +void StompFrameParserTest::unescapeSpecialSymbolsTestIllegalSymbols() { + StompFrameParser parser; + auto res = parser.unescapeSpecialSymbols("test\\ftest"); + QVERIFY2(!res.first, "Illegal symbol not recognized"); +} + +void StompFrameParserTest::cleanupTestCase() { + qDebug("StompFrameParserTest ends .."); +} diff --git a/c_plus_plus/tests/stomptests/stompframeparsertest.h b/c_plus_plus/tests/stomptests/stompframeparsertest.h new file mode 100644 index 00000000..884ac957 --- /dev/null +++ b/c_plus_plus/tests/stomptests/stompframeparsertest.h @@ -0,0 +1,24 @@ +#ifndef __STOMPFRAMEPARSER_TEST__ +#define __STOMPFRAMEPARSER_TEST__ + +#include + +class StompFrameParserTest : public QObject { + Q_OBJECT + +private slots: + void initTestCase(); + void parseBodyDelimiterFromMessageDoesNotExist(); + void parseBodyDelimiterFromMessageLongExists(); + void parseBodyDelimiterFromMessageExists(); + void parseBodyDelimiterFromMessageDoubleExist(); + void unescapeSpecialSymbolsTestColon(); + void unescapeSpecialSymbolsTestSlash(); + void unescapeSpecialSymbolsTestCarriageReturn(); + void unescapeSpecialSymbolsTestLineFeed(); + void unescapeSpecialSymbolsTestWorks(); + void unescapeSpecialSymbolsTestIllegalSymbols(); + void cleanupTestCase(); +}; + +#endif diff --git a/c_plus_plus/tests/stomptests/stompframetest.cpp b/c_plus_plus/tests/stomptests/stompframetest.cpp index dbe548a2..122ecdaf 100644 --- a/c_plus_plus/tests/stomptests/stompframetest.cpp +++ b/c_plus_plus/tests/stomptests/stompframetest.cpp @@ -2,6 +2,7 @@ #include #include "stompframe.h" +#include "stompframeparser.h" void StompFrameTest::initTestCase() { @@ -55,53 +56,6 @@ void StompFrameTest::escapeSpecialSymbolsTestWorks() { QVERIFY2(QString(ba) == "testtest", errorMsg.toUtf8().data()); } -void StompFrameTest::unescapeSpecialSymbolsTestColon() { - StompFrame frame; - auto res = frame.unescapeSpecialSymbols("test\\ctest"); - QVERIFY2(res.first, "Decoding of : failed"); - QString errorMsg = QString("Decoding of : failed ") + QString(res.second); - QVERIFY2(QString(res.second) == "test:test", errorMsg.toUtf8().data()); -} - -void StompFrameTest::unescapeSpecialSymbolsTestSlash() { - StompFrame frame; - auto res = frame.unescapeSpecialSymbols("test\\\\test"); - QVERIFY2(res.first, "Decoding of \\ failed "); - QString errorMsg = QString("Decoding of \\ failed ") + QString(res.second); - QVERIFY2(QString(res.second) == "test\\test", errorMsg.toUtf8().data()); -} - -void StompFrameTest::unescapeSpecialSymbolsTestCarriageReturn() { - StompFrame frame; - auto res = frame.unescapeSpecialSymbols("test\\rtest"); - QVERIFY2(res.first, "Decoding of \\r failed "); - QString errorMsg = QString("Decoding of \\r failed ") + QString(res.second); - QVERIFY2(QString(res.second) == "test\rtest", errorMsg.toUtf8().data()); -} - -void StompFrameTest::unescapeSpecialSymbolsTestLineFeed() { - StompFrame frame; - auto res = frame.unescapeSpecialSymbols("test\\ntest"); - QVERIFY2(res.first, "Decoding of \\n failed"); - QString errorMsg = QString("Decoding of \\n failed ") + QString(res.second); - QVERIFY2(QString(res.second) == "test\ntest", errorMsg.toUtf8().data()); -} - -void StompFrameTest::unescapeSpecialSymbolsTestWorks() { - StompFrame frame; - auto res = frame.unescapeSpecialSymbols("testtest"); - QVERIFY2(res.first, "Decoding of testtest failed"); - QString errorMsg = QString("Decoding of test failed ") + QString(res.second); - QVERIFY2(QString(res.second) == "testtest", errorMsg.toUtf8().data()); -} - -void StompFrameTest::unescapeSpecialSymbolsTestIllegalSymbols() { - StompFrame frame; - auto res = frame.unescapeSpecialSymbols("test\\ftest"); - QVERIFY2(!res.first, "Illegal symbol not recognized"); -} - -void StompFrameTest::cleanupTestCase() -{ +void StompFrameTest::cleanupTestCase() { qDebug("StompFrameTest ends .."); } diff --git a/c_plus_plus/tests/stomptests/stompframetest.h b/c_plus_plus/tests/stomptests/stompframetest.h index 1354e843..39eecc9a 100644 --- a/c_plus_plus/tests/stomptests/stompframetest.h +++ b/c_plus_plus/tests/stomptests/stompframetest.h @@ -14,12 +14,6 @@ private slots: void escapeSpecialSymbolsTestCarriageReturn(); void escapeSpecialSymbolsTestLineFeed(); void escapeSpecialSymbolsTestWorks(); - void unescapeSpecialSymbolsTestColon(); - void unescapeSpecialSymbolsTestSlash(); - void unescapeSpecialSymbolsTestCarriageReturn(); - void unescapeSpecialSymbolsTestLineFeed(); - void unescapeSpecialSymbolsTestWorks(); - void unescapeSpecialSymbolsTestIllegalSymbols(); void cleanupTestCase(); };