Add test for sasl module

This commit is contained in:
Alexey Sokolov
2020-03-29 11:12:01 +01:00
parent 5a047d4b58
commit b1d4cb0ae5
2 changed files with 97 additions and 6 deletions
+22
View File
@@ -40,6 +40,8 @@ class IO {
* Have to use second param as the ASSERT_*'s return a non-QByteArray.
*/
void ReadUntilAndGet(QByteArray pattern, QByteArray& match);
// Can be used to check that something was not sent. Slow.
QByteArray ReadRemainder();
void Write(QByteArray s = "", bool new_line = true);
void Close();
@@ -140,6 +142,9 @@ void IO<Device>::ReadUntilAndGet(QByteArray pattern, QByteArray& match) {
if (search != -1) {
match += m_readed.mid(start, search - start);
m_readed.remove(0, search + 1);
if (match.endsWith('\r')) {
match.chop(1);
}
return;
}
/* No newline yet, add to retvalue and trunc output */
@@ -162,6 +167,23 @@ void IO<Device>::ReadUntilAndGet(QByteArray pattern, QByteArray& match) {
}
}
template <typename Device>
QByteArray IO<Device>::ReadRemainder() {
auto deadline = QDateTime::currentDateTime().addSecs(2);
while (QDateTime::currentDateTime() < deadline) {
const int timeout_ms =QDateTime::currentDateTime().msecsTo(deadline);
m_device->waitForReadyRead(std::max(1, timeout_ms));
QByteArray chunk = m_device->readAll();
if (m_verbose) {
std::cout << chunk.toStdString() << std::flush;
}
m_readed += chunk;
}
QByteArray result = std::move(m_readed);
m_readed.clear();
return result;
}
template <typename Device>
void IO<Device>::Write(QByteArray s, bool new_line) {
if (!m_device) return;