Skip to content

Commit

Permalink
Test textfileContents
Browse files Browse the repository at this point in the history
and in the process restructure the C++ tests
  • Loading branch information
martinburchell committed Jul 13, 2023
1 parent 3b1e520 commit b69e480
Show file tree
Hide file tree
Showing 10 changed files with 240 additions and 119 deletions.
5 changes: 3 additions & 2 deletions .github/scripts/cpp_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ cd ${GITHUB_WORKSPACE}/tablet_qt/tests
qmake
make
export QT_DEBUG_PLUGINS=1
auto/questionnairelib/bin/test_lib
auto/questionnairelib/bin/test_questionnairelib
auto/lib/convert/bin/test_convert
auto/lib/filefunc/bin/test_filefunc
auto/questionnairelib/namevalueoptions/bin/test_namevalueoptions
6 changes: 3 additions & 3 deletions tablet_qt/lib/filefunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <QFileInfo>
#include <QString>
#include <QTextStream>
#include "lib/uifunc.h"
#include "lib/errorfunc.h"


namespace filefunc {
Expand Down Expand Up @@ -101,8 +101,8 @@ bool ensureDirectoryExists(const QString& dir)
void ensureDirectoryExistsOrDie(const QString& dir)
{
if (!ensureDirectoryExists(dir)) {
uifunc::stopApp(QObject::tr("Failed to make directory: ") +
dir);
errorfunc::fatalError(QObject::tr("Failed to make directory: ") +
dir);
}
}

Expand Down
56 changes: 56 additions & 0 deletions tablet_qt/tests/auto/lib/convert/convert.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
CONFIG += testcase
QT += network
QT += testlib
QT += widgets
QT -= gui

QT_BASE_DIR = $$(CAMCOPS_QT6_BASE_DIR) # value at time of qmake ("now")
isEmpty(QT_BASE_DIR) {
error("Environment variable CAMCOPS_QT6_BASE_DIR is undefined")
}

CAMCOPS_SRC = $$PWD/../../../..

MOC_DIR = moc
OBJECTS_DIR = obj
TARGET = bin/test_convert

SOURCES += \
testconvert.cpp \
$$CAMCOPS_SRC/common/dpi.cpp \
$$CAMCOPS_SRC/common/textconst.cpp \
$$CAMCOPS_SRC/common/uiconst.cpp \
$$CAMCOPS_SRC/lib/convert.cpp \
$$CAMCOPS_SRC/lib/datetime.cpp \
$$CAMCOPS_SRC/lib/errorfunc.cpp \
$$CAMCOPS_SRC/lib/stringfunc.cpp \
$$CAMCOPS_SRC/lib/version.cpp \
$$CAMCOPS_SRC/maths/ccrandom.cpp \
$$CAMCOPS_SRC/maths/mathfunc.cpp \
$$CAMCOPS_SRC/whisker/whiskerapi.cpp \
$$CAMCOPS_SRC/whisker/whiskerconnectionstate.cpp \
$$CAMCOPS_SRC/whisker/whiskerconstants.cpp \
$$CAMCOPS_SRC/whisker/whiskerinboundmessage.cpp \
$$CAMCOPS_SRC/whisker/whiskeroutboundcommand.cpp

HEADERS += \
$$CAMCOPS_SRC/common/dpi.h \
$$CAMCOPS_SRC/common/textconst.h \
$$CAMCOPS_SRC/common/uiconst.h \
$$CAMCOPS_SRC/lib/convert.h \
$$CAMCOPS_SRC/lib/datetime.h \
$$CAMCOPS_SRC/lib/errorfunc.h \
$$CAMCOPS_SRC/lib/stringfunc.h \
$$CAMCOPS_SRC/lib/version.h \
$$CAMCOPS_SRC/maths/ccrandom.h \
$$CAMCOPS_SRC/maths/mathfunc.h \
$$CAMCOPS_SRC/whisker/whiskerapi.h \
$$CAMCOPS_SRC/whisker/whiskerconnectionstate.h \
$$CAMCOPS_SRC/whisker/whiskerconstants.h \
$$CAMCOPS_SRC/whisker/whiskerinboundmessage.h \
$$CAMCOPS_SRC/whisker/whiskeroutboundcommand.h

INCLUDEPATH += "$${QT_BASE_DIR}/eigen/eigen-3.4.0"
INCLUDEPATH += $$CAMCOPS_SRC

DEFINES += SRCDIR=\\\"$$PWD/\\\"
File renamed without changes.
58 changes: 58 additions & 0 deletions tablet_qt/tests/auto/lib/filefunc/filefunc.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
CONFIG += testcase
QT += network
QT += testlib
QT += widgets
QT -= gui

QT_BASE_DIR = $$(CAMCOPS_QT6_BASE_DIR) # value at time of qmake ("now")
isEmpty(QT_BASE_DIR) {
error("Environment variable CAMCOPS_QT6_BASE_DIR is undefined")
}

CAMCOPS_SRC = $$PWD/../../../..

MOC_DIR = moc
OBJECTS_DIR = obj
TARGET = bin/test_filefunc

SOURCES += \
testfilefunc.cpp \
$$CAMCOPS_SRC/common/dpi.cpp \
$$CAMCOPS_SRC/common/textconst.cpp \
$$CAMCOPS_SRC/common/uiconst.cpp \
$$CAMCOPS_SRC/lib/convert.cpp \
$$CAMCOPS_SRC/lib/datetime.cpp \
$$CAMCOPS_SRC/lib/errorfunc.cpp \
$$CAMCOPS_SRC/lib/filefunc.cpp \
$$CAMCOPS_SRC/lib/stringfunc.cpp \
$$CAMCOPS_SRC/lib/version.cpp \
$$CAMCOPS_SRC/maths/ccrandom.cpp \
$$CAMCOPS_SRC/maths/mathfunc.cpp \
$$CAMCOPS_SRC/whisker/whiskerapi.cpp \
$$CAMCOPS_SRC/whisker/whiskerconnectionstate.cpp \
$$CAMCOPS_SRC/whisker/whiskerconstants.cpp \
$$CAMCOPS_SRC/whisker/whiskerinboundmessage.cpp \
$$CAMCOPS_SRC/whisker/whiskeroutboundcommand.cpp

HEADERS += \
$$CAMCOPS_SRC/common/dpi.h \
$$CAMCOPS_SRC/common/textconst.h \
$$CAMCOPS_SRC/common/uiconst.h \
$$CAMCOPS_SRC/lib/convert.h \
$$CAMCOPS_SRC/lib/datetime.h \
$$CAMCOPS_SRC/lib/errorfunc.h \
$$CAMCOPS_SRC/lib/filefunc.h \
$$CAMCOPS_SRC/lib/stringfunc.h \
$$CAMCOPS_SRC/lib/version.h \
$$CAMCOPS_SRC/maths/ccrandom.h \
$$CAMCOPS_SRC/maths/mathfunc.h \
$$CAMCOPS_SRC/whisker/whiskerapi.h \
$$CAMCOPS_SRC/whisker/whiskerconnectionstate.h \
$$CAMCOPS_SRC/whisker/whiskerconstants.h \
$$CAMCOPS_SRC/whisker/whiskerinboundmessage.h \
$$CAMCOPS_SRC/whisker/whiskeroutboundcommand.h

INCLUDEPATH += "$${QT_BASE_DIR}/eigen/eigen-3.4.0"
INCLUDEPATH += $$CAMCOPS_SRC

DEFINES += SRCDIR=\\\"$$PWD/\\\"
55 changes: 55 additions & 0 deletions tablet_qt/tests/auto/lib/filefunc/testfilefunc.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
Copyright (C) 2012, University of Cambridge, Department of Psychiatry.
Created by Rudolf Cardinal (rnc1001@cam.ac.uk).
This file is part of CamCOPS.
CamCOPS is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
CamCOPS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with CamCOPS. If not, see <https://www.gnu.org/licenses/>.
*/

#include <QtTest/QtTest>

#include "lib/filefunc.h"


class TestFileFunc: public QObject
{
Q_OBJECT

private slots:
void testTextFileContentsReturnsContentsOfFile();
};


using namespace filefunc;

void TestFileFunc::testTextFileContentsReturnsContentsOfFile()
{
// https://www.cl.cam.ac.uk/~mgk25/ucs/examples/quickbrown.txt
const char *text = ""
"Quizdeltagerne spiste jordbær med fløde, mens cirkusklovnen "
"Wolther spillede på xylofon."
"Γαζέες καὶ μυρτιὲς δὲν θὰ βρῶ πιὰ στὸ χρυσαφὶ ξέφωτο."
"В чащах юга жил бы цитрус? Да, но фальшивый экземпляр!";

auto file = QTemporaryFile();
file.open();
file.write(text);
file.close();
QCOMPARE(textfileContents(file.fileName()), QString(text));
}

QTEST_MAIN(TestFileFunc)

#include "testfilefunc.moc"
58 changes: 3 additions & 55 deletions tablet_qt/tests/auto/lib/lib.pro
Original file line number Diff line number Diff line change
@@ -1,56 +1,4 @@
CONFIG += testcase
QT += network
QT += testlib
QT += widgets
QT -= gui
TEMPLATE = subdirs

QT_BASE_DIR = $$(CAMCOPS_QT6_BASE_DIR) # value at time of qmake ("now")
isEmpty(QT_BASE_DIR) {
error("Environment variable CAMCOPS_QT6_BASE_DIR is undefined")
}

CAMCOPS_SRC = $$PWD/../../..

MOC_DIR = moc
OBJECTS_DIR = obj
TARGET = bin/test_lib

SOURCES += \
testconvert.cpp \
$$CAMCOPS_SRC/common/dpi.cpp \
$$CAMCOPS_SRC/common/textconst.cpp \
$$CAMCOPS_SRC/common/uiconst.cpp \
$$CAMCOPS_SRC/lib/convert.cpp \
$$CAMCOPS_SRC/lib/datetime.cpp \
$$CAMCOPS_SRC/lib/errorfunc.cpp \
$$CAMCOPS_SRC/lib/stringfunc.cpp \
$$CAMCOPS_SRC/lib/version.cpp \
$$CAMCOPS_SRC/maths/ccrandom.cpp \
$$CAMCOPS_SRC/maths/mathfunc.cpp \
$$CAMCOPS_SRC/whisker/whiskerapi.cpp \
$$CAMCOPS_SRC/whisker/whiskerconnectionstate.cpp \
$$CAMCOPS_SRC/whisker/whiskerconstants.cpp \
$$CAMCOPS_SRC/whisker/whiskerinboundmessage.cpp \
$$CAMCOPS_SRC/whisker/whiskeroutboundcommand.cpp

HEADERS += \
$$CAMCOPS_SRC/common/dpi.h \
$$CAMCOPS_SRC/common/textconst.h \
$$CAMCOPS_SRC/common/uiconst.h \
$$CAMCOPS_SRC/lib/convert.h \
$$CAMCOPS_SRC/lib/datetime.h \
$$CAMCOPS_SRC/lib/errorfunc.h \
$$CAMCOPS_SRC/lib/stringfunc.h \
$$CAMCOPS_SRC/lib/version.h \
$$CAMCOPS_SRC/maths/ccrandom.h \
$$CAMCOPS_SRC/maths/mathfunc.h \
$$CAMCOPS_SRC/whisker/whiskerapi.h \
$$CAMCOPS_SRC/whisker/whiskerconnectionstate.h \
$$CAMCOPS_SRC/whisker/whiskerconstants.h \
$$CAMCOPS_SRC/whisker/whiskerinboundmessage.h \
$$CAMCOPS_SRC/whisker/whiskeroutboundcommand.h

INCLUDEPATH += "$${QT_BASE_DIR}/eigen/eigen-3.4.0"
INCLUDEPATH += $$CAMCOPS_SRC

DEFINES += SRCDIR=\\\"$$PWD/\\\"
SUBDIRS += convert
SUBDIRS += filefunc
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
CONFIG += testcase
QT += testlib
QT += network
QT += widgets
QT -= gui

QT_BASE_DIR = $$(CAMCOPS_QT6_BASE_DIR) # value at time of qmake ("now")
isEmpty(QT_BASE_DIR) {
error("Environment variable CAMCOPS_QT6_BASE_DIR is undefined")
}

CAMCOPS_SRC = $$PWD/../../../..

MOC_DIR = moc
OBJECTS_DIR = obj
TARGET = bin/test_namevalueoptions

SOURCES += \
testnamevalueoptions.cpp \
$$CAMCOPS_SRC/common/dpi.cpp \
$$CAMCOPS_SRC/common/textconst.cpp \
$$CAMCOPS_SRC/common/uiconst.cpp \
$$CAMCOPS_SRC/lib/convert.cpp \
$$CAMCOPS_SRC/lib/datetime.cpp \
$$CAMCOPS_SRC/lib/errorfunc.cpp \
$$CAMCOPS_SRC/lib/stringfunc.cpp \
$$CAMCOPS_SRC/lib/version.cpp \
$$CAMCOPS_SRC/maths/ccrandom.cpp \
$$CAMCOPS_SRC/maths/mathfunc.cpp \
$$CAMCOPS_SRC/questionnairelib/namevalueoptions.cpp \
$$CAMCOPS_SRC/questionnairelib/namevaluepair.cpp \
$$CAMCOPS_SRC/whisker/whiskerapi.cpp \
$$CAMCOPS_SRC/whisker/whiskerconnectionstate.cpp \
$$CAMCOPS_SRC/whisker/whiskerconstants.cpp \
$$CAMCOPS_SRC/whisker/whiskerinboundmessage.cpp \
$$CAMCOPS_SRC/whisker/whiskeroutboundcommand.cpp

HEADERS += \
$$CAMCOPS_SRC/common/dpi.h \
$$CAMCOPS_SRC/common/textconst.h \
$$CAMCOPS_SRC/common/uiconst.h \
$$CAMCOPS_SRC/lib/convert.h \
$$CAMCOPS_SRC/lib/datetime.h \
$$CAMCOPS_SRC/lib/errorfunc.h \
$$CAMCOPS_SRC/lib/stringfunc.h \
$$CAMCOPS_SRC/lib/version.h \
$$CAMCOPS_SRC/maths/ccrandom.h \
$$CAMCOPS_SRC/maths/mathfunc.h \
$$CAMCOPS_SRC/questionnairelib/namevalueoptions.h \
$$CAMCOPS_SRC/questionnairelib/namevaluepair.h \
$$CAMCOPS_SRC/whisker/whiskerapi.h \
$$CAMCOPS_SRC/whisker/whiskerconnectionstate.h \
$$CAMCOPS_SRC/whisker/whiskerconstants.h \
$$CAMCOPS_SRC/whisker/whiskerinboundmessage.h \
$$CAMCOPS_SRC/whisker/whiskeroutboundcommand.h

INCLUDEPATH += "$${QT_BASE_DIR}/eigen/eigen-3.4.0"
INCLUDEPATH += $$CAMCOPS_SRC

DEFINES += SRCDIR=\\\"$$PWD/\\\"
61 changes: 2 additions & 59 deletions tablet_qt/tests/auto/questionnairelib/questionnairelib.pro
Original file line number Diff line number Diff line change
@@ -1,60 +1,3 @@
CONFIG += testcase
QT += testlib
QT += network
QT += widgets
QT -= gui
TEMPLATE = subdirs

QT_BASE_DIR = $$(CAMCOPS_QT6_BASE_DIR) # value at time of qmake ("now")
isEmpty(QT_BASE_DIR) {
error("Environment variable CAMCOPS_QT6_BASE_DIR is undefined")
}

CAMCOPS_SRC = $$PWD/../../..

MOC_DIR = moc
OBJECTS_DIR = obj
TARGET = bin/test_questionnairelib

SOURCES += \
testnamevalueoptions.cpp \
$$CAMCOPS_SRC/common/dpi.cpp \
$$CAMCOPS_SRC/common/textconst.cpp \
$$CAMCOPS_SRC/common/uiconst.cpp \
$$CAMCOPS_SRC/lib/convert.cpp \
$$CAMCOPS_SRC/lib/datetime.cpp \
$$CAMCOPS_SRC/lib/errorfunc.cpp \
$$CAMCOPS_SRC/lib/stringfunc.cpp \
$$CAMCOPS_SRC/lib/version.cpp \
$$CAMCOPS_SRC/maths/ccrandom.cpp \
$$CAMCOPS_SRC/maths/mathfunc.cpp \
$$CAMCOPS_SRC/questionnairelib/namevalueoptions.cpp \
$$CAMCOPS_SRC/questionnairelib/namevaluepair.cpp \
$$CAMCOPS_SRC/whisker/whiskerapi.cpp \
$$CAMCOPS_SRC/whisker/whiskerconnectionstate.cpp \
$$CAMCOPS_SRC/whisker/whiskerconstants.cpp \
$$CAMCOPS_SRC/whisker/whiskerinboundmessage.cpp \
$$CAMCOPS_SRC/whisker/whiskeroutboundcommand.cpp

HEADERS += \
$$CAMCOPS_SRC/common/dpi.h \
$$CAMCOPS_SRC/common/textconst.h \
$$CAMCOPS_SRC/common/uiconst.h \
$$CAMCOPS_SRC/lib/convert.h \
$$CAMCOPS_SRC/lib/datetime.h \
$$CAMCOPS_SRC/lib/errorfunc.h \
$$CAMCOPS_SRC/lib/stringfunc.h \
$$CAMCOPS_SRC/lib/version.h \
$$CAMCOPS_SRC/maths/ccrandom.h \
$$CAMCOPS_SRC/maths/mathfunc.h \
$$CAMCOPS_SRC/questionnairelib/namevalueoptions.h \
$$CAMCOPS_SRC/questionnairelib/namevaluepair.h \
$$CAMCOPS_SRC/whisker/whiskerapi.h \
$$CAMCOPS_SRC/whisker/whiskerconnectionstate.h \
$$CAMCOPS_SRC/whisker/whiskerconstants.h \
$$CAMCOPS_SRC/whisker/whiskerinboundmessage.h \
$$CAMCOPS_SRC/whisker/whiskeroutboundcommand.h

INCLUDEPATH += "$${QT_BASE_DIR}/eigen/eigen-3.4.0"
INCLUDEPATH += $$CAMCOPS_SRC

DEFINES += SRCDIR=\\\"$$PWD/\\\"
SUBDIRS += namevalueoptions

0 comments on commit b69e480

Please sign in to comment.