testiconutils.cpp 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. if (!blackImages.isEmpty()) {
  33. QVERIFY(!OCC::Ui::IconUtils::drawSvgWithCustomFillColor(blackSvgDirPath + QLatin1Char('/') + blackImages.at(0), QColorConstants::Svg::red).isNull());
  34. }
  35. if (!blackImages.isEmpty()) {
  36. QVERIFY(!OCC::Ui::IconUtils::drawSvgWithCustomFillColor(blackSvgDirPath + QLatin1Char('/') + blackImages.at(0), QColorConstants::Svg::green).isNull());
  37. }
  38. const QString whiteSvgDirPath{QString{OCC::Theme::themePrefix} + QStringLiteral("white")};
  39. const QDir whiteSvgDir(whiteSvgDirPath);
  40. const QStringList whiteImages = whiteSvgDir.entryList(QStringList("*.svg"));
  41. if (!whiteImages.isEmpty()) {
  42. QVERIFY(!OCC::Ui::IconUtils::drawSvgWithCustomFillColor(whiteSvgDirPath + QLatin1Char('/') + whiteImages.at(0), QColorConstants::Svg::blue).isNull());
  43. }
  44. }
  45. void testCreateSvgPixmapWithCustomColor()
  46. {
  47. const QDir blackSvgDir(QString(QString{OCC::Theme::themePrefix}) + QStringLiteral("black"));
  48. const QStringList blackImages = blackSvgDir.entryList(QStringList("*.svg"));
  49. if (!blackImages.isEmpty()) {
  50. QVERIFY(!OCC::Ui::IconUtils::createSvgPixmapWithCustomColor(blackImages.at(0), QColorConstants::Svg::red).isNull());
  51. }
  52. if (!blackImages.isEmpty()) {
  53. QVERIFY(!OCC::Ui::IconUtils::createSvgPixmapWithCustomColor(blackImages.at(0), QColorConstants::Svg::green).isNull());
  54. }
  55. const QDir whiteSvgDir(QString(QString{OCC::Theme::themePrefix}) + QStringLiteral("white"));
  56. const QStringList whiteImages = whiteSvgDir.entryList(QStringList("*.svg"));
  57. if (!whiteImages.isEmpty()) {
  58. QVERIFY(!OCC::Ui::IconUtils::createSvgPixmapWithCustomColor(whiteImages.at(0), QColorConstants::Svg::blue).isNull());
  59. }
  60. }
  61. void testPixmapForBackground()
  62. {
  63. const QDir blackSvgDir(QString(QString{OCC::Theme::themePrefix}) + QStringLiteral("black"));
  64. const QStringList blackImages = blackSvgDir.entryList(QStringList("*.svg"));
  65. const QDir whiteSvgDir(QString(QString{OCC::Theme::themePrefix}) + QStringLiteral("white"));
  66. const QStringList whiteImages = whiteSvgDir.entryList(QStringList("*.svg"));
  67. if (blackImages.size() > 0) {
  68. // white pixmap for dark background - should not fail
  69. QVERIFY(!OCC::Ui::IconUtils::pixmapForBackground(whiteImages.at(0), QColor("blue")).isNull());
  70. }
  71. if (whiteImages.size() > 0) {
  72. // black pixmap for bright background - should not fail
  73. QVERIFY(!OCC::Ui::IconUtils::pixmapForBackground(blackImages.at(0), QColor("yellow")).isNull());
  74. }
  75. }
  76. };
  77. QTEST_MAIN(TestIconUtils)
  78. #include "testiconutils.moc"