Commit f440685c authored by Anna Medonosová's avatar Anna Medonosová

Basic unittests for gamut masking classes

parent a8524451
......@@ -10,6 +10,7 @@ include_directories(
add_subdirectory(styles)
add_subdirectory(tests)
add_subdirectory(resources/tests)
set(kritaflake_SRCS
KoGradientHelper.cpp
......
......@@ -22,6 +22,7 @@
#include <QRectF>
#include <QSizeF>
#include <kis_assert.h>
#include <FlakeDebug.h>
//#define DEBUG_GAMUT_MASK_CONVERTER
......@@ -155,6 +156,9 @@ void KisGamutMaskViewConverter::setViewSize(QSize viewSize)
void KisGamutMaskViewConverter::setMaskSize(QSizeF maskSize)
{
KIS_ASSERT(!qIsNull(maskSize.width()));
KIS_ASSERT(!qIsNull(maskSize.height()));
m_maskSize = maskSize;
m_maskResolution = maskSize.width();
......
......@@ -41,7 +41,6 @@
#include <KisGamutMaskViewConverter.h>
#include <kis_assert.h>
KoGamutMaskShape::KoGamutMaskShape(KoShape* shape)
: m_maskShape(shape)
, m_shapePaintingContext(KoShapePaintingContext())
......
set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} )
include(ECMAddTests)
include_directories(${CMAKE_SOURCE_DIR}/sdk/tests)
macro_add_unittest_definitions()
# needs kritaimage for TestUtil
ecm_add_tests(
KoGamutMaskTest.cpp
# KoGamutMaskShapeTest.cpp
LINK_LIBRARIES kritaflake kritaimage Qt5::Test
NAME_PREFIX "libs-flake-")
/*
* Copyright (c) 2019 Anna Medonosova <anna.medonosova@gmail.com>
*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <QTest>
#include <resources/KoGamutMask.h>
#include <KisGamutMaskViewConverter.h>
#include <testutil.h>
#include "KoGamutMaskTest.h"
KoGamutMaskTest::KoGamutMaskTest(QObject *parent) : QObject(parent)
{
}
void KoGamutMaskTest::testCoordIsClear()
{
QFETCH(QString, maskFile);
QFETCH(QPointF, coord);
QFETCH(int, maskRotation);
QFETCH(bool, expectedOutput);
QScopedPointer<KoGamutMask> mask(new KoGamutMask(TestUtil::fetchDataFileLazy(maskFile)));
mask->load();
Q_ASSERT(mask->valid());
mask->setRotation(maskRotation);
KisGamutMaskViewConverter* converter = new KisGamutMaskViewConverter();
converter->setMaskSize(mask->maskSize());
converter->setViewSize(QSize(100.0, 100.0));
bool maskOutput = mask->coordIsClear(coord, *converter, false);
QCOMPARE(maskOutput, expectedOutput);
}
void KoGamutMaskTest::testCoordIsClear_data()
{
QTest::addColumn<QString>("maskFile");
QTest::addColumn<QPointF>("coord");
QTest::addColumn<int>("maskRotation");
QTest::addColumn<bool>("expectedOutput");
// single shape mask
QTest::addRow("Atmospheric_Triad.kgm: disallowed coordinate, no rotation") << "Atmospheric_Triad.kgm"
<< QPointF(0.0, 0.0) << 0
<< false;
QTest::addRow("Atmospheric_Triad.kgm: allowed coordinate, no rotation") << "Atmospheric_Triad.kgm"
<< QPointF(33.0, 71.0) << 0
<< true;
QTest::addRow("Atmospheric_Triad.kgm: disallowed coordinate, with rotation") << "Atmospheric_Triad.kgm"
<< QPointF(33.0, 71.0) << 180
<< false;
QTest::addRow("Atmospheric_Triad.kgm: allowed coordinate, with rotation") << "Atmospheric_Triad.kgm"
<< QPointF(76.4,60.9) << 180
<< true;
// multiple shapes mask
QTest::addRow("Dominant_Hue_With_Accent.kgm: allowed coordinate, shape 1, no rotation")
<< "Dominant_Hue_With_Accent.kgm"
<< QPointF(71.0, 49.0) << 0
<< true;
QTest::addRow("Dominant_Hue_With_Accent.kgm: allowed coordinate, shape 2, no rotation")
<< "Dominant_Hue_With_Accent.kgm"
<< QPointF(11.0, 51.0) << 0
<< true;
QTest::addRow("Dominant_Hue_With_Accent.kgm: allowed coordinate, shape 1, with rotation")
<< "Dominant_Hue_With_Accent.kgm"
<< QPointF(40.0, 21.0) << 256
<< true;
QTest::addRow("Dominant_Hue_With_Accent.kgm: allowed coordinate, shape 2, with rotation")
<< "Dominant_Hue_With_Accent.kgm"
<< QPointF(57.0, 82.0) << 256
<< true;
}
void KoGamutMaskTest::testLoad()
{
QFETCH(QString, maskFile);
QFETCH(QString, expectedTitle);
QFETCH(QString, expectedDescription);
QFETCH(int, expectedShapeCount);
QScopedPointer<KoGamutMask> mask(new KoGamutMask(TestUtil::fetchDataFileLazy(maskFile)));
mask->load();
Q_ASSERT(mask->valid());
QCOMPARE(mask->title(), expectedTitle);
QCOMPARE(mask->description(), expectedDescription);
QCOMPARE(mask->koShapes().size(), expectedShapeCount);
}
void KoGamutMaskTest::testLoad_data()
{
QTest::addColumn<QString>("maskFile");
QTest::addColumn<QString>("expectedTitle");
QTest::addColumn<QString>("expectedDescription");
QTest::addColumn<int>("expectedShapeCount");
QTest::addRow("single shape mask")
<< "Atmospheric_Triad.kgm"
<< "Atmospheric Triad" << "test gamut mask description"
<< 1;
QTest::addRow("multiple shape mask")
<< "Dominant_Hue_With_Accent.kgm"
<< "Dominant Hue With Accent" << ""
<< 2;
}
QTEST_MAIN(KoGamutMaskTest);
/*
* Copyright (c) 2019 Anna Medonosova <anna.medonosova@gmail.com>
*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef KOGAMUTMASKTEST_H
#define KOGAMUTMASKTEST_H
#include <QObject>
class KoGamutMaskTest : public QObject
{
Q_OBJECT
public:
explicit KoGamutMaskTest(QObject *parent = nullptr);
private Q_SLOTS:
void testCoordIsClear();
void testCoordIsClear_data();
void testLoad();
void testLoad_data();
// TODO: add preview vs. non-preview testing
};
#endif // KOGAMUTMASKTEST_H
......@@ -33,6 +33,7 @@ ecm_add_tests(
TestSegmentTypeCommand.cpp
TestKoDrag.cpp
TestKoMarkerCollection.cpp
KisGamutMaskViewConverterTest.cpp
LINK_LIBRARIES kritaflake Qt5::Test
NAME_PREFIX "libs-flake-")
......
/*
* Copyright (c) 2019 Anna Medonosova <anna.medonosova@gmail.com>
*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <QScopedPointer>
#include <KisGamutMaskViewConverter.h>
#include <kis_assert_exception.h>
#include "KisGamutMaskViewConverterTest.h"
KisGamutMaskViewConverterTest::KisGamutMaskViewConverterTest(QObject *parent) : QObject(parent)
{
}
void KisGamutMaskViewConverterTest::testDocumentToViewX()
{
QFETCH(qreal, input);
QFETCH(qreal, expectedOutput);
QFETCH(QSizeF, maskSize);
QFETCH(QSize, viewSize);
QScopedPointer<KisGamutMaskViewConverter> converter(new KisGamutMaskViewConverter());
converter->setMaskSize(maskSize);
converter->setViewSize(viewSize);
qreal converterOutput = converter->documentToViewX(input);
QCOMPARE(converterOutput, expectedOutput);
}
void KisGamutMaskViewConverterTest::testDocumentToViewX_data()
{
QTest::addColumn<qreal>("input");
QTest::addColumn<qreal>("expectedOutput");
QTest::addColumn<QSizeF>("maskSize");
QTest::addColumn<QSize>("viewSize");
QTest::newRow("mask < view") << 2.0 << 4.0 << QSizeF(200.0, 200.0) << QSize(400, 400);
QTest::newRow("view < mask") << 2.0 << 1.0 << QSizeF(400.0, 400.0) << QSize(200, 200);
QTest::newRow("view not square") << 2.0 << 4.0 << QSizeF(200.0, 300.0) << QSize(400, 400);
QTest::newRow("mask not square") << 2.0 << 4.0 << QSizeF(200.0, 200.0) << QSize(400, 600);
}
void KisGamutMaskViewConverterTest::testDocumentToViewY()
{
QFETCH(qreal, input);
QFETCH(qreal, expectedOutput);
QFETCH(QSizeF, maskSize);
QFETCH(QSize, viewSize);
QScopedPointer<KisGamutMaskViewConverter> converter(new KisGamutMaskViewConverter());
converter->setMaskSize(maskSize);
converter->setViewSize(viewSize);
qreal converterOutput = converter->documentToViewY(input);
QCOMPARE(converterOutput, expectedOutput);
}
void KisGamutMaskViewConverterTest::testDocumentToViewY_data()
{
QTest::addColumn<qreal>("input");
QTest::addColumn<qreal>("expectedOutput");
QTest::addColumn<QSizeF>("maskSize");
QTest::addColumn<QSize>("viewSize");
QTest::newRow("mask < view") << 2.0 << 4.0 << QSizeF(200.0, 200.0) << QSize(400, 400);
QTest::newRow("view < mask") << 2.0 << 1.0 << QSizeF(400.0, 400.0) << QSize(200, 200);
QTest::newRow("view not square") << 2.0 << 4.0 << QSizeF(200.0, 300.0) << QSize(400, 400);
QTest::newRow("mask not square") << 2.0 << 4.0 << QSizeF(200.0, 200.0) << QSize(400, 600);
}
void KisGamutMaskViewConverterTest::testViewToDocumentX()
{
QFETCH(qreal, input);
QFETCH(qreal, expectedOutput);
QFETCH(QSizeF, maskSize);
QFETCH(QSize, viewSize);
QScopedPointer<KisGamutMaskViewConverter> converter(new KisGamutMaskViewConverter());
converter->setMaskSize(maskSize);
converter->setViewSize(viewSize);
qreal converterOutput = converter->viewToDocumentX(input);
QCOMPARE(converterOutput, expectedOutput);
}
void KisGamutMaskViewConverterTest::testViewToDocumentX_data()
{
QTest::addColumn<qreal>("input");
QTest::addColumn<qreal>("expectedOutput");
QTest::addColumn<QSizeF>("maskSize");
QTest::addColumn<QSize>("viewSize");
QTest::newRow("mask < view") << 4.0 << 2.0 << QSizeF(200.0, 200.0) << QSize(400, 400);
QTest::newRow("view < mask") << 1.0 << 2.0 << QSizeF(400.0, 400.0) << QSize(200, 200);
QTest::newRow("view not square") << 4.0 << 2.0 << QSizeF(200.0, 300.0) << QSize(400, 400);
QTest::newRow("mask not square") << 4.0 << 2.0 << QSizeF(200.0, 200.0) << QSize(400, 600);
}
void KisGamutMaskViewConverterTest::testViewToDocumentY()
{
QFETCH(qreal, input);
QFETCH(qreal, expectedOutput);
QFETCH(QSizeF, maskSize);
QFETCH(QSize, viewSize);
QScopedPointer<KisGamutMaskViewConverter> converter(new KisGamutMaskViewConverter());
converter->setMaskSize(maskSize);
converter->setViewSize(viewSize);
qreal converterOutput = converter->viewToDocumentY(input);
QCOMPARE(converterOutput, expectedOutput);
}
void KisGamutMaskViewConverterTest::testViewToDocumentY_data()
{
QTest::addColumn<qreal>("input");
QTest::addColumn<qreal>("expectedOutput");
QTest::addColumn<QSizeF>("maskSize");
QTest::addColumn<QSize>("viewSize");
QTest::newRow("mask < view") << 4.0 << 2.0 << QSizeF(200.0, 200.0) << QSize(400, 400);
QTest::newRow("view < mask") << 1.0 << 2.0 << QSizeF(400.0, 400.0) << QSize(200, 200);
QTest::newRow("view not square") << 4.0 << 2.0 << QSizeF(200.0, 300.0) << QSize(400, 400);
QTest::newRow("mask not square") << 4.0 << 2.0 << QSizeF(200.0, 200.0) << QSize(400, 600);
}
QTEST_MAIN(KisGamutMaskViewConverterTest);
/*
* Copyright (c) 2019 Anna Medonosova <anna.medonosova@gmail.com>
*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef KISGAMUTMASKVIEWCONVERTERTEST_H
#define KISGAMUTMASKVIEWCONVERTERTEST_H
#include <QObject>
#include <QTest>
class KisGamutMaskViewConverterTest : public QObject
{
Q_OBJECT
public:
explicit KisGamutMaskViewConverterTest(QObject *parent = nullptr);
private Q_SLOTS:
void testDocumentToViewX();
void testDocumentToViewX_data();
void testDocumentToViewY();
void testDocumentToViewY_data();
void testViewToDocumentX();
void testViewToDocumentX_data();
void testViewToDocumentY();
void testViewToDocumentY_data();
};
#endif // KISGAMUTMASKVIEWCONVERTERTEST_H
set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} )
include_directories(${CMAKE_SOURCE_DIR}/libs/image/metadata
include_directories(${CMAKE_SOURCE_DIR}/libs/image/metadata
${CMAKE_SOURCE_DIR}/sdk/tests )
include(ECMAddTests)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment