From 0cc5540737a7222e2d173d39d54b178933d497fd Mon Sep 17 00:00:00 2001 From: Massimo Callegari Date: Mon, 30 Dec 2024 12:04:09 +0100 Subject: [PATCH] engine: improve some coverage --- engine/src/rgbalgorithm.cpp | 16 +++++++------ .../test/rgbalgorithm/rgbalgorithm_test.cpp | 23 ++++++++++++++----- engine/test/rgbtext/rgbtext_test.cpp | 8 +++++++ engine/test/rgbtext/rgbtext_test.h | 1 + 4 files changed, 35 insertions(+), 13 deletions(-) diff --git a/engine/src/rgbalgorithm.cpp b/engine/src/rgbalgorithm.cpp index 3b87ef052d..86cabdce4d 100644 --- a/engine/src/rgbalgorithm.cpp +++ b/engine/src/rgbalgorithm.cpp @@ -44,19 +44,21 @@ RGBAlgorithm::RGBAlgorithm(Doc * doc) void RGBAlgorithm::setColors(QVector colors) { + int nCols = acceptColors(); m_colors.clear(); - QVectorIterator 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]; } diff --git a/engine/test/rgbalgorithm/rgbalgorithm_test.cpp b/engine/test/rgbalgorithm/rgbalgorithm_test.cpp index d73c505d45..89d6b558b9 100644 --- a/engine/test/rgbalgorithm/rgbalgorithm_test.cpp +++ b/engine/test/rgbalgorithm/rgbalgorithm_test.cpp @@ -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 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; } diff --git a/engine/test/rgbtext/rgbtext_test.cpp b/engine/test/rgbtext/rgbtext_test.cpp index 73a09cbc40..afc1a6ae01 100644 --- a/engine/test/rgbtext/rgbtext_test.cpp +++ b/engine/test/rgbtext/rgbtext_test.cpp @@ -441,4 +441,12 @@ void RGBText_Test::verticalScroll() } } +void RGBText_Test::unused() +{ + RGBText text(m_doc); + QVector colors; + text.rgbMapSetColors(colors); + QCOMPARE(text.rgbMapGetColors().isEmpty(), true); +} + QTEST_MAIN(RGBText_Test) diff --git a/engine/test/rgbtext/rgbtext_test.h b/engine/test/rgbtext/rgbtext_test.h index c6656854e1..df66141499 100644 --- a/engine/test/rgbtext/rgbtext_test.h +++ b/engine/test/rgbtext/rgbtext_test.h @@ -42,6 +42,7 @@ private slots: void staticLetters(); void horizontalScroll(); void verticalScroll(); + void unused(); private: Doc * m_doc;