File indexing completed on 2024-04-28 15:29:28

0001 /*
0002     SPDX-FileCopyrightText: 2012 Benjamin Port <benjamin.port@ben2367.fr>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include <kplotpoint.h>
0008 
0009 #include <QTest>
0010 
0011 class KPlotPointTest : public QObject
0012 {
0013     Q_OBJECT
0014 
0015 private Q_SLOTS:
0016 
0017     void testConstructor()
0018     {
0019         KPlotPoint *p1 = new KPlotPoint(2.0, 3.0, QStringLiteral("label"), 5.0);
0020         KPlotPoint *p2 = new KPlotPoint(QPointF(2.0, 3.0), QStringLiteral("label"), 5.0);
0021 
0022         QCOMPARE(p1->x(), 2.0);
0023         QCOMPARE(p2->x(), 2.0);
0024 
0025         QCOMPARE(p1->y(), 3.0);
0026         QCOMPARE(p2->y(), 3.0);
0027 
0028         QCOMPARE(p1->barWidth(), 5.0);
0029         QCOMPARE(p2->barWidth(), 5.0);
0030 
0031         QCOMPARE(p1->label(), QString::fromLatin1("label"));
0032         QCOMPARE(p2->label(), QString::fromLatin1("label"));
0033 
0034         delete p1;
0035         delete p2;
0036     }
0037 
0038     void testPosition()
0039     {
0040         KPlotPoint *p1 = new KPlotPoint(2.0, 3.0, QStringLiteral("label"), 5.0);
0041 
0042         p1->setX(4.0);
0043         QCOMPARE(p1->x(), 4.0);
0044 
0045         p1->setY(6.0);
0046         QCOMPARE(p1->y(), 6.0);
0047 
0048         QCOMPARE(p1->position(), QPointF(4.0, 6.0));
0049 
0050         p1->setPosition(QPointF(1.0, 7.0));
0051         QCOMPARE(p1->position(), QPointF(1.0, 7.0));
0052         QCOMPARE(p1->x(), 1.0);
0053         QCOMPARE(p1->y(), 7.0);
0054 
0055         delete p1;
0056     }
0057 
0058     void testLabel()
0059     {
0060         KPlotPoint *p1 = new KPlotPoint(2.0, 3.0, QStringLiteral("label"), 5.0);
0061 
0062         p1->setLabel(QStringLiteral("newLabel"));
0063         QCOMPARE(p1->label(), QString::fromLatin1("newLabel"));
0064 
0065         delete p1;
0066     }
0067 
0068     void testBarWidth()
0069     {
0070         KPlotPoint *p1 = new KPlotPoint(2.0, 3.0, QStringLiteral("label"), 5.0);
0071 
0072         p1->setBarWidth(5.0);
0073         QCOMPARE(p1->barWidth(), 5.0);
0074 
0075         delete p1;
0076     }
0077 };
0078 
0079 QTEST_MAIN(KPlotPointTest)
0080 
0081 #include "kplotpointtest.moc"