testutility.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 "mirall/utility.h"
  10. using namespace Mirall::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. QCOMPARE(octetsToString(999) , QString("999 B"));
  24. QCOMPARE(octetsToString(1000) , QString("1 kB"));
  25. QCOMPARE(octetsToString(1010) , QString("1 kB"));
  26. QCOMPARE(octetsToString(1110) , QString("1.1 kB"));
  27. QCOMPARE(octetsToString(9110) , QString("9.1 kB"));
  28. QCOMPARE(octetsToString(9910) , QString("9.9 kB"));
  29. QCOMPARE(octetsToString(9999) , QString("10 kB"));
  30. QCOMPARE(octetsToString(123456) , QString("123 kB"));
  31. QCOMPARE(octetsToString(1234567) , QString("1.2 MB"));
  32. QCOMPARE(octetsToString(12345678) , QString("12 MB"));
  33. QCOMPARE(octetsToString(123456789) , QString("123 MB"));
  34. QCOMPARE(octetsToString(1000LL*1000*1000 * 5) , QString("5 GB"));
  35. QVERIFY(octetsToString(1) == "1 B");
  36. QVERIFY(octetsToString(2) == "2 B");
  37. QVERIFY(octetsToString(1024) == "1 kB");
  38. QVERIFY(octetsToString(1024*1024) == "1 MB");
  39. QVERIFY(octetsToString(1024LL*1024*1024) == "1.1 GB");
  40. QVERIFY(octetsToString(1024LL*1024*1024*1024) == "1.1 TB");
  41. }
  42. void testLaunchOnStartup()
  43. {
  44. const QString appName = "testLaunchOnStartup";
  45. const QString guiName = "LaunchOnStartup GUI Name";
  46. QVERIFY(hasLaunchOnStartup(appName) == false);
  47. setLaunchOnStartup(appName, guiName, true);
  48. QVERIFY(hasLaunchOnStartup(appName) == true);
  49. setLaunchOnStartup(appName, guiName, false);
  50. QVERIFY(hasLaunchOnStartup(appName) == false);
  51. }
  52. void testToCSyncScheme()
  53. {
  54. QVERIFY(toCSyncScheme("http://example.com/owncloud/") ==
  55. "owncloud://example.com/owncloud/");
  56. QVERIFY(toCSyncScheme("https://example.com/owncloud/") ==
  57. "ownclouds://example.com/owncloud/");
  58. }
  59. };
  60. #endif