testutility.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. This software is in the public domain, furnished "as is", without technical
  3. support, and with no warranty, express or implied, as to its usefulness for
  4. any purpose.
  5. */
  6. #ifndef MIRALL_TESTUTILITY_H
  7. #define MIRALL_TESTUTILITY_H
  8. #include <QtTest>
  9. #include "utility.h"
  10. using namespace OCC::Utility;
  11. class TestUtility : public QObject
  12. {
  13. Q_OBJECT
  14. private slots:
  15. void testFormatFingerprint()
  16. {
  17. QVERIFY2(formatFingerprint("68ac906495480a3404beee4874ed853a037a7a8f")
  18. == "68:ac:90:64:95:48:0a:34:04:be:ee:48:74:ed:85:3a:03:7a:7a:8f",
  19. "Utility::formatFingerprint() is broken");
  20. }
  21. void testOctetsToString()
  22. {
  23. QLocale::setDefault(QLocale("en"));
  24. QCOMPARE(octetsToString(999) , QString("999 B"));
  25. QCOMPARE(octetsToString(1000) , QString("1,000 B"));
  26. QCOMPARE(octetsToString(1010) , QString("1,010 B"));
  27. QCOMPARE(octetsToString(1024) , QString("1 kB"));
  28. QCOMPARE(octetsToString(1110) , QString("1.1 kB"));
  29. QCOMPARE(octetsToString(9110) , QString("8.9 kB"));
  30. QCOMPARE(octetsToString(9910) , QString("9.7 kB"));
  31. QCOMPARE(octetsToString(9999) , QString("9.8 kB"));
  32. QCOMPARE(octetsToString(10240) , QString("10 kB"));
  33. QCOMPARE(octetsToString(123456) , QString("121 kB"));
  34. QCOMPARE(octetsToString(1234567) , QString("1.2 MB"));
  35. QCOMPARE(octetsToString(12345678) , QString("12 MB"));
  36. QCOMPARE(octetsToString(123456789) , QString("118 MB"));
  37. QCOMPARE(octetsToString(1000LL*1000*1000 * 5) , QString("4.7 GB"));
  38. QCOMPARE(octetsToString(1024LL*1024*1024 * 5) , QString("5 GB"));
  39. QCOMPARE(octetsToString(1), QString("1 B"));
  40. QCOMPARE(octetsToString(2), QString("2 B"));
  41. QCOMPARE(octetsToString(1024), QString("1 kB"));
  42. QCOMPARE(octetsToString(1024*1024), QString("1 MB"));
  43. QCOMPARE(octetsToString(1024LL*1024*1024), QString("1 GB"));
  44. QCOMPARE(octetsToString(1024LL*1024*1024*1024), QString("1 TB"));
  45. }
  46. void testLaunchOnStartup()
  47. {
  48. qsrand(QDateTime::currentDateTime().toTime_t());
  49. QString postfix = QString::number(qrand());
  50. const QString appName = QString::fromLatin1("testLaunchOnStartup.%1").arg(postfix);
  51. const QString guiName = "LaunchOnStartup GUI Name";
  52. QVERIFY(hasLaunchOnStartup(appName) == false);
  53. setLaunchOnStartup(appName, guiName, true);
  54. QVERIFY(hasLaunchOnStartup(appName) == true);
  55. setLaunchOnStartup(appName, guiName, false);
  56. QVERIFY(hasLaunchOnStartup(appName) == false);
  57. }
  58. void testToCSyncScheme()
  59. {
  60. QVERIFY(toCSyncScheme("http://example.com/owncloud/") ==
  61. "owncloud://example.com/owncloud/");
  62. QVERIFY(toCSyncScheme("https://example.com/owncloud/") ==
  63. "ownclouds://example.com/owncloud/");
  64. }
  65. };
  66. #endif