File: TestUtils.cpp

package info (click to toggle)
sfxr-qt 1.5.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 10,988 kB
  • sloc: cpp: 48,737; python: 1,885; sh: 385; makefile: 4
file content (32 lines) | stat: -rw-r--r-- 836 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "TestUtils.h"

#include <QDebug>
#include <QFile>

QByteArray loadFile(const QString& path) {
    QFile file(path);
    if (!file.open(QIODevice::ReadOnly)) {
        qCritical() << "Could not load" << path << ":" << file.errorString();
        return {};
    }
    return file.readAll();
}

QtDebugSilencer::QtDebugSilencer() {
    auto silentHandler = [](QtMsgType, const QMessageLogContext&, const QString&) {};
    mOldHandler = qInstallMessageHandler(silentHandler);
}

QtDebugSilencer::~QtDebugSilencer() {
    qInstallMessageHandler(mOldHandler);
}

std::ostream& operator<<(std::ostream& ostr, const QString& str) {
    ostr << '"' << str.toStdString() << '"';
    return ostr;
}

std::ostream& operator<<(std::ostream& ostr, const QUrl& url) {
    ostr << '"' << url.toEncoded().constData() << '"';
    return ostr;
}