File indexing completed on 2024-05-12 15:53:54

0001 /**
0002  * Copyright (C) 2001-2015 Klaralvdalens Datakonsult AB.  All rights reserved.
0003  *
0004  * This file is part of the KD Chart library.
0005  *
0006  * This program is free software; you can redistribute it and/or
0007  * modify it under the terms of the GNU General Public License as
0008  * published by the Free Software Foundation; either version 2 of
0009  * the License, or (at your option) any later version.
0010  *
0011  * This program is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014  * GNU General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU General Public License
0017  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
0018  */
0019 
0020 #include <KChartPalette>
0021 #include <QtTest/QtTest>
0022 
0023 using namespace KChart;
0024 
0025 class TestKChartPalette: public QObject {
0026   Q_OBJECT
0027 private Q_SLOTS:
0028 
0029   void testKChartPaletteInit()
0030   {
0031     Palette p;
0032     QCOMPARE( p.isValid(), false );
0033     Palette *p2 = new Palette();
0034     QCOMPARE( p2->isValid(), false );
0035     QCOMPARE( p2->size(), 0 );
0036     delete p2;
0037   }
0038 
0039   void testKChartPaletteAddBrush()
0040   {
0041     Palette p;
0042     p.addBrush( Qt::red );
0043     QCOMPARE( p.isValid(), true );
0044     QCOMPARE( p.size(), 1 );
0045     // make sure adding a brush at an invalid position does the right thing
0046     p.addBrush( Qt::blue, 7 );
0047     QCOMPARE( p.isValid(), true );
0048     QCOMPARE( p.size(), 2 );
0049   }
0050 
0051   void testKChartPaletteGetBrush()
0052   {
0053     Palette p;
0054     p.addBrush( Qt::red );
0055     p.addBrush( Qt::blue, 7 );
0056     QCOMPARE( p.isValid(), true );
0057     QCOMPARE( p.size(), 2 );
0058     QBrush brush = p.getBrush( 1 );
0059     // work around the lack of qCompare for QBrushes
0060     bool result = brush == Qt::blue;
0061     QCOMPARE( result, true );
0062     // test wrap around
0063     brush = p.getBrush( 2 );
0064     result = brush == Qt::red;
0065     QCOMPARE( result, true );
0066   }
0067 
0068   void testKChartPaletteRemoveBrush()
0069   {
0070     Palette p;
0071     p.addBrush( Qt::red );
0072     p.removeBrush( 2 );
0073     QCOMPARE( p.size(), 1 );
0074     QCOMPARE( p.isValid(), true );
0075     p.removeBrush( 0 );
0076     QCOMPARE( p.isValid(), false );
0077   }
0078 
0079   void testKChartPaletteDefaultPalette()
0080   {
0081     const Palette def = Palette::defaultPalette();
0082     QBrush brush = def.getBrush( 5 );
0083     bool result = brush == Qt::yellow;
0084     QCOMPARE( result, true );
0085   }
0086 
0087   void testKChartPaletteSuduedPalette()
0088   {
0089     const Palette def = Palette::subduedPalette();
0090     QBrush brush = def.getBrush( 5 );
0091     bool result = brush == QColor( 0x86,0xe0,0x70 );
0092     QCOMPARE( result, true );
0093   }
0094 
0095   void testKChartPaletteRainbowPalette()
0096   {
0097     const Palette def = Palette::rainbowPalette();
0098     QBrush brush = def.getBrush( 5 );
0099     bool result = brush == Qt::cyan;
0100     QCOMPARE( result, true );
0101   }
0102 
0103   void testKChartPaletteCopying()
0104   {
0105     const Palette def = Palette::rainbowPalette();
0106     const Palette other = def;
0107     QBrush brush = other.getBrush( 5 );
0108     bool result = brush == Qt::cyan;
0109     QCOMPARE( result, true );
0110     QCOMPARE( def.size(), other.size() );
0111   }
0112 
0113 };
0114 
0115 QTEST_MAIN(TestKChartPalette)
0116 
0117 #include "main.moc"