summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/guidevtest/maindialog.cpp2
-rw-r--r--tests/guidevtest/maindialog.h2
-rw-r--r--tests/guidevtest/testsdialog.cpp75
-rw-r--r--tests/guidevtest/testsdialog.h27
-rw-r--r--tests/guidevtest/unittestinfo.cpp17
-rw-r--r--tests/guidevtest/unittestinfo.h2
-rw-r--r--tests/guidevtest/unittestmanager.cpp57
-rw-r--r--tests/guidevtest/unittestmanager.h20
8 files changed, 151 insertions, 51 deletions
diff --git a/tests/guidevtest/maindialog.cpp b/tests/guidevtest/maindialog.cpp
index 398ae65..3e5a3b0 100644
--- a/tests/guidevtest/maindialog.cpp
+++ b/tests/guidevtest/maindialog.cpp
@@ -8,6 +8,8 @@
#include "unittestmanager.h"
#include "testsdialog.h"
+
+
/* Public methods */
MainDialog::MainDialog(QWidget *parent)
diff --git a/tests/guidevtest/maindialog.h b/tests/guidevtest/maindialog.h
index ebbb058..7de8154 100644
--- a/tests/guidevtest/maindialog.h
+++ b/tests/guidevtest/maindialog.h
@@ -4,6 +4,8 @@
#include <QtGui/QDialog>
#include <QtCore/QMap>
+
+
namespace Ui {
class MainDialog;
}
diff --git a/tests/guidevtest/testsdialog.cpp b/tests/guidevtest/testsdialog.cpp
index 5fcc5a9..7f7cbb6 100644
--- a/tests/guidevtest/testsdialog.cpp
+++ b/tests/guidevtest/testsdialog.cpp
@@ -2,14 +2,81 @@
#include "ui_testsdialog.h"
#include "unittestmanager.h"
+
+
+// TestsViewModel
+
+/* Public methods */
+
+TestsViewModel::TestsViewModel(UnitTestManager *manager, QObject *parent)
+ : QAbstractListModel(parent)
+{
+ m_unitList = manager->units();
+}
+
+int TestsViewModel::rowCount(const QModelIndex &parent) const
+{
+ Q_UNUSED(parent);
+ return m_unitList.count();
+}
+
+QVariant TestsViewModel::data(const QModelIndex &index, int role) const
+{
+ if (index.isValid()
+ && (index.row() < m_unitList.count())) {
+ UnitTestBase *item = m_unitList.at(index.row());
+ if (role == Qt::DisplayRole)
+ return item->name();
+ if (role == Qt::CheckStateRole)
+ return item->isEnabled() ? Qt::Checked : Qt::Unchecked;
+ }
+ return QVariant();
+}
+
+QVariant TestsViewModel::headerData(int section, Qt::Orientation orientation, int role) const
+{
+ Q_UNUSED(section);
+ Q_UNUSED(orientation);
+ Q_UNUSED(role);
+ return QVariant();
+}
+
+Qt::ItemFlags TestsViewModel::flags(const QModelIndex &index) const
+{
+ Qt::ItemFlags flag = Qt::ItemIsEnabled;
+ if (index.isValid())
+ flag |= Qt::ItemIsUserCheckable | Qt::ItemIsSelectable;
+ return flag;
+}
+
+bool TestsViewModel::setData(const QModelIndex &index, const QVariant &value, int role)
+{
+ if (index.isValid()) {
+ UnitTestBase *item = m_unitList.at(index.row());
+ if (role == Qt::CheckStateRole) {
+ bool enable = value.toBool();
+ if (item->isEnabled() != enable) {
+ item->setEnable(enable);
+ emit dataChanged(index, index);
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+
+
+// TestsDialog
+
+/* Public methods */
+
TestsDialog::TestsDialog(UnitTestManager *manager)
: ui(new Ui::TestsDialog)
- , m_utManager(manager)
{
ui->setupUi(this);
-
- foreach (UnitTestBase *unit, m_utManager->units())
- ui->listWidget->addItem(unit->name());
+ m_model = new TestsViewModel(manager, this);
+ ui->listView->setModel(m_model);
}
TestsDialog::~TestsDialog()
diff --git a/tests/guidevtest/testsdialog.h b/tests/guidevtest/testsdialog.h
index a728229..f6492d5 100644
--- a/tests/guidevtest/testsdialog.h
+++ b/tests/guidevtest/testsdialog.h
@@ -2,12 +2,35 @@
#define TESTSDIALOG_H
#include <QtGui/QDialog>
+#include <QtCore/QAbstractListModel>
+
+
namespace Ui {
- class TestsDialog;
+class TestsDialog;
}
class UnitTestManager;
+class UnitTestBase;
+
+class TestsViewModel : public QAbstractListModel
+{
+ Q_OBJECT
+public:
+ explicit TestsViewModel(UnitTestManager *manager, QObject *parent = 0);
+ virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
+ virtual QVariant data(const QModelIndex &index, int role) const;
+ virtual QVariant headerData(int section, Qt::Orientation orientation,
+ int role = Qt::DisplayRole) const;
+ virtual Qt::ItemFlags flags(const QModelIndex &index) const;
+ virtual bool setData(const QModelIndex &index, const QVariant &value,
+ int role = Qt::EditRole);
+
+private:
+ QList<UnitTestBase *> m_unitList;
+};
+
+
class TestsDialog : public QDialog
{
@@ -18,7 +41,7 @@ public:
private:
Ui::TestsDialog *ui;
- UnitTestManager *m_utManager;
+ TestsViewModel *m_model;
};
#endif // TESTSDIALOG_H
diff --git a/tests/guidevtest/unittestinfo.cpp b/tests/guidevtest/unittestinfo.cpp
index a45ce6e..bd099b1 100644
--- a/tests/guidevtest/unittestinfo.cpp
+++ b/tests/guidevtest/unittestinfo.cpp
@@ -1,6 +1,10 @@
#include "unittestinfo.h"
#include "serialportinfo.h"
+
+
+/* Public methods */
+
UnitTestInfo::UnitTestInfo(QObject *parent)
: UnitTestBase(UnitTestBase::InfoUnitId, parent)
{
@@ -8,9 +12,11 @@ UnitTestInfo::UnitTestInfo(QObject *parent)
m_description = QString(tr("Info Test Description"));
}
+/* Public slots */
+
void UnitTestInfo::start()
{
- bool ret = openLog();
+ bool ret = UnitTestManager::openLog();
if (!ret) {
emit error();
return;
@@ -20,9 +26,9 @@ void UnitTestInfo::start()
header = header
.arg(m_id)
.arg(m_name)
- .arg(getDateTime());
+ .arg(UnitTestManager::timestamp());
- if (writeToLog(header)) {
+ if (UnitTestManager::writeToLog(header)) {
int it = 0;
foreach (SerialPortInfo inf, SerialPortInfo::availablePorts()) {
QString s("Port# %1, name: %2\n"
@@ -39,13 +45,12 @@ void UnitTestInfo::start()
.arg(inf.isValid())
.arg(inf.isBusy());
- ret = writeToLog(s);
+ ret = UnitTestManager::writeToLog(s);
if (!ret)
break;
}
-
}
- closeLog();
+ UnitTestManager::closeLog();
if (ret)
emit finished();
diff --git a/tests/guidevtest/unittestinfo.h b/tests/guidevtest/unittestinfo.h
index e1048f1..540ec10 100644
--- a/tests/guidevtest/unittestinfo.h
+++ b/tests/guidevtest/unittestinfo.h
@@ -3,6 +3,8 @@
#include "unittestmanager.h"
+
+
class UnitTestInfo : public UnitTestBase
{
Q_OBJECT
diff --git a/tests/guidevtest/unittestmanager.cpp b/tests/guidevtest/unittestmanager.cpp
index dd8e6d2..4cb3ef5 100644
--- a/tests/guidevtest/unittestmanager.cpp
+++ b/tests/guidevtest/unittestmanager.cpp
@@ -6,8 +6,6 @@
#include <QtCore/QDateTime>
-const QString UnitTestManager::logFileParam = "UnitTestManager/logFile";
-
// UnitTestBase
@@ -53,30 +51,6 @@ 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 QDateTime::currentDateTime().toString();
-}
-
// UnitTestFactory
@@ -122,17 +96,38 @@ void UnitTestManager::setPorts(const QString &src, const QString &dst)
m_dstPort = dst;
}
-void UnitTestManager::setLogFile(const QString &log)
+QList<UnitTestBase *> UnitTestManager::units() const
{
+ return m_unitList;
+}
+void UnitTestManager::setLogFileName(const QString &name)
+{
+ QSettings settings;
+ settings.setValue(UnitTestManager::m_logFileParam, name);
}
-QList<UnitTestBase *> UnitTestManager::units() const
+bool UnitTestManager::openLog()
{
- return m_unitList;
+ QSettings settings;
+ m_log.setFileName(settings.value(UnitTestManager::m_logFileParam).toString());
+ return (m_log.exists() && m_log.open(QIODevice::WriteOnly | QIODevice::Append));
}
+bool UnitTestManager::writeToLog(const QString &content)
+{
+ return (m_log.write(content.toLocal8Bit()) > 0);
+}
+void UnitTestManager::closeLog()
+{
+ m_log.close();
+}
+
+QString UnitTestManager::timestamp()
+{
+ return QDateTime::currentDateTime().toString();
+}
/* Public slots */
@@ -163,3 +158,7 @@ void UnitTestManager::step()
else
step();
}
+
+//
+const QString UnitTestManager::m_logFileParam = "UnitTestManager/logFile";
+QFile UnitTestManager::m_log;
diff --git a/tests/guidevtest/unittestmanager.h b/tests/guidevtest/unittestmanager.h
index 12b2540..41fef1f 100644
--- a/tests/guidevtest/unittestmanager.h
+++ b/tests/guidevtest/unittestmanager.h
@@ -4,6 +4,8 @@
#include <QtCore/QObject>
#include <QtCore/QFile>
+
+
class UnitTestBase : public QObject
{
Q_OBJECT
@@ -35,16 +37,9 @@ protected:
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;
};
@@ -67,11 +62,13 @@ signals:
public:
explicit UnitTestManager(QObject *parent = 0);
void setPorts(const QString &src, const QString &dst);
- void setLogFile(const QString &log);
-
QList<UnitTestBase *> units() const;
- static const QString logFileParam;
+ static void setLogFileName(const QString &name);
+ static bool openLog();
+ static bool writeToLog(const QString &content);
+ static void closeLog();
+ static QString timestamp();
public slots:
void start();
@@ -86,6 +83,9 @@ private:
QString m_srcPort;
QString m_dstPort;
QList<UnitTestBase *> m_unitList;
+
+ static const QString m_logFileParam;
+ static QFile m_log;
};
#endif // UNITTESTMANAGER_H