Skip to content

Instantly share code, notes, and snippets.

@jlebar
Created June 4, 2020 18:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jlebar/731f9385db6d658c5e131636ce158cc4 to your computer and use it in GitHub Desktop.
Save jlebar/731f9385db6d658c5e131636ce158cc4 to your computer and use it in GitHub Desktop.
commit a0cfe8a15b50afd01a716188ca08780f0ea7da83
Author: Paulo Pinheiro <paulovap.os@gmail.com>
Date: Wed Jun 3 21:44:29 2020 +0200
[GUI Tests] Simplify GUI sub-project to run tests.
So, the current implementation of tests could be a bit
cumbersome, because needed to create a new qmake project
for each test class. This PR simplifies the gui folder structure
to accommodate tests sub-project in a way to keep all tests in a
single folder.
diff --git a/gui/ProjectVentilatorGUI.pro b/gui/ProjectVentilatorGUI.pro
deleted file mode 100644
index b6a12dd..0000000
--- a/gui/ProjectVentilatorGUI.pro
+++ /dev/null
@@ -1,26 +0,0 @@
-QT += core quick charts serialport
-CONFIG += c++1z
-DEFINES += QT_DEPRECATED_WARNINGS
-
-SOURCES += $$files("*.cpp") \
- ../common/generated_libs/network_protocol/network_protocol.pb.c \
- ../common/third_party/nanopb/pb_common.c \
- ../common/third_party/nanopb/pb_decode.c \
- ../common/third_party/nanopb/pb_encode.c
-SOURCES += $$files("$$PWD/../common/**/*.c")
-HEADERS += $$files("*.h") \
- ../common/generated_libs/network_protocol/network_protocol.pb.h \
- ../common/third_party/nanopb/pb.h \
- ../common/third_party/nanopb/pb_common.h \
- ../common/third_party/nanopb/pb_decode.h \
- ../common/third_party/nanopb/pb_encode.h
-HEADERS += $$files("$$PWD/../common/**/*.h")
-INCLUDEPATH += $$PWD/../common/third_party/nanopb
-RESOURCES += qml.qrc images/Logo.png
-DISTFILES += images/Logo.png
-TRANSLATIONS += ProjectVentilatorGUI_es_GT.ts
-
-# Default rules for deployment.
-qnx: target.path = /tmp/$${TARGET}/bin
-else: unix:!android: target.path = /opt/$${TARGET}/bin
-!isEmpty(target.path): INSTALLS += target
diff --git a/gui/ControlPanel.qml b/gui/app/ControlPanel.qml
similarity index 100%
rename from gui/ControlPanel.qml
rename to gui/app/ControlPanel.qml
diff --git a/gui/controls/FpsItem.qml b/gui/app/FpsItem.qml
similarity index 100%
copy from gui/controls/FpsItem.qml
copy to gui/app/FpsItem.qml
diff --git a/gui/ModeSelectionPopup.qml b/gui/app/ModeSelectionPopup.qml
similarity index 100%
rename from gui/ModeSelectionPopup.qml
rename to gui/app/ModeSelectionPopup.qml
diff --git a/gui/ProjectVentilatorGUI_es_GT.ts b/gui/app/ProjectVentilatorGUI_es_GT.ts
similarity index 100%
rename from gui/ProjectVentilatorGUI_es_GT.ts
rename to gui/app/ProjectVentilatorGUI_es_GT.ts
diff --git a/gui/README.md b/gui/app/README.md
similarity index 99%
rename from gui/README.md
rename to gui/app/README.md
index 895961e..d87733d 100644
--- a/gui/README.md
+++ b/gui/app/README.md
@@ -55,4 +55,3 @@ hdmi_cvt=1024 600 60 3 0 0 0
hdmi_group=2
hdmi_mode=87
```
-
diff --git a/gui/controls/ScopeView.qml b/gui/app/ScopeView.qml
similarity index 100%
copy from gui/controls/ScopeView.qml
copy to gui/app/ScopeView.qml
diff --git a/gui/controls/StepCounter.qml b/gui/app/StepCounter.qml
similarity index 100%
copy from gui/controls/StepCounter.qml
copy to gui/app/StepCounter.qml
diff --git a/gui/Style.qml b/gui/app/Style.qml
similarity index 100%
rename from gui/Style.qml
rename to gui/app/Style.qml
diff --git a/gui/app/app.pro b/gui/app/app.pro
new file mode 100644
index 0000000..0470bc8
--- /dev/null
+++ b/gui/app/app.pro
@@ -0,0 +1,23 @@
+QT += core quick charts serialport
+
+! include( ../common.pri ) {
+ error( "Couldn't find the common.pri file!" )
+}
+
+TARGET = ProjectVentilatorGUI
+
+
+SOURCES += $$files("*.cpp")
+
+HEADERS += $$files("*.h")
+
+RESOURCES += qml.qrc images/Logo.png
+
+DISTFILES += images/Logo.png
+
+TRANSLATIONS += ProjectVentilatorGUI_es_GT.ts
+
+# Default rules for deployment.
+qnx: target.path = /tmp/$${TARGET}/bin
+else: unix:!android: target.path = /opt/$${TARGET}/bin
+!isEmpty(target.path): INSTALLS += target
diff --git a/gui/chrono.h b/gui/app/chrono.h
similarity index 100%
rename from gui/chrono.h
rename to gui/app/chrono.h
diff --git a/gui/connected_device.h b/gui/app/connected_device.h
similarity index 94%
rename from gui/connected_device.h
rename to gui/app/connected_device.h
index 80cb12c..4422b0a 100644
--- a/gui/connected_device.h
+++ b/gui/app/connected_device.h
@@ -1,7 +1,7 @@
#ifndef CONNECTED_DEVICE_H
#define CONNECTED_DEVICE_H
-#include "../common/generated_libs/network_protocol/network_protocol.pb.h"
+#include "network_protocol.pb.h"
#include <functional>
// Represents a connection to the device running the controller.
@@ -38,5 +38,4 @@ private:
std::function<void(ControllerStatus *)> receive_fn_;
};
-
#endif // CONNECTED_DEVICE_H
diff --git a/gui/controller_history.h b/gui/app/controller_history.h
similarity index 96%
rename from gui/controller_history.h
rename to gui/app/controller_history.h
index acb150d..e201e2d 100644
--- a/gui/controller_history.h
+++ b/gui/app/controller_history.h
@@ -1,8 +1,8 @@
#ifndef CONTROLLER_HISTORY_H
#define CONTROLLER_HISTORY_H
-#include "../common/generated_libs/network_protocol/network_protocol.pb.h"
#include "chrono.h"
+#include "network_protocol.pb.h"
#include <deque>
#include <tuple>
diff --git a/gui/controls/FpsItem.qml b/gui/app/controls/FpsItem.qml
similarity index 100%
copy from gui/controls/FpsItem.qml
copy to gui/app/controls/FpsItem.qml
diff --git a/gui/controls/FpsItem.qml b/gui/app/controls/FpsItem.qml.orig
similarity index 100%
rename from gui/controls/FpsItem.qml
rename to gui/app/controls/FpsItem.qml.orig
diff --git a/gui/controls/HeaderButton.qml b/gui/app/controls/HeaderButton.qml
similarity index 100%
rename from gui/controls/HeaderButton.qml
rename to gui/app/controls/HeaderButton.qml
diff --git a/gui/controls/Mode.qml b/gui/app/controls/Mode.qml
similarity index 100%
rename from gui/controls/Mode.qml
rename to gui/app/controls/Mode.qml
diff --git a/gui/controls/PopupButton.qml b/gui/app/controls/PopupButton.qml
similarity index 100%
rename from gui/controls/PopupButton.qml
rename to gui/app/controls/PopupButton.qml
diff --git a/gui/controls/ScopeView.qml b/gui/app/controls/ScopeView.qml
similarity index 100%
copy from gui/controls/ScopeView.qml
copy to gui/app/controls/ScopeView.qml
diff --git a/gui/controls/ScopeView.qml b/gui/app/controls/ScopeView.qml.orig
similarity index 100%
rename from gui/controls/ScopeView.qml
rename to gui/app/controls/ScopeView.qml.orig
diff --git a/gui/controls/StepCounter.qml b/gui/app/controls/StepCounter.qml
similarity index 100%
copy from gui/controls/StepCounter.qml
copy to gui/app/controls/StepCounter.qml
diff --git a/gui/controls/StepCounter.qml b/gui/app/controls/StepCounter.qml.orig
similarity index 100%
rename from gui/controls/StepCounter.qml
rename to gui/app/controls/StepCounter.qml.orig
diff --git a/gui/gui_state_container.cpp b/gui/app/gui_state_container.cpp
similarity index 100%
rename from gui/gui_state_container.cpp
rename to gui/app/gui_state_container.cpp
diff --git a/gui/gui_state_container.h b/gui/app/gui_state_container.h
similarity index 100%
rename from gui/gui_state_container.h
rename to gui/app/gui_state_container.h
diff --git a/gui/images/Logo.png b/gui/app/images/Logo.png
similarity index 100%
rename from gui/images/Logo.png
rename to gui/app/images/Logo.png
diff --git a/gui/images/respiraWorksLogoHorizontalTransparent.png b/gui/app/images/respiraWorksLogoHorizontalTransparent.png
similarity index 100%
rename from gui/images/respiraWorksLogoHorizontalTransparent.png
rename to gui/app/images/respiraWorksLogoHorizontalTransparent.png
diff --git a/gui/main.cpp b/gui/app/main.cpp
similarity index 100%
rename from gui/main.cpp
rename to gui/app/main.cpp
diff --git a/gui/main.qml b/gui/app/main.qml
similarity index 100%
rename from gui/main.qml
rename to gui/app/main.qml
diff --git a/gui/modes/CommandPressureMode.qml b/gui/app/modes/CommandPressureMode.qml
similarity index 100%
rename from gui/modes/CommandPressureMode.qml
rename to gui/app/modes/CommandPressureMode.qml
diff --git a/gui/modes/HighFlowNasalCannulaMode.qml b/gui/app/modes/HighFlowNasalCannulaMode.qml
similarity index 100%
rename from gui/modes/HighFlowNasalCannulaMode.qml
rename to gui/app/modes/HighFlowNasalCannulaMode.qml
diff --git a/gui/modes/PressureAssistMode.qml b/gui/app/modes/PressureAssistMode.qml
similarity index 100%
rename from gui/modes/PressureAssistMode.qml
rename to gui/app/modes/PressureAssistMode.qml
diff --git a/gui/periodic_closure.cpp b/gui/app/periodic_closure.cpp
similarity index 100%
rename from gui/periodic_closure.cpp
rename to gui/app/periodic_closure.cpp
diff --git a/gui/periodic_closure.h b/gui/app/periodic_closure.h
similarity index 100%
rename from gui/periodic_closure.h
rename to gui/app/periodic_closure.h
diff --git a/gui/qml.qrc b/gui/app/qml.qrc
similarity index 100%
rename from gui/qml.qrc
rename to gui/app/qml.qrc
diff --git a/gui/qmldir b/gui/app/qmldir
similarity index 100%
rename from gui/qmldir
rename to gui/app/qmldir
diff --git a/gui/respira_connected_device.h b/gui/app/respira_connected_device.h
similarity index 95%
rename from gui/respira_connected_device.h
rename to gui/app/respira_connected_device.h
index 7e2420e..748a419 100644
--- a/gui/respira_connected_device.h
+++ b/gui/app/respira_connected_device.h
@@ -1,9 +1,9 @@
-#include "../common/generated_libs/network_protocol/network_protocol.pb.h"
-#include "../common/third_party/nanopb/pb_common.h"
-#include "../common/third_party/nanopb/pb_decode.h"
-#include "../common/third_party/nanopb/pb_encode.h"
#include "chrono.h"
#include "connected_device.h"
+#include "network_protocol.pb.h"
+#include "pb_common.h"
+#include "pb_decode.h"
+#include "pb_encode.h"
#include <QSerialPort>
#include <QtDebug>
#include <memory>
diff --git a/gui/autotests/autotests.pri b/gui/autotests/autotests.pri
deleted file mode 100644
index 45c5374..0000000
--- a/gui/autotests/autotests.pri
+++ /dev/null
@@ -1,5 +0,0 @@
-QT += core testlib
-CONFIG += qt warn_on depend_includepath testcase
-QMAKE_CXXFLAGS += --coverage
-QMAKE_LFLAGS += --coverage
-SOURCES = $${TARGET}.cpp
diff --git a/gui/autotests/autotests.pro b/gui/autotests/autotests.pro
deleted file mode 100644
index ff6868b..0000000
--- a/gui/autotests/autotests.pro
+++ /dev/null
@@ -1,4 +0,0 @@
-TEMPLATE = subdirs
-SUBDIRS =\
- hello_test\
- goodbye_test
diff --git a/gui/autotests/goodbye_test/goodbye_test.cpp b/gui/autotests/goodbye_test/goodbye_test.cpp
deleted file mode 100644
index f45b2c0..0000000
--- a/gui/autotests/goodbye_test/goodbye_test.cpp
+++ /dev/null
@@ -1,13 +0,0 @@
-#include <QCoreApplication>
-#include <QtTest>
-
-class GoodbyeTest : public QObject {
- Q_OBJECT
-
-private slots:
- void test_goodbye() { QVERIFY(1 == 1); }
-};
-
-QTEST_MAIN(GoodbyeTest)
-
-#include "goodbye_test.moc"
diff --git a/gui/autotests/goodbye_test/goodbye_test.pro b/gui/autotests/goodbye_test/goodbye_test.pro
deleted file mode 100644
index feb63d0..0000000
--- a/gui/autotests/goodbye_test/goodbye_test.pro
+++ /dev/null
@@ -1,2 +0,0 @@
-include(../autotests.pri)
-TARGET = goodbye_test
diff --git a/gui/autotests/hello_test/hello_test.cpp b/gui/autotests/hello_test/hello_test.cpp
deleted file mode 100644
index bcb8d3c..0000000
--- a/gui/autotests/hello_test/hello_test.cpp
+++ /dev/null
@@ -1,13 +0,0 @@
-#include <QCoreApplication>
-#include <QtTest>
-
-class HelloTest : public QObject {
- Q_OBJECT
-
-private slots:
- void test_hello() { QVERIFY(1 == 1); }
-};
-
-QTEST_MAIN(HelloTest)
-
-#include "hello_test.moc"
diff --git a/gui/autotests/hello_test/hello_test.pro b/gui/autotests/hello_test/hello_test.pro
deleted file mode 100644
index 90d3984..0000000
--- a/gui/autotests/hello_test/hello_test.pro
+++ /dev/null
@@ -1,2 +0,0 @@
-include(../autotests.pri)
-TARGET = hello_test
diff --git a/gui/common.pri b/gui/common.pri
new file mode 100644
index 0000000..1f4cd7a
--- /dev/null
+++ b/gui/common.pri
@@ -0,0 +1,27 @@
+CONFIG += c++1z
+
+DEFINES += QT_DEPRECATED_WARNINGS
+
+
+top_srcdir=$$PWD
+# top_builddir=$$shadowed($$PWD)
+
+SOURCES += \
+ $$top_srcdir/../common/generated_libs/network_protocol/network_protocol.pb.c \
+ $$top_srcdir/../common/third_party/nanopb/pb_common.c \
+ $$top_srcdir/../common/third_party/nanopb/pb_decode.c \
+ $$top_srcdir/../common/third_party/nanopb/pb_encode.c \
+ $$files("$$top_srcdir//../common/**/*.c")
+
+HEADERS += \
+ $$top_srcdir/../common/generated_libs/network_protocol/network_protocol.pb.h \
+ $$top_srcdir/../common/third_party/nanopb/pb.h \
+ $$top_srcdir/../common/third_party/nanopb/pb_common.h \
+ $$top_srcdir/../common/third_party/nanopb/pb_decode.h \
+ $$top_srcdir/../common/third_party/nanopb/pb_encode.h
+
+HEADERS += $$files("$$top_srcdir/../common/**/*.h")
+
+INCLUDEPATH += \
+ $$top_srcdir/../common/generated_libs/network_protocol \
+ $$top_srcdir/../common/third_party/nanopb
diff --git a/gui/gui.pro b/gui/gui.pro
new file mode 100644
index 0000000..ca8e52e
--- /dev/null
+++ b/gui/gui.pro
@@ -0,0 +1,11 @@
+TEMPLATE = subdirs # This changes to the subdirs function. You can't combine
+ # compiling code and the subdirs function in the same .pro
+ # file.
+
+# By default, you assign a directory to the SUBDIRS variable, and qmake looks
+# inside that directory for a <dirname>.pro file.
+SUBDIRS = app tests
+
+# You can also use this to specify dependencies. In this case, we don't want
+# the build target to run until after the logic and gui targets are complete.
+build.depends = app
diff --git a/gui/gui.sh b/gui/gui.sh
index ce125dd..4061de1 100755
--- a/gui/gui.sh
+++ b/gui/gui.sh
@@ -79,6 +79,8 @@ if [ "$1" == "--install" ] ; then
qtquickcontrols2-5-dev \
qml-module-qtquick-controls \
qml-module-qtquick-controls2 \
+ libqt5serialport5-dev \
+ libqt5serialport5 \
qtdeclarative5-dev-tools \
xvfb
fi
@@ -99,10 +101,8 @@ fi
########
if [ "$1" == "--test" ] ; then
- create_clean_directory build_autotests
- cd build_autotests
- qmake ../autotests
- make -j
+
+ cd build
if [ "$PLATFORM" == "Darwin" ]; then
make check
@@ -111,4 +111,5 @@ if [ "$1" == "--test" ] ; then
Xvfb :1 &
DISPLAY=:1 make check
fi
+ cd -
fi
diff --git a/gui/rpi-image/rpi-primer.yml b/gui/rpi-image/rpi-primer.yml
index f87d73f..ea3dafd 100644
--- a/gui/rpi-image/rpi-primer.yml
+++ b/gui/rpi-image/rpi-primer.yml
@@ -54,4 +54,4 @@
- name: Add script to spin up gui docker instance on boot
lineinfile:
dest: /home/pi/.config/openbox/autostart
- line: 'docker run --name=gui -d --restart unless-stopped --volume="$HOME/.Xauthority:/root/.Xauthority:rw" --env="DISPLAY" --net=host -i -t respiraworks/gui /gui/build/ProjectVentilatorGUI &'
+ line: 'docker run --name=gui -d --restart unless-stopped --volume="$HOME/.Xauthority:/root/.Xauthority:rw" --env="DISPLAY" --net=host -i -t respiraworks/gui /gui/build/app/ProjectVentilatorGUI &'
diff --git a/gui/run_eglfs.sh b/gui/run_eglfs.sh
index 4841869..0f72942 100755
--- a/gui/run_eglfs.sh
+++ b/gui/run_eglfs.sh
@@ -14,4 +14,4 @@ DISPLAY=:0
# Run GUI APP forcing to use eglfs with a particular configuration
# defined in kms.json
-QT_QPA_EGLFS_KMS_CONFIG=kms.json QT_QPA_EGLFS_INTEGRATION=eglfs_kms build/ProjectVentilatorGUI -platform eglfs
+QT_QPA_EGLFS_KMS_CONFIG=kms.json QT_QPA_EGLFS_INTEGRATION=eglfs_kms build/app/ProjectVentilatorGUI -platform eglfs
diff --git a/gui/autotests/.gitignore b/gui/tests/.gitignore
similarity index 100%
rename from gui/autotests/.gitignore
rename to gui/tests/.gitignore
diff --git a/gui/tests/goodbyetest.cpp b/gui/tests/goodbyetest.cpp
new file mode 100644
index 0000000..8c9351d
--- /dev/null
+++ b/gui/tests/goodbyetest.cpp
@@ -0,0 +1,11 @@
+#include "goodbyetest.h"
+
+GoodbyeTest::GoodbyeTest() {}
+
+GoodbyeTest::~GoodbyeTest() {}
+
+void GoodbyeTest::initTestCase() {}
+
+void GoodbyeTest::cleanupTestCase() {}
+
+void GoodbyeTest::test_case1() {}
diff --git a/gui/tests/goodbyetest.h b/gui/tests/goodbyetest.h
new file mode 100644
index 0000000..81cd766
--- /dev/null
+++ b/gui/tests/goodbyetest.h
@@ -0,0 +1,19 @@
+#ifndef GOODBYETEST_H
+#define GOODBYETEST_H
+
+#include <QCoreApplication>
+#include <QtTest>
+
+class GoodbyeTest : public QObject {
+ Q_OBJECT
+public:
+ GoodbyeTest();
+ ~GoodbyeTest();
+
+private slots:
+ void initTestCase();
+ void cleanupTestCase();
+ void test_case1();
+};
+
+#endif // GOODBYETEST_H
diff --git a/gui/tests/hellotest.cpp b/gui/tests/hellotest.cpp
new file mode 100644
index 0000000..5aaa760
--- /dev/null
+++ b/gui/tests/hellotest.cpp
@@ -0,0 +1,9 @@
+#include "hellotest.h"
+
+HelloTest::HelloTest(QObject *parent) : QObject(parent) {}
+
+void HelloTest::initTestCase() {}
+
+void HelloTest::cleanupTestCase() {}
+
+void HelloTest::test_case1() {}
diff --git a/gui/tests/hellotest.h b/gui/tests/hellotest.h
new file mode 100644
index 0000000..997bc5b
--- /dev/null
+++ b/gui/tests/hellotest.h
@@ -0,0 +1,17 @@
+#ifndef HELLOTEST_H
+#define HELLOTEST_H
+
+#include <QObject>
+
+class HelloTest : public QObject {
+ Q_OBJECT
+public:
+ explicit HelloTest(QObject *parent = nullptr);
+
+private slots:
+ void initTestCase();
+ void cleanupTestCase();
+ void test_case1();
+};
+
+#endif // HELLOTEST_H
diff --git a/gui/tests/tests.pro b/gui/tests/tests.pro
new file mode 100644
index 0000000..1029289
--- /dev/null
+++ b/gui/tests/tests.pro
@@ -0,0 +1,19 @@
+QT += testlib gui
+
+CONFIG += qt warn_on depend_includepath testcase
+
+! include( ../common.pri ) {
+ error( "Couldn't find the common.pri file!" )
+}
+
+
+TEMPLATE = app
+
+SOURCES += \
+ goodbyetest.cpp \
+ hellotest.cpp \
+ tst_main.cpp
+
+HEADERS += \
+ goodbyetest.h \
+ hellotest.h
diff --git a/gui/tests/tst_main.cpp b/gui/tests/tst_main.cpp
new file mode 100644
index 0000000..f84771e
--- /dev/null
+++ b/gui/tests/tst_main.cpp
@@ -0,0 +1,21 @@
+#include <QCoreApplication>
+#include <QtTest>
+
+#include "goodbyetest.h"
+#include "hellotest.h"
+
+int main(int argc, char *argv[]) {
+ QGuiApplication app(argc, argv);
+
+ int status = 0;
+ {
+ HelloTest tc;
+ status = QTest::qExec(&tc, argc, argv);
+ }
+
+ {
+ GoodbyeTest tc;
+ status |= QTest::qExec(&tc, argc, argv);
+ }
+ return status;
+}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment