File: tst_barcategoryaxis.cpp

package info (click to toggle)
qt6-graphs 6.9.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,124 kB
  • sloc: cpp: 65,200; javascript: 204; makefile: 23
file content (189 lines) | stat: -rw-r--r-- 5,020 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

#include "qtestcase.h"
#include <QtGraphs/QBarCategoryAxis>
#include <QtTest/QtTest>

class tst_barcategoryaxis : public QObject
{
    Q_OBJECT

private slots:
    void initTestCase();
    void cleanupTestCase();
    void init();
    void cleanup();

    void construct();

    void initialProperties();
    void initializeProperties();

    void appendInsertRemove();
    void replaceClear();

private:
    QBarCategoryAxis *m_axis;
};

void tst_barcategoryaxis::initTestCase() {}

void tst_barcategoryaxis::cleanupTestCase() {}

void tst_barcategoryaxis::init()
{
    m_axis = new QBarCategoryAxis();
}

void tst_barcategoryaxis::cleanup()
{
    delete m_axis;
}

void tst_barcategoryaxis::construct()
{
    QBarCategoryAxis *axis = new QBarCategoryAxis();
    QVERIFY(axis);
    delete axis;
}

void tst_barcategoryaxis::initialProperties()
{
    QVERIFY(m_axis);

    QCOMPARE(m_axis->categories(), {});
    QCOMPARE(m_axis->min(), "");
    QCOMPARE(m_axis->max(), "");
    QCOMPARE(m_axis->count(), 0);
}

void tst_barcategoryaxis::initializeProperties()
{
    QVERIFY(m_axis);

    QSignalSpy spy0(m_axis, &QBarCategoryAxis::categoriesChanged);
    QSignalSpy spy1(m_axis, &QBarCategoryAxis::minChanged);
    QSignalSpy spy2(m_axis, &QBarCategoryAxis::maxChanged);
    QSignalSpy spy3(m_axis, &QBarCategoryAxis::categoryRangeChanged);
    QSignalSpy spy4(m_axis, &QBarCategoryAxis::countChanged);

    QStringList cats = {"One", "Two", "Three"};

    m_axis->setCategories(cats);

    QCOMPARE(m_axis->categories(), cats);
    QCOMPARE(m_axis->min(), "One");
    QCOMPARE(m_axis->max(), "Three");
    QCOMPARE(m_axis->count(), 3);

    m_axis->setMin("Zero");
    m_axis->setMax("Ten");

    // TODO: QTBUG-121718
    // QCOMPARE(m_axis->min(), "Zero");
    // QCOMPARE(m_axis->max(), "Ten");

    m_axis->setRange("Zero", "Ten");

    QCOMPARE(spy0.size(), 1);
    QCOMPARE(spy1.size(), 1);
    QCOMPARE(spy2.size(), 1);
    QCOMPARE(spy3.size(), 1);
    QCOMPARE(spy4.size(), 1);

    // TODO: QTBUG-121718
    // QCOMPARE(m_axis->min(), "Zero");
    // QCOMPARE(m_axis->max(), "Ten");
}

void tst_barcategoryaxis::appendInsertRemove()
{
    QVERIFY(m_axis);

    QSignalSpy spy0(m_axis, &QBarCategoryAxis::categoriesChanged);
    QSignalSpy spy1(m_axis, &QBarCategoryAxis::minChanged);
    QSignalSpy spy2(m_axis, &QBarCategoryAxis::maxChanged);
    QSignalSpy spy3(m_axis, &QBarCategoryAxis::categoryRangeChanged);
    QSignalSpy spy4(m_axis, &QBarCategoryAxis::countChanged);

    QStringList cats = {"One", "Two", "Three"};
    QStringList morecats = {"Four", "Five", "Six"};
    QStringList allcats = cats + morecats;
    QStringList mixedcats = {"One", "Four", "Two", "Five", "Six", "Three"};

    // Append 3
    for (int i = 0; i < cats.count(); ++i)
        m_axis->append(cats[i]);

    QCOMPARE(m_axis->categories(), cats);
    QCOMPARE(m_axis->min(), cats[0]);
    QCOMPARE(m_axis->max(), cats[cats.length() - 1]);

    // Append 3 more
    for (int i = 0; i < morecats.count(); ++i)
        m_axis->append(morecats[i]);

    QCOMPARE(m_axis->categories(), allcats);
    QCOMPARE(m_axis->min(), cats[0]);
    QCOMPARE(m_axis->max(), morecats[morecats.length() - 1]);

    // Remove the first 3
    for (int i = 0; i < cats.count(); ++i)
        m_axis->remove(cats[i]);

    QCOMPARE(m_axis->categories(), morecats);

    // Insert them in between
    m_axis->insert(3, cats[2]);
    m_axis->insert(1, cats[1]);
    m_axis->insert(0, cats[0]);

    QCOMPARE(m_axis->categories(), mixedcats);
    QCOMPARE(m_axis->min(), mixedcats[0]);
    QCOMPARE(m_axis->max(), mixedcats[mixedcats.length() - 1]);

    QCOMPARE(spy0.size(), 12);
    QCOMPARE(spy1.size(), 5);
    QCOMPARE(spy2.size(), 7);
    QCOMPARE(spy3.size(), 11);
    QCOMPARE(spy4.size(), 12);
}

void tst_barcategoryaxis::replaceClear()
{
    QVERIFY(m_axis);

    QSignalSpy spy0(m_axis, &QBarCategoryAxis::categoriesChanged);
    QSignalSpy spy1(m_axis, &QBarCategoryAxis::minChanged);
    QSignalSpy spy2(m_axis, &QBarCategoryAxis::maxChanged);
    QSignalSpy spy3(m_axis, &QBarCategoryAxis::categoryRangeChanged);
    QSignalSpy spy4(m_axis, &QBarCategoryAxis::countChanged);

    QStringList mixedcats = {"One", "Four", "Two", "Five", "Six", "Three"};
    QStringList replacedcats = {"Ten", "Four", "Fifteen", "Five", "Six", "Twenty"};

    m_axis->setCategories(mixedcats);

    // Replace 3
    m_axis->replace("One", "Ten");
    m_axis->replace("Two", "Fifteen");
    m_axis->replace("Three", "Twenty");

    QCOMPARE(m_axis->categories(), replacedcats);
    QCOMPARE(m_axis->min(), "Ten");
    QCOMPARE(m_axis->max(), "Twenty");

    // Clear
    m_axis->clear();
    QCOMPARE(m_axis->count(), 0);

    QCOMPARE(spy0.size(), 5);
    QCOMPARE(spy1.size(), 3);
    QCOMPARE(spy2.size(), 3);
    QCOMPARE(spy3.size(), 4);
    QCOMPARE(spy4.size(), 5);
}

QTEST_MAIN(tst_barcategoryaxis)
#include "tst_barcategoryaxis.moc"