mirror of
https://github.com/znc/znc.git
synced 2026-08-07 09:22:55 +02:00
Add test for sasl module
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user