summaryrefslogtreecommitdiff
path: root/tests/common/printQtTypes.cpp
blob: 72975b754a220eddb8cfccd16e073921d9dcf92c (plain)
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
#include "printQtTypes.h"

void PrintTo(const QString& str, ::std::ostream* os)
{
    *os << "\"" << str.toStdString() << "\"";
}

void PrintTo(const QStringList& list, ::std::ostream* os)
{
    *os << "(" << list.join(", ").toStdString() << ")";
}

void PrintTo(const QDateTime& time, ::std::ostream* os)
{
    *os << time.toString("yyyy-MM-dd HH:mm:ss").toStdString();
}

void PrintTo(const QByteArray& array, ::std::ostream* os)
{
    *os << "\"";
    const char* hex = array.toHex().constData();
    for(int i = 0; i < array.size(); i++)
    {
        unsigned char ch =  array.constData()[i];
        if(ch >= 32 && ch <= 126)
            *os << ch;
        else
            *os << "\\x" << hex[i * 2] << hex[i * 2 + 1] << " ";
    }
    *os << "\"";
}