testiconutils.cpp 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright (C) by Oleksandr Zolotov <alex@nextcloud.com>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  11. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. * for more details.
  13. */
  14. #include <QTest>
  15. #include "theme.h"
  16. #include "iconutils.h"
  17. class TestIconUtils : public QObject
  18. {
  19. Q_OBJECT
  20. public:
  21. TestIconUtils()
  22. {
  23. Q_INIT_RESOURCE(resources);
  24. Q_INIT_RESOURCE(theme);
  25. }
  26. private slots:
  27. void testDrawSvgWithCustomFillColor()
  28. {
  29. const QString blackSvgDirPath{QString{OCC::Theme::themePrefix} + QStringLiteral("black")};
  30. const QDir blackSvgDir(blackSvgDirPath);
  31. const QStringList blackImages = blackSvgDir.entryList(QStringList("*.svg"));
  32. Q_ASSERT(!blackImages.isEmpty());
  33. QVERIFY(!OCC::Ui::IconUtils::drawSvgWithCustomFillColor(blackSvgDirPath + QStringLiteral("/") + blackImages.at(0), QColorConstants::Svg::red).isNull());
  34. QVERIFY(!OCC::Ui::IconUtils::drawSvgWithCustomFillColor(blackSvgDirPath + QStringLiteral("/") + blackImages.at(0), QColorConstants::Svg::green).isNull());
  35. const QString whiteSvgDirPath{QString{OCC::Theme::themePrefix} + QStringLiteral("white")};
  36. const QDir whiteSvgDir(whiteSvgDirPath);
  37. const QStringList whiteImages = whiteSvgDir.entryList(QStringList("*.svg"));
  38. Q_ASSERT(!whiteImages.isEmpty());
  39. QVERIFY(!OCC::Ui::IconUtils::drawSvgWithCustomFillColor(whiteSvgDirPath + QStringLiteral("/") + whiteImages.at(0), QColorConstants::Svg::blue).isNull());
  40. }
  41. void testCreateSvgPixmapWithCustomColor()
  42. {
  43. const QDir blackSvgDir(QString(QString{OCC::Theme::themePrefix}) + QStringLiteral("black"));
  44. const QStringList blackImages = blackSvgDir.entryList(QStringList("*.svg"));
  45. QVERIFY(!blackImages.isEmpty());
  46. QVERIFY(!OCC::Ui::IconUtils::createSvgImageWithCustomColor(blackImages.at(0), QColorConstants::Svg::red).isNull());
  47. QVERIFY(!OCC::Ui::IconUtils::createSvgImageWithCustomColor(blackImages.at(0), QColorConstants::Svg::green).isNull());
  48. const QDir whiteSvgDir(QString(QString{OCC::Theme::themePrefix}) + QStringLiteral("white"));
  49. const QStringList whiteImages = whiteSvgDir.entryList(QStringList("*.svg"));
  50. QVERIFY(!whiteImages.isEmpty());
  51. QVERIFY(!OCC::Ui::IconUtils::createSvgImageWithCustomColor(whiteImages.at(0), QColorConstants::Svg::blue).isNull());
  52. }
  53. void testPixmapForBackground()
  54. {
  55. const QDir blackSvgDir(QString(QString{OCC::Theme::themePrefix}) + QStringLiteral("black"));
  56. const QStringList blackImages = blackSvgDir.entryList(QStringList("*.svg"));
  57. const QDir whiteSvgDir(QString(QString{OCC::Theme::themePrefix}) + QStringLiteral("white"));
  58. const QStringList whiteImages = whiteSvgDir.entryList(QStringList("*.svg"));
  59. QVERIFY(!blackImages.isEmpty());
  60. QVERIFY(!OCC::Ui::IconUtils::pixmapForBackground(whiteImages.at(0), QColor("blue")).isNull());
  61. QVERIFY(!whiteImages.isEmpty());
  62. QVERIFY(!OCC::Ui::IconUtils::pixmapForBackground(blackImages.at(0), QColor("yellow")).isNull());
  63. }
  64. };
  65. QTEST_MAIN(TestIconUtils)
  66. #include "testiconutils.moc"