testiconutils.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 testPixmapForBackground()
  28. {
  29. const QDir blackSvgDir(QString(OCC::Theme::themePrefix) + QStringLiteral("black"));
  30. const QStringList blackImages = blackSvgDir.entryList(QStringList("*.svg"));
  31. const QDir whiteSvgDir(QString(OCC::Theme::themePrefix) + QStringLiteral("white"));
  32. const QStringList whiteImages = whiteSvgDir.entryList(QStringList("*.svg"));
  33. if (blackImages.size() > 0) {
  34. // white pixmap for dark background - should not fail
  35. QVERIFY(!OCC::Ui::IconUtils::pixmapForBackground(whiteImages.at(0), QColor("blue")).isNull());
  36. }
  37. if (whiteImages.size() > 0) {
  38. // black pixmap for bright background - should not fail
  39. QVERIFY(!OCC::Ui::IconUtils::pixmapForBackground(blackImages.at(0), QColor("yellow")).isNull());
  40. }
  41. const auto blackImagesExclusive = QSet<QString>(blackImages.begin(), blackImages.end()).subtract(QSet<QString>(whiteImages.begin(), whiteImages.end()));
  42. const auto whiteImagesExclusive = QSet<QString>(whiteImages.begin(), whiteImages.end()).subtract(QSet<QString>(blackImages.begin(), blackImages.end()));
  43. if (blackImagesExclusive != whiteImagesExclusive) {
  44. // black pixmap for dark background - should fail as we don't have this image in black
  45. QVERIFY(OCC::Ui::IconUtils::pixmapForBackground(blackImagesExclusive.values().at(0), QColor("blue")).isNull());
  46. // white pixmap for bright background - should fail as we don't have this image in white
  47. QVERIFY(OCC::Ui::IconUtils::pixmapForBackground(whiteImagesExclusive.values().at(0), QColor("yellow")).isNull());
  48. }
  49. }
  50. };
  51. QTEST_MAIN(TestIconUtils)
  52. #include "testiconutils.moc"