testtheme.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * Copyright (C) 2021 by Felix Weilbach <felix.weilbach@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 "themeutils.h"
  17. #include "iconutils.h"
  18. class TestTheme : public QObject
  19. {
  20. Q_OBJECT
  21. public:
  22. TestTheme()
  23. {
  24. Q_INIT_RESOURCE(resources);
  25. Q_INIT_RESOURCE(theme);
  26. }
  27. private slots:
  28. void testHidpiFileName_darkBackground_returnPathToWhiteIcon()
  29. {
  30. FakePaintDevice paintDevice;
  31. const QColor backgroundColor("#000000");
  32. const QString iconName("icon-name");
  33. const auto iconPath = OCC::Theme::hidpiFileName(iconName + ".png", backgroundColor, &paintDevice);
  34. QCOMPARE(iconPath, ":/client/theme/white/" + iconName + ".png");
  35. }
  36. void testHidpiFileName_lightBackground_returnPathToBlackIcon()
  37. {
  38. FakePaintDevice paintDevice;
  39. const QColor backgroundColor("#ffffff");
  40. const QString iconName("icon-name");
  41. const auto iconPath = OCC::Theme::hidpiFileName(iconName + ".png", backgroundColor, &paintDevice);
  42. QCOMPARE(iconPath, ":/client/theme/black/" + iconName + ".png");
  43. }
  44. void testHidpiFileName_hidpiDevice_returnHidpiIconPath()
  45. {
  46. FakePaintDevice paintDevice;
  47. paintDevice.setHidpi(true);
  48. const QColor backgroundColor("#000000");
  49. const QString iconName("wizard-files");
  50. const auto iconPath = OCC::Theme::hidpiFileName(iconName + ".png", backgroundColor, &paintDevice);
  51. QCOMPARE(iconPath, ":/client/theme/white/" + iconName + "@2x.png");
  52. }
  53. void testIsDarkColor_nextcloudBlue_returnTrue()
  54. {
  55. const QColor color(0, 130, 201);
  56. const auto result = OCC::Theme::isDarkColor(color);
  57. QCOMPARE(result, true);
  58. }
  59. void testIsDarkColor_lightColor_returnFalse()
  60. {
  61. const QColor color(255, 255, 255);
  62. const auto result = OCC::Theme::isDarkColor(color);
  63. QCOMPARE(result, false);
  64. }
  65. void testIsDarkColor_darkColor_returnTrue()
  66. {
  67. const QColor color(0, 0, 0);
  68. const auto result = OCC::Theme::isDarkColor(color);
  69. QCOMPARE(result, true);
  70. }
  71. void testIsHidpi_hidpi_returnTrue()
  72. {
  73. FakePaintDevice paintDevice;
  74. paintDevice.setHidpi(true);
  75. QCOMPARE(OCC::Theme::isHidpi(&paintDevice), true);
  76. }
  77. void testIsHidpi_lowdpi_returnFalse()
  78. {
  79. FakePaintDevice paintDevice;
  80. paintDevice.setHidpi(false);
  81. QCOMPARE(OCC::Theme::isHidpi(&paintDevice), false);
  82. }
  83. };
  84. QTEST_GUILESS_MAIN(TestTheme)
  85. #include "testtheme.moc"