summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorkuzulis <scapig2@yandex.ru>2011-10-16 00:26:50 +0400
committerkuzulis <kuzulis@myhost.(none)>2011-10-16 00:26:50 +0400
commit9e988db61d88016b68dc96f7ff7de61377af926c (patch)
treeef20a3054f0aebdb908cf340c2058fef16cdbf7d /tests
parent3421f4b8bc8729d59efb1593c7852260d7161df2 (diff)
downloadqtserialport-9e988db61d88016b68dc96f7ff7de61377af926c.tar.gz
Modify unit test /tests/guidevtest
Diffstat (limited to 'tests')
-rw-r--r--tests/guidevtest/guidevtest.pro12
-rw-r--r--tests/guidevtest/main.cpp5
-rw-r--r--tests/guidevtest/maindialog.cpp3
-rw-r--r--tests/guidevtest/testsdialog.cpp3
-rw-r--r--tests/guidevtest/testsdialog.ui10
-rw-r--r--tests/guidevtest/unittestinfo.cpp54
-rw-r--r--tests/guidevtest/unittestinfo.h17
-rw-r--r--tests/guidevtest/unittestmanager.cpp142
-rw-r--r--tests/guidevtest/unittestmanager.h69
9 files changed, 279 insertions, 36 deletions
diff --git a/tests/guidevtest/guidevtest.pro b/tests/guidevtest/guidevtest.pro
index 9ed3d0b..d92123f 100644
--- a/tests/guidevtest/guidevtest.pro
+++ b/tests/guidevtest/guidevtest.pro
@@ -15,8 +15,7 @@ INCLUDEPATH += \
HEADERS += \
../../include/serialport.h \
- ../../include/serialportinfo.h \
- unittestmanager.h
+ ../../include/serialportinfo.h
include(../../src/src.pri)
@@ -24,11 +23,14 @@ SOURCES += \
main.cpp \
maindialog.cpp \
testsdialog.cpp \
- unittestmanager.cpp
+ unittestmanager.cpp \
+ unittestinfo.cpp
HEADERS += \
maindialog.h \
- testsdialog.h
+ testsdialog.h \
+ unittestmanager.h \
+ unittestinfo.h
FORMS += \
maindialog.ui \
@@ -38,3 +40,5 @@ FORMS += \
+
+
diff --git a/tests/guidevtest/main.cpp b/tests/guidevtest/main.cpp
index b50363e..f955681 100644
--- a/tests/guidevtest/main.cpp
+++ b/tests/guidevtest/main.cpp
@@ -4,6 +4,11 @@
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
+
+ QCoreApplication::setOrganizationName("Kuzulis");
+ QCoreApplication::setOrganizationDomain("kuzulis.com");
+ QCoreApplication::setApplicationName("QSerialDevice unit test");
+
MainDialog w;
w.show();
diff --git a/tests/guidevtest/maindialog.cpp b/tests/guidevtest/maindialog.cpp
index 75cdb4b..398ae65 100644
--- a/tests/guidevtest/maindialog.cpp
+++ b/tests/guidevtest/maindialog.cpp
@@ -63,7 +63,8 @@ void MainDialog::procIdleState()
void MainDialog::procOptionsState()
{
- TestsDialog dlg(m_utManager);//();
+ TestsDialog dlg(m_utManager);
+ //dlg.setModal(true);
dlg.exec();
emit toIdle();
diff --git a/tests/guidevtest/testsdialog.cpp b/tests/guidevtest/testsdialog.cpp
index 3b4faa5..5fcc5a9 100644
--- a/tests/guidevtest/testsdialog.cpp
+++ b/tests/guidevtest/testsdialog.cpp
@@ -7,6 +7,9 @@ TestsDialog::TestsDialog(UnitTestManager *manager)
, m_utManager(manager)
{
ui->setupUi(this);
+
+ foreach (UnitTestBase *unit, m_utManager->units())
+ ui->listWidget->addItem(unit->name());
}
TestsDialog::~TestsDialog()
diff --git a/tests/guidevtest/testsdialog.ui b/tests/guidevtest/testsdialog.ui
index f78fd5c..7d60c1c 100644
--- a/tests/guidevtest/testsdialog.ui
+++ b/tests/guidevtest/testsdialog.ui
@@ -2,17 +2,23 @@
<ui version="4.0">
<class>TestsDialog</class>
<widget class="QDialog" name="TestsDialog">
+ <property name="windowModality">
+ <enum>Qt::NonModal</enum>
+ </property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
- <width>132</width>
+ <width>146</width>
<height>172</height>
</rect>
</property>
<property name="windowTitle">
<string>Available tests</string>
</property>
+ <property name="modal">
+ <bool>false</bool>
+ </property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QListWidget" name="listWidget"/>
@@ -20,7 +26,7 @@
<item>
<widget class="QCheckBox" name="brkBox">
<property name="text">
- <string>Break tests on error</string>
+ <string>Break all tests on error</string>
</property>
</widget>
</item>
diff --git a/tests/guidevtest/unittestinfo.cpp b/tests/guidevtest/unittestinfo.cpp
new file mode 100644
index 0000000..a45ce6e
--- /dev/null
+++ b/tests/guidevtest/unittestinfo.cpp
@@ -0,0 +1,54 @@
+#include "unittestinfo.h"
+#include "serialportinfo.h"
+
+UnitTestInfo::UnitTestInfo(QObject *parent)
+ : UnitTestBase(UnitTestBase::InfoUnitId, parent)
+{
+ m_name = QString(tr("Info Test"));
+ m_description = QString(tr("Info Test Description"));
+}
+
+void UnitTestInfo::start()
+{
+ bool ret = openLog();
+ if (!ret) {
+ emit error();
+ return;
+ }
+
+ QString header("Test: ID# %1, Name: %2, %3");
+ header = header
+ .arg(m_id)
+ .arg(m_name)
+ .arg(getDateTime());
+
+ if (writeToLog(header)) {
+ int it = 0;
+ foreach (SerialPortInfo inf, SerialPortInfo::availablePorts()) {
+ QString s("Port# %1, name: %2\n"
+ " location : %3\n"
+ " description : %4\n"
+ " valid : %5\n"
+ " busy : %6");
+
+ s = s
+ .arg(it++)
+ .arg(inf.portName())
+ .arg(inf.systemLocation())
+ .arg(inf.description())
+ .arg(inf.isValid())
+ .arg(inf.isBusy());
+
+ ret = writeToLog(s);
+ if (!ret)
+ break;
+ }
+
+ }
+ closeLog();
+
+ if (ret)
+ emit finished();
+ else
+ emit error();
+}
diff --git a/tests/guidevtest/unittestinfo.h b/tests/guidevtest/unittestinfo.h
new file mode 100644
index 0000000..e1048f1
--- /dev/null
+++ b/tests/guidevtest/unittestinfo.h
@@ -0,0 +1,17 @@
+#ifndef UNITTESTINFO_H
+#define UNITTESTINFO_H
+
+#include "unittestmanager.h"
+
+class UnitTestInfo : public UnitTestBase
+{
+ Q_OBJECT
+public:
+ explicit UnitTestInfo(QObject *parent = 0);
+
+public slots:
+ virtual void start();
+
+};
+
+#endif // UNITTESTINFO_H
diff --git a/tests/guidevtest/unittestmanager.cpp b/tests/guidevtest/unittestmanager.cpp
index 610d299..dd8e6d2 100644
--- a/tests/guidevtest/unittestmanager.cpp
+++ b/tests/guidevtest/unittestmanager.cpp
@@ -1,51 +1,165 @@
#include "unittestmanager.h"
+#include "unittestinfo.h"
#include <QtCore/QTimer>
+#include <QtCore/QSettings>
+#include <QtCore/QDateTime>
+
+
+const QString UnitTestManager::logFileParam = "UnitTestManager/logFile";
+
+
+// UnitTestBase
/* Public methods */
-bool UnitTestBase::isUse() const
+UnitTestBase::UnitTestBase(UnitID id, QObject *parent)
+ : QObject(parent)
+ , m_id(id)
+{
+ m_enableParam = "%1/enable";
+}
+
+void UnitTestBase::setPorts(const QString &src, const QString &dst)
+{
+ m_srcPort = src;
+ m_dstPort = dst;
+}
+
+void UnitTestBase::setEnable(bool enable)
+{
+ QSettings settings;
+ settings.setValue(m_enableParam.arg(m_id), enable);
+}
+
+bool UnitTestBase::isEnabled() const
+{
+ QSettings settings;
+ return settings.value(m_enableParam.arg(m_id)).toBool();
+}
+
+int UnitTestBase::id() const
+{
+ return m_id;
+}
+
+QString UnitTestBase::name() const
+{
+ return m_name;
+}
+
+QString UnitTestBase::description() const
+{
+ return m_description;
+}
+
+/* Protected methods */
+
+bool UnitTestBase::openLog()
+{
+ QSettings settings;
+ m_log.setFileName(settings.value(UnitTestManager::logFileParam).toString());
+ return (m_log.exists() && m_log.open(QIODevice::WriteOnly | QIODevice::Append));
+}
+
+bool UnitTestBase::writeToLog(const QString &content)
+{
+ return (m_log.write(content.toLocal8Bit()) > 0);
+}
+
+void UnitTestBase::closeLog()
+{
+ m_log.close();
+}
+
+QString UnitTestBase::getDateTime() const
{
- return false;
+ return QDateTime::currentDateTime().toString();
}
-UnitTestBase *UnitTestFactory::create(UnitTypes unit)
+
+
+// UnitTestFactory
+
+/* Public methods */
+
+UnitTestBase *UnitTestFactory::create(UnitTestBase::UnitID id)
{
+ switch (id) {
+ case UnitTestBase::InfoUnitId:
+ return new UnitTestInfo();
+ default:;
+ }
+
return 0;
}
+
+
+// UnitTestManager
+
+/* Public methods */
+
UnitTestManager::UnitTestManager(QObject *parent)
: QObject(parent)
, m_count(0)
, m_it(0)
{
- m_timer = new QTimer(this);
- m_timer->setInterval(1000);
- connect(m_timer, SIGNAL(timeout()), this, SLOT(step()));
-
- // Create units.
- m_unitList.append(UnitTestFactory::create(UnitTestFactory::InfoTestUnit));
+ // Create all units.
+ m_unitList.append(UnitTestFactory::create(UnitTestBase::InfoUnitId));
+ //..
+ //...
+ foreach (UnitTestBase *unit, m_unitList)
+ connect(unit, SIGNAL(finished()), this, SLOT(step()));
m_count = m_unitList.count();
}
+void UnitTestManager::setPorts(const QString &src, const QString &dst)
+{
+ m_srcPort = src;
+ m_dstPort = dst;
+}
+
+void UnitTestManager::setLogFile(const QString &log)
+{
+
+}
+
+QList<UnitTestBase *> UnitTestManager::units() const
+{
+ return m_unitList;
+}
+
+
+
/* Public slots */
void UnitTestManager::start()
{
m_it = 0;
- m_timer->start();
+ step();
}
void UnitTestManager::stop()
{
- m_timer->stop();
}
/* Private slots */
- void UnitTestManager::step()
- {
+void UnitTestManager::step()
+{
+ if (m_it == m_count) {
+ emit allFinished();
+ return;
+ }
- }
+ UnitTestBase *unit = m_unitList.at(m_it++);
+ if (unit->isEnabled()) {
+ unit->setPorts(m_srcPort, m_dstPort);
+ QTimer::singleShot(1000, unit, SLOT(start()));
+ }
+ else
+ step();
+}
diff --git a/tests/guidevtest/unittestmanager.h b/tests/guidevtest/unittestmanager.h
index 399a106..12b2540 100644
--- a/tests/guidevtest/unittestmanager.h
+++ b/tests/guidevtest/unittestmanager.h
@@ -2,37 +2,76 @@
#define UNITTESTMANAGER_H
#include <QtCore/QObject>
+#include <QtCore/QFile>
-class QTimer;
-class UnitTestManager;
-
-class UnitTestBase
+class UnitTestBase : public QObject
{
+ Q_OBJECT
+signals:
+ void finished();
+ void error();
+
public:
- bool isUse() const;
+ enum UnitID {
+ InfoUnitId,
+
+ };
+
+ explicit UnitTestBase(UnitID id, QObject *parent = 0);
+ void setPorts(const QString &src, const QString &dst);
+ void setEnable(bool enable);
+ bool isEnabled() const;
+
+ int id() const;
+ QString name() const;
+ QString description() const;
+
+public slots:
+ virtual void start() = 0;
+
+protected:
+ int m_id;
+ QString m_name;
+ QString m_description;
+ QString m_enableParam;
+
+ bool openLog();
+ bool writeToLog(const QString &content);
+ void closeLog();
+
+ QString getDateTime() const;
+private:
+ QString m_srcPort;
+ QString m_dstPort;
+ QFile m_log;
};
+
+
class UnitTestFactory
{
public:
- enum UnitTypes {
- InfoTestUnit,
+ static UnitTestBase *create(UnitTestBase::UnitID id);
+};
- };
- static UnitTestBase *create(UnitTypes unit);
-};
class UnitTestManager : public QObject
{
Q_OBJECT
+signals:
+ void started();
+ void allFinished();
+
public:
explicit UnitTestManager(QObject *parent = 0);
+ void setPorts(const QString &src, const QString &dst);
+ void setLogFile(const QString &log);
-signals:
- void started();
- void stopped();
+ QList<UnitTestBase *> units() const;
+
+ static const QString logFileParam;
public slots:
void start();
@@ -44,9 +83,9 @@ private slots:
private:
int m_count;
int m_it;
- QTimer *m_timer;
+ QString m_srcPort;
+ QString m_dstPort;
QList<UnitTestBase *> m_unitList;
-
};
#endif // UNITTESTMANAGER_H