Changeset View
Changeset View
Standalone View
Standalone View
libs/pigment/tests/TestKisSwatchGroup.cpp
- This file was added.
1 | #include "TestKisSwatchGroup.h" | ||||
---|---|---|---|---|---|
2 | #include <QtTest> | ||||
3 | | ||||
4 | void TestKisSwatchGroup::testAddingOneEntry() | ||||
5 | { | ||||
6 | KisSwatch e; | ||||
7 | e.setName("first"); | ||||
8 | g.setEntry(e, 0, 0); | ||||
9 | QVERIFY(g.checkEntry(0, 0)); | ||||
10 | QVERIFY(!g.checkEntry(1, 2)); | ||||
11 | QVERIFY(!g.checkEntry(10, 5)); | ||||
12 | QCOMPARE(g.getEntry(0, 0), e); | ||||
13 | QCOMPARE(g.colorCount(), 1); | ||||
14 | testSwatches[QPair<int, int>(0, 0)] = e; | ||||
15 | } | ||||
16 | | ||||
17 | void TestKisSwatchGroup::testAddingMultipleEntries() | ||||
18 | { | ||||
19 | KisSwatch e2; | ||||
20 | e2.setName("second"); | ||||
21 | g.setEntry(e2, 9, 3); | ||||
22 | QCOMPARE(g.columnCount(), 16); | ||||
23 | QVERIFY(g.checkEntry(9, 3)); | ||||
24 | QVERIFY(!g.checkEntry(1, 2)); | ||||
25 | QVERIFY(!g.checkEntry(10, 5)); | ||||
26 | QVERIFY(g.checkEntry(0, 0)); | ||||
27 | QCOMPARE(g.getEntry(0, 0).name(), QString("first")); | ||||
28 | KisSwatch e3; | ||||
29 | e3.setName("third"); | ||||
30 | g.setEntry(e3, 4, 12); | ||||
31 | QCOMPARE(g.colorCount(), 3); | ||||
32 | QVERIFY(g.checkEntry(9, 3)); | ||||
33 | QCOMPARE(g.getEntry(9, 3).name(), QString("second")); | ||||
34 | testSwatches[QPair<int, int>(9, 3)] = e2; | ||||
35 | testSwatches[QPair<int, int>(4, 12)] = e3; | ||||
36 | } | ||||
37 | | ||||
38 | void TestKisSwatchGroup::testReplaceEntries() | ||||
39 | { | ||||
40 | KisSwatch e4; | ||||
41 | e4.setName("fourth"); | ||||
42 | g.setEntry(e4, 0, 0); | ||||
43 | QCOMPARE(g.colorCount(), 3); | ||||
44 | QVERIFY(g.checkEntry(0, 0)); | ||||
45 | QCOMPARE(g.getEntry(0, 0).name(), QString("fourth")); | ||||
46 | testSwatches[QPair<int, int>(0, 0)] = e4; | ||||
47 | } | ||||
48 | | ||||
49 | void TestKisSwatchGroup::testRemoveEntries() | ||||
50 | { | ||||
51 | testSwatches.remove(QPair<int, int>(9, 3)); | ||||
52 | QVERIFY(g.removeEntry(9, 3)); | ||||
53 | QCOMPARE(g.colorCount(), testSwatches.size()); | ||||
54 | QVERIFY(!g.removeEntry(13, 10)); | ||||
55 | QVERIFY(!g.checkEntry(9, 3)); | ||||
56 | } | ||||
57 | | ||||
58 | void TestKisSwatchGroup::testChangeColumnNumber() | ||||
59 | { | ||||
60 | g.setColumnCount(20); | ||||
61 | QCOMPARE(g.columnCount(), 20); | ||||
62 | for (QPair<int, int> p : testSwatches.keys()) { | ||||
63 | QCOMPARE(testSwatches[p], g.getEntry(p.first, p.second)); | ||||
64 | } | ||||
65 | g.setColumnCount(10); | ||||
66 | int keptCount = 0; | ||||
67 | for (QPair<int, int> p : testSwatches.keys()) { | ||||
68 | if (p.first < 10) { | ||||
69 | keptCount++; | ||||
70 | QCOMPARE(testSwatches[p], g.getEntry(p.first, p.second)); | ||||
71 | } | ||||
72 | } | ||||
73 | QCOMPARE(keptCount, g.colorCount()); | ||||
74 | } | ||||
75 | | ||||
76 | void TestKisSwatchGroup::testAddEntry() | ||||
77 | { | ||||
78 | KisSwatchGroup g2; | ||||
79 | g2.setColumnCount(3); | ||||
80 | g2.setRowCount(1); | ||||
81 | for (int i = 0; i != 3; i++) { | ||||
82 | g2.addEntry(KisSwatch()); | ||||
83 | } | ||||
84 | QCOMPARE(g2.rowCount(), 1); | ||||
85 | QCOMPARE(g2.columnCount(), 3); | ||||
86 | QCOMPARE(g2.colorCount(), 3); | ||||
87 | g2.addEntry(KisSwatch()); | ||||
88 | QCOMPARE(g2.rowCount(), 2); | ||||
89 | QCOMPARE(g2.columnCount(), 3); | ||||
90 | QCOMPARE(g2.colorCount(), 4); | ||||
91 | g2.setRowCount(1); | ||||
92 | QCOMPARE(g2.rowCount(), 1); | ||||
93 | QCOMPARE(g2.columnCount(), 3); | ||||
94 | QCOMPARE(g2.colorCount(), 3); | ||||
95 | for (int i = 0; i != 4; i++) { | ||||
96 | g2.addEntry(KisSwatch()); | ||||
97 | } | ||||
98 | QCOMPARE(g2.rowCount(), 3); | ||||
99 | QCOMPARE(g2.columnCount(), 3); | ||||
100 | QCOMPARE(g2.colorCount(), 7); | ||||
101 | } | ||||
102 | | ||||
103 | QTEST_GUILESS_MAIN(TestKisSwatchGroup) |