summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDenis Shienkov <scapig2@yandex.ru>2011-10-15 19:09:17 +0400
committerDenis Shienkov <scapig2@yandex.ru>2011-10-15 19:09:17 +0400
commit1fc2ba5735d4bea741946f7f0be61191ec4268c6 (patch)
tree4a46c276ec9e5e775647b1e036ddf80e87bb28cf /tests
parent7d88be4080f025ce97c6d66961d7e1a03584cebc (diff)
Started the development of unit test application to test the library.
Diffstat (limited to 'tests')
-rw-r--r--tests/guidevtest/guidevtest.pro36
-rw-r--r--tests/guidevtest/main.cpp11
-rw-r--r--tests/guidevtest/maindialog.cpp101
-rw-r--r--tests/guidevtest/maindialog.h40
-rw-r--r--tests/guidevtest/maindialog.ui72
-rw-r--r--tests/guidevtest/testsdialog.cpp14
-rw-r--r--tests/guidevtest/testsdialog.h22
-rw-r--r--tests/guidevtest/testsdialog.ui19
8 files changed, 315 insertions, 0 deletions
diff --git a/tests/guidevtest/guidevtest.pro b/tests/guidevtest/guidevtest.pro
new file mode 100644
index 00000000..389c0f64
--- /dev/null
+++ b/tests/guidevtest/guidevtest.pro
@@ -0,0 +1,36 @@
+#-------------------------------------------------
+#
+# Project created by QtCreator 2011-10-15T16:26:56
+#
+#-------------------------------------------------
+
+QT += core gui
+
+TARGET = guidevtest
+TEMPLATE = app
+
+INCLUDEPATH += \
+ ../../include \
+ ../../src
+
+HEADERS += \
+ ../../include/serialport.h \
+ ../../include/serialportinfo.h
+
+include(../../src/src.pri)
+
+SOURCES += \
+ main.cpp \
+ maindialog.cpp \
+ testsdialog.cpp
+
+HEADERS += \
+ maindialog.h \
+ testsdialog.h
+
+FORMS += \
+ maindialog.ui \
+ testsdialog.ui
+
+
+
diff --git a/tests/guidevtest/main.cpp b/tests/guidevtest/main.cpp
new file mode 100644
index 00000000..b50363e4
--- /dev/null
+++ b/tests/guidevtest/main.cpp
@@ -0,0 +1,11 @@
+#include <QtGui/QApplication>
+#include "maindialog.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+ MainDialog w;
+ w.show();
+
+ return a.exec();
+}
diff --git a/tests/guidevtest/maindialog.cpp b/tests/guidevtest/maindialog.cpp
new file mode 100644
index 00000000..91614bf9
--- /dev/null
+++ b/tests/guidevtest/maindialog.cpp
@@ -0,0 +1,101 @@
+#include "maindialog.h"
+#include "ui_maindialog.h"
+
+#include <QtCore/QStateMachine>
+#include <QtGui/QMessageBox>
+
+#include "serialportinfo.h"
+
+/* Public methods */
+
+MainDialog::MainDialog(QWidget *parent)
+ : QDialog(parent)
+ , ui(new Ui::MainDialog)
+{
+ ui->setupUi(this);
+
+ m_idleState = new QState();
+ m_optionsState = new QState();
+ m_runningState = new QState();
+
+ connect(m_idleState,SIGNAL(entered()), this, SLOT(procIdleState()));
+ connect(m_optionsState,SIGNAL(entered()), this, SLOT(procOptionsState()));
+ connect(m_runningState,SIGNAL(entered()), this, SLOT(procRunningState()));
+
+ // From Idle State to ...
+ m_idleState->addTransition(ui->optButton, SIGNAL(clicked()), m_optionsState);
+ m_idleState->addTransition(ui->ctrlButton, SIGNAL(clicked()), m_runningState);
+
+ // From Options State to ...
+ //...
+ //...
+
+ // From Running State to ...
+ m_runningState->addTransition(ui->ctrlButton, SIGNAL(clicked()), m_idleState);
+ m_runningState->addTransition(this, SIGNAL(hasError()), m_idleState);
+
+ m_stateMachine = new QStateMachine(this);
+ m_stateMachine->addState(m_idleState);
+ m_stateMachine->addState(m_optionsState);
+ m_stateMachine->addState(m_runningState);
+
+ m_stateMachine->setInitialState(m_idleState);
+ m_stateMachine->start();
+}
+
+MainDialog::~MainDialog()
+{
+ delete ui;
+}
+
+/* Private slots */
+
+void MainDialog::procIdleState()
+{
+ ui->ctrlButton->setText(tr("Start"));
+ ui->srcBox->setEnabled(true);
+ ui->dstBox->setEnabled(true);
+ ui->optButton->setEnabled(true);
+ procUbdatePortsBox();
+}
+
+void MainDialog::procOptionsState()
+{
+
+
+
+}
+
+void MainDialog::procRunningState()
+{
+ if (ui->srcBox->currentText() == ui->dstBox->currentText()) {
+ QMessageBox msgBox;
+ msgBox.setIcon(QMessageBox::Warning);
+ msgBox.setText(tr("You can not choose the source and\n"
+ "destination the same name."));
+ msgBox.exec();
+ emit hasError();
+ return;
+ }
+ ui->ctrlButton->setText(tr("Stop"));
+ ui->srcBox->setEnabled(false);
+ ui->dstBox->setEnabled(false);
+ ui->optButton->setEnabled(false);
+}
+
+void MainDialog::procUbdatePortsBox()
+{
+ ui->srcBox->clear();
+ ui->dstBox->clear();
+
+ foreach(SerialPortInfo inf, SerialPortInfo::availablePorts()) {
+ if (inf.isValid() && !inf.isBusy()) {
+ QString s = inf.portName();
+ ui->srcBox->addItem(s);
+ ui->dstBox->addItem(s);
+ }
+ }
+}
+
+
+/* Private methods */
diff --git a/tests/guidevtest/maindialog.h b/tests/guidevtest/maindialog.h
new file mode 100644
index 00000000..3de4014c
--- /dev/null
+++ b/tests/guidevtest/maindialog.h
@@ -0,0 +1,40 @@
+#ifndef MAINDIALOG_H
+#define MAINDIALOG_H
+
+#include <QtGui/QDialog>
+#include <QtCore/QMap>
+
+namespace Ui {
+class MainDialog;
+}
+
+class QState;
+class QStateMachine;
+
+class MainDialog : public QDialog
+{
+ Q_OBJECT
+
+signals:
+ void hasError();
+
+public:
+ explicit MainDialog(QWidget *parent = 0);
+ ~MainDialog();
+
+private slots:
+ void procIdleState();
+ void procOptionsState();
+ void procRunningState();
+ void procUbdatePortsBox();
+
+private:
+ Ui::MainDialog *ui;
+
+ QState *m_idleState;
+ QState *m_optionsState;
+ QState *m_runningState;
+ QStateMachine *m_stateMachine;
+};
+
+#endif // MAINDIALOG_H
diff --git a/tests/guidevtest/maindialog.ui b/tests/guidevtest/maindialog.ui
new file mode 100644
index 00000000..ff572324
--- /dev/null
+++ b/tests/guidevtest/maindialog.ui
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainDialog</class>
+ <widget class="QDialog" name="MainDialog">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>107</width>
+ <height>220</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Quick test</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QGroupBox" name="pairBox">
+ <property name="title">
+ <string>Free for pair:</string>
+ </property>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0">
+ <widget class="QLabel" name="srcLabel">
+ <property name="text">
+ <string>Source:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QComboBox" name="srcBox"/>
+ </item>
+ <item row="2" column="0">
+ <widget class="QLabel" name="dstLabel">
+ <property name="text">
+ <string>Destination:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="0">
+ <widget class="QComboBox" name="dstBox"/>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="optButton">
+ <property name="text">
+ <string>Options</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="ctrlButton">
+ <property name="text">
+ <string>Start</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QProgressBar" name="progressBar">
+ <property name="value">
+ <number>24</number>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <layoutdefault spacing="6" margin="11"/>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/tests/guidevtest/testsdialog.cpp b/tests/guidevtest/testsdialog.cpp
new file mode 100644
index 00000000..80e46e01
--- /dev/null
+++ b/tests/guidevtest/testsdialog.cpp
@@ -0,0 +1,14 @@
+#include "testsdialog.h"
+#include "ui_testsdialog.h"
+
+TestsDialog::TestsDialog(QWidget *parent)
+ : QDialog(parent)
+ , ui(new Ui::TestsDialog)
+{
+ ui->setupUi(this);
+}
+
+TestsDialog::~TestsDialog()
+{
+ delete ui;
+}
diff --git a/tests/guidevtest/testsdialog.h b/tests/guidevtest/testsdialog.h
new file mode 100644
index 00000000..8a9db7b7
--- /dev/null
+++ b/tests/guidevtest/testsdialog.h
@@ -0,0 +1,22 @@
+#ifndef TESTSDIALOG_H
+#define TESTSDIALOG_H
+
+#include <QDialog>
+
+namespace Ui {
+ class TestsDialog;
+}
+
+class TestsDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ explicit TestsDialog(QWidget *parent = 0);
+ ~TestsDialog();
+
+private:
+ Ui::TestsDialog *ui;
+};
+
+#endif // TESTSDIALOG_H
diff --git a/tests/guidevtest/testsdialog.ui b/tests/guidevtest/testsdialog.ui
new file mode 100644
index 00000000..5685bbdb
--- /dev/null
+++ b/tests/guidevtest/testsdialog.ui
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>TestsDialog</class>
+ <widget class="QDialog" name="TestsDialog">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>246</width>
+ <height>300</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Available tests</string>
+ </property>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>