Skip to content

Commit

Permalink
engine: improve some coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
mcallegari committed Dec 30, 2024
1 parent 6cc7209 commit 0cc5540
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
16 changes: 9 additions & 7 deletions engine/src/rgbalgorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,21 @@ RGBAlgorithm::RGBAlgorithm(Doc * doc)

void RGBAlgorithm::setColors(QVector<QColor> colors)
{
int nCols = acceptColors();
m_colors.clear();
QVectorIterator<QColor> it(colors);
int count = 0;
while (it.hasNext()) {
QColor color = it.next();
if (acceptColors() < count)
m_colors.append(color);
count ++;

for (int i = 0; i < nCols; i++)
{
if (i < colors.count())
m_colors.append(colors.at(i));
}
}

QColor RGBAlgorithm::getColor(uint i) const
{
if (i >= (uint)m_colors.count())
return QColor();

return m_colors[i];
}

Expand Down
23 changes: 17 additions & 6 deletions engine/test/rgbalgorithm/rgbalgorithm_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,23 @@ void RGBAlgorithm_Test::algorithm()
QVERIFY(algo != NULL);
QCOMPARE(algo->type(), RGBAlgorithm::Script);
QCOMPARE(algo->name(), QString("Stripes"));
printf("%s\n", algo->name().toStdString().c_str());
printf("%s\n", algo->name().toStdString().c_str());
printf("%s\n", algo->name().toStdString().c_str());
printf("%s\n", algo->name().toStdString().c_str());
printf("%s\n", algo->name().toStdString().c_str());
printf("%s\n", algo->name().toStdString().c_str());
delete algo;

algo = RGBAlgorithm::algorithm(m_doc, "Balls");
QVERIFY(algo != NULL);
QCOMPARE(algo->type(), RGBAlgorithm::Script);
QCOMPARE(algo->name(), QString("Balls"));
QCOMPARE(algo->apiVersion(), 3);
QCOMPARE(algo->acceptColors(), 5);
QVector<QColor> colors;
colors << Qt::red;
colors << Qt::green;
colors << Qt::blue;
algo->setColors(colors);

QCOMPARE(algo->getColor(0), Qt::red);
QCOMPARE(algo->getColor(1), Qt::green);
QCOMPARE(algo->getColor(2), Qt::blue);
delete algo;
}

Expand Down
8 changes: 8 additions & 0 deletions engine/test/rgbtext/rgbtext_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,4 +441,12 @@ void RGBText_Test::verticalScroll()
}
}

void RGBText_Test::unused()
{
RGBText text(m_doc);
QVector<uint> colors;
text.rgbMapSetColors(colors);
QCOMPARE(text.rgbMapGetColors().isEmpty(), true);
}

QTEST_MAIN(RGBText_Test)
1 change: 1 addition & 0 deletions engine/test/rgbtext/rgbtext_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ private slots:
void staticLetters();
void horizontalScroll();
void verticalScroll();
void unused();

private:
Doc * m_doc;
Expand Down

0 comments on commit 0cc5540

Please sign in to comment.