Skip to content

Commit

Permalink
Test Margins::getContentsMargins()
Browse files Browse the repository at this point in the history
  • Loading branch information
martinburchell committed Jul 13, 2023
1 parent 3d0498b commit 5d8ed87
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/scripts/cpp_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ cd ${GITHUB_WORKSPACE}/tablet_qt/tests
qmake
make
export QT_DEBUG_PLUGINS=1

auto/lib/convert/bin/test_convert
auto/lib/filefunc/bin/test_filefunc
auto/lib/margins/bin/test_margins

auto/questionnairelib/namevalueoptions/bin/test_namevalueoptions
2 changes: 2 additions & 0 deletions docs/source/autodoc/tablet_qt/_index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,8 @@ tablet_qt
tests/auto/lib/filefunc/filefunc.pro.rst
tests/auto/lib/filefunc/testfilefunc.cpp.rst
tests/auto/lib/lib.pro.rst
tests/auto/lib/margins/margins.pro.rst
tests/auto/lib/margins/testmargins.cpp.rst
tests/auto/questionnairelib/namevalueoptions/namevalueoptions.pro.rst
tests/auto/questionnairelib/namevalueoptions/testnamevalueoptions.cpp.rst
tests/auto/questionnairelib/questionnairelib.pro.rst
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.. docs/source/autodoc/tablet_qt/tests/auto/lib/margins/margins.pro.rst
.. THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.
.. 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/>.
tablet_qt/tests/auto/lib/margins/margins.pro
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. literalinclude:: ../../../../../../../../tablet_qt/tests/auto/lib/margins/margins.pro
:language: none
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.. docs/source/autodoc/tablet_qt/tests/auto/lib/margins/testmargins.cpp.rst
.. THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT.
.. 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/>.
tablet_qt/tests/auto/lib/margins/testmargins.cpp
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. literalinclude:: ../../../../../../../../tablet_qt/tests/auto/lib/margins/testmargins.cpp
:language: C++
1 change: 1 addition & 0 deletions tablet_qt/tests/auto/lib/lib.pro
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ TEMPLATE = subdirs

SUBDIRS += convert
SUBDIRS += filefunc
SUBDIRS += margins
58 changes: 58 additions & 0 deletions tablet_qt/tests/auto/lib/margins/margins.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_margins

SOURCES += \
testmargins.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/margins.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/margins.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/margins/testmargins.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/margins.h"


class TestMargins: public QObject
{
Q_OBJECT

private slots:
void testGetContentsMarginsReturnsWidgetMargins();
};


void TestMargins::testGetContentsMarginsReturnsWidgetMargins()
{
auto widget = new QWidget();

const int left = 0;
const int top = 10;
const int right = 20;
const int bottom = 50;

widget->setContentsMargins(left, top, right, bottom);
auto margins = Margins::getContentsMargins(widget);

QCOMPARE(margins.left(), left);
QCOMPARE(margins.top(), top);
QCOMPARE(margins.right(), right);
QCOMPARE(margins.bottom(), bottom);
}

QTEST_MAIN(TestMargins)

#include "testmargins.moc"

0 comments on commit 5d8ed87

Please sign in to comment.