summaryrefslogtreecommitdiffstats
path: root/tests/guidevtest/unittestinfo.cpp
blob: 08bcc26073a11ab423538e78bbd837424fd806c3 (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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "unittests.h"
#include "serialportinfo.h"



/* Public methods */

UnitTestInfo::UnitTestInfo(Logger *logger, QObject *parent)
    : UnitTestBase(UnitTestBase::InfoUnitId, logger, parent)
{
    m_name = QString(tr("Info Test"));
    m_description = QString(tr("\"Info Test\" tested class SerialPortInfo,\n"
                               "by calling its methods and write the results to a log.\n\n"
                               "In the log lists all serial ports that were discovered,\n"
                               "their properties, states, and supported standard rates."));
}

/* Public slots */

void UnitTestInfo::start(bool first)
{
    Q_UNUSED (first);

    QString header(tr("\n[ Test: ID#%1, Name: %2 ]\n%3\n\n"));
    header = header
            .arg(m_id)
            .arg(m_name)
            .arg(QString("timestamp"));/*.arg(UnitTestManager::timestamp());*/

    m_logger->addContent(header);

    int it = 0;
    foreach (SerialPortInfo inf, SerialPortInfo::availablePorts()) {
        QString body(tr("Port# %1, name : %2\n"
                        "  location    : %3\n"
                        "  description : %4\n"
                        "  valid       : %5\n"
                        "  busy        : %6\n"
                        "  rates       : %7\n"));

        QString r;
        foreach (qint32 rate, inf.standardRates()) {
            r.append(QString::number(rate));
            r.append(';');
        }

        body = body
                .arg(it++)
                .arg(inf.portName())
                .arg(inf.systemLocation())
                .arg(inf.description())
                .arg(inf.isValid())
                .arg(inf.isBusy())
                .arg(r);

        m_logger->addContent(body);
    }

    QString trailer(tr("\nFound %1 ports.\n"));
    trailer = trailer.arg(it);
    m_logger->addContent(trailer);

    emit finished();
}