File indexing completed on 2024-05-12 04:20:15
0001 /** 0002 * SPDX-FileCopyrightText: 2001-2015 Klaralvdalens Datakonsult AB. All rights reserved. 0003 * 0004 * This file is part of the KD Chart library. 0005 * 0006 * SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #include <KChartPalette> 0010 #include <QtTest/QtTest> 0011 0012 using namespace KChart; 0013 0014 class TestKChartPalette: public QObject { 0015 Q_OBJECT 0016 private Q_SLOTS: 0017 0018 void testKChartPaletteInit() 0019 { 0020 Palette p; 0021 QCOMPARE( p.isValid(), false ); 0022 Palette *p2 = new Palette(); 0023 QCOMPARE( p2->isValid(), false ); 0024 QCOMPARE( p2->size(), 0 ); 0025 delete p2; 0026 } 0027 0028 void testKChartPaletteAddBrush() 0029 { 0030 Palette p; 0031 p.addBrush( Qt::red ); 0032 QCOMPARE( p.isValid(), true ); 0033 QCOMPARE( p.size(), 1 ); 0034 // make sure adding a brush at an invalid position does the right thing 0035 p.addBrush( Qt::blue, 7 ); 0036 QCOMPARE( p.isValid(), true ); 0037 QCOMPARE( p.size(), 2 ); 0038 } 0039 0040 void testKChartPaletteGetBrush() 0041 { 0042 Palette p; 0043 p.addBrush( Qt::red ); 0044 p.addBrush( Qt::blue, 7 ); 0045 QCOMPARE( p.isValid(), true ); 0046 QCOMPARE( p.size(), 2 ); 0047 QBrush brush = p.getBrush( 1 ); 0048 // work around the lack of qCompare for QBrushes 0049 bool result = brush == Qt::blue; 0050 QCOMPARE( result, true ); 0051 // test wrap around 0052 brush = p.getBrush( 2 ); 0053 result = brush == Qt::red; 0054 QCOMPARE( result, true ); 0055 } 0056 0057 void testKChartPaletteRemoveBrush() 0058 { 0059 Palette p; 0060 p.addBrush( Qt::red ); 0061 p.removeBrush( 2 ); 0062 QCOMPARE( p.size(), 1 ); 0063 QCOMPARE( p.isValid(), true ); 0064 p.removeBrush( 0 ); 0065 QCOMPARE( p.isValid(), false ); 0066 } 0067 0068 void testKChartPaletteDefaultPalette() 0069 { 0070 const Palette def = Palette::defaultPalette(); 0071 QBrush brush = def.getBrush( 5 ); 0072 bool result = brush == Qt::yellow; 0073 QCOMPARE( result, true ); 0074 } 0075 0076 void testKChartPaletteSuduedPalette() 0077 { 0078 const Palette def = Palette::subduedPalette(); 0079 QBrush brush = def.getBrush( 5 ); 0080 bool result = brush == QColor( 0x86,0xe0,0x70 ); 0081 QCOMPARE( result, true ); 0082 } 0083 0084 void testKChartPaletteRainbowPalette() 0085 { 0086 const Palette def = Palette::rainbowPalette(); 0087 QBrush brush = def.getBrush( 5 ); 0088 bool result = brush == Qt::cyan; 0089 QCOMPARE( result, true ); 0090 } 0091 0092 void testKChartPaletteCopying() 0093 { 0094 const Palette def = Palette::rainbowPalette(); 0095 const Palette other = def; 0096 QBrush brush = other.getBrush( 5 ); 0097 bool result = brush == Qt::cyan; 0098 QCOMPARE( result, true ); 0099 QCOMPARE( def.size(), other.size() ); 0100 } 0101 0102 }; 0103 0104 QTEST_MAIN(TestKChartPalette) 0105 0106 #include "main.moc"