From 769427f90fa9b78444933418c8f708ef69d9f8ec Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 16 Aug 2016 18:21:27 +0300 Subject: [PATCH] Added tests ref issue #543. --HG-- branch : release --- src/test/ValentinaTest/ValentinaTest.pro | 6 +- src/test/ValentinaTest/qttestmainlambda.cpp | 2 + src/test/ValentinaTest/tst_vgobject.cpp | 139 ++++++++++++++++++++ src/test/ValentinaTest/tst_vgobject.h | 45 +++++++ 4 files changed, 190 insertions(+), 2 deletions(-) create mode 100644 src/test/ValentinaTest/tst_vgobject.cpp create mode 100644 src/test/ValentinaTest/tst_vgobject.h diff --git a/src/test/ValentinaTest/ValentinaTest.pro b/src/test/ValentinaTest/ValentinaTest.pro index 221638b8a..4d06af775 100644 --- a/src/test/ValentinaTest/ValentinaTest.pro +++ b/src/test/ValentinaTest/ValentinaTest.pro @@ -54,7 +54,8 @@ SOURCES += \ tst_vcommandline.cpp \ tst_tstranslation.cpp \ tst_vdetail.cpp \ - tst_vabstractcurve.cpp + tst_vabstractcurve.cpp \ + tst_vgobject.cpp HEADERS += \ tst_vposter.h \ @@ -76,7 +77,8 @@ HEADERS += \ tst_vcommandline.h \ tst_tstranslation.h \ tst_vdetail.h \ - tst_vabstractcurve.h + tst_vabstractcurve.h \ + tst_vgobject.h # Set using ccache. Function enable_ccache() defined in common.pri. $$enable_ccache() diff --git a/src/test/ValentinaTest/qttestmainlambda.cpp b/src/test/ValentinaTest/qttestmainlambda.cpp index 282494c5a..7ca2d484a 100644 --- a/src/test/ValentinaTest/qttestmainlambda.cpp +++ b/src/test/ValentinaTest/qttestmainlambda.cpp @@ -46,6 +46,7 @@ #include "tst_tstranslation.h" #include "tst_vdetail.h" #include "tst_vabstractcurve.h" +#include "tst_vgobject.h" #include "../vmisc/def.h" @@ -95,6 +96,7 @@ int main(int argc, char** argv) ASSERT_TEST(new TST_VCommandLine()); ASSERT_TEST(new TST_TSTranslation()); ASSERT_TEST(new TST_VAbstractCurve()); + ASSERT_TEST(new TST_VGObject()); return status; } diff --git a/src/test/ValentinaTest/tst_vgobject.cpp b/src/test/ValentinaTest/tst_vgobject.cpp new file mode 100644 index 000000000..f864b5f9d --- /dev/null +++ b/src/test/ValentinaTest/tst_vgobject.cpp @@ -0,0 +1,139 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 16 8, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2016 Valentina project + ** All Rights Reserved. + ** + ** Valentina 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. + ** + ** Valentina 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 Valentina. If not, see . + ** + *************************************************************************/ + +#include "tst_vgobject.h" + +#include + +#include "../vgeometry/vgobject.h" +#include "../vmisc/def.h" + +//--------------------------------------------------------------------------------------------------------------------- +TST_VGObject::TST_VGObject(QObject *parent) + :QObject(parent) +{} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_VGObject::TestIsPointOnLineviaPDP_data() +{ + QTest::addColumn("p1"); + QTest::addColumn("p2"); + QTest::addColumn("t"); + QTest::addColumn("excpect"); + + { + const QPointF p1(483.54330708661416, 3819.527433070866); + const QPointF p2(483.54330708661416, 1929.763653543307); + const QPointF t(483.54330708661416, 1920.763653543307); + QTest::newRow("Point is on line, but not on segment.") << p1 << p2 << t << true; + } + + { + const QPointF p1(483.54330708661416, 3819.527433070866); + const QPointF p2(483.54330708661416, 1929.763653543307); + const QPointF t(483.54330708661416, 2874.763653543307); + QTest::newRow("Point is on segment. On middle.") << p1 << p2 << t << true; + } + + { + const QPointF p1(483.54330708661416, 3819.527433070866); + const QPointF p2(483.54330708661416, 1929.763653543307); + const QPointF t(483.54330708661416, 1929.763653543307); + QTest::newRow("Point is on segment. The end of segment.") << p1 << p2 << t << true; + } + + { + const QPointF p1(483.54330708661416, 3819.527433070866); + const QPointF p2(483.54330708661416, 1929.763653543307); + const QPointF t(483.54330708661416 + VGObject::accuracyPointOnLine, 2874.763653543307); + QTest::newRow("Min accuracy gap. On middle.") << p1 << p2 << t << false; + } + + { + const QPointF p1(483.54330708661416, 3819.527433070866); + const QPointF p2(483.54330708661416, 1929.763653543307); + const QPointF t(483.54330708661416 + VGObject::accuracyPointOnLine, 1929.763653543307); + QTest::newRow("Min accuracy gap.") << p1 << p2 << t << false; + } + + { + const QPointF p1(483.54330708661416, 3819.527433070866); + const QPointF p2(483.54330708661416, 1929.763653543307); + const QPointF t(483.54330708661416 + VGObject::accuracyPointOnLine/2., 2874.763653543307); + QTest::newRow("Less than min accuracy gap. On middle.") << p1 << p2 << t << true; + } + + { + const QPointF p1(483.54330708661416, 3819.527433070866); + const QPointF p2(483.54330708661416, 1929.763653543307); + const QPointF t(483.54330708661416 + VGObject::accuracyPointOnLine/2., 1929.763653543307); + QTest::newRow("Less than min accuracy gap.") << p1 << p2 << t << true; + } + + // For more details see issue #534. + { + const QPointF p1(483.54330708661416, 3819.527433070866); + const QPointF p2(483.54330708661416, 1929.763653543307); + const QPointF t(370.1574803149606, 2874.763653543307); + QTest::newRow("Issue 534 - 3 cm gap. On middle.") << p1 << p2 << t << false; + } + + { + const QPointF p1(483.54330708661416, 3819.527433070866); + const QPointF p2(483.54330708661416, 1929.763653543307); + const QPointF t(370.1574803149606, 1929.763653543307); + QTest::newRow("Issue 534 - 3 cm gap.") << p1 << p2 << t << false; + } + + { + const QPointF p1(483.54330708661416, 3819.527433070866); + const QPointF p2(483.54330708661416, 1929.763653543307); + const QPointF t(407.9527559055118, 2874.763653543307); + QTest::newRow("Issue 534 - 2 cm gap. On middle.") << p1 << p2 << t << false; + } + + { + const QPointF p1(483.54330708661416, 3819.527433070866); + const QPointF p2(483.54330708661416, 1929.763653543307); + const QPointF t(407.9527559055118, 1929.763653543307); + QTest::newRow("Issue 534 - 2 cm gap.") << p1 << p2 << t << false; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_VGObject::TestIsPointOnLineviaPDP() const +{ + QFETCH(QPointF, p1); + QFETCH(QPointF, p2); + QFETCH(QPointF, t); + QFETCH(bool, excpect); + + const bool res = VGObject::IsPointOnLineviaPDP(t, p1, p2); + QCOMPARE(res, excpect); +} + diff --git a/src/test/ValentinaTest/tst_vgobject.h b/src/test/ValentinaTest/tst_vgobject.h new file mode 100644 index 000000000..9211f6b17 --- /dev/null +++ b/src/test/ValentinaTest/tst_vgobject.h @@ -0,0 +1,45 @@ +/************************************************************************ + ** + ** @file + ** @author Roman Telezhynskyi + ** @date 16 8, 2016 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2016 Valentina project + ** All Rights Reserved. + ** + ** Valentina 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. + ** + ** Valentina 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 Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef TST_VGOBJECT_H +#define TST_VGOBJECT_H + +#include + +class TST_VGObject : public QObject +{ + Q_OBJECT +public: + explicit TST_VGObject(QObject *parent = nullptr); + +private slots: + void TestIsPointOnLineviaPDP_data(); + void TestIsPointOnLineviaPDP() const; +}; + +#endif // TST_VGOBJECT_H