testnextcloudpropagator.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. #include <QtTest>
  7. #include <QDebug>
  8. #include "propagatedownload.h"
  9. #include "owncloudpropagator_p.h"
  10. using namespace OCC;
  11. namespace OCC {
  12. QString OWNCLOUDSYNC_EXPORT createDownloadTmpFileName(const QString &previous);
  13. }
  14. class TestNextcloudPropagator : public QObject
  15. {
  16. Q_OBJECT
  17. private slots:
  18. void testUpdateErrorFromSession()
  19. {
  20. //OwncloudPropagator propagator(nullptr, QLatin1String("test1"), QLatin1String("test2"), new ProgressDatabase);
  21. QVERIFY( true );
  22. }
  23. void testTmpDownloadFileNameGeneration()
  24. {
  25. QString fn;
  26. // without dir
  27. for (int i = 1; i <= 1000; i++) {
  28. fn+="F";
  29. QString tmpFileName = createDownloadTmpFileName(fn);
  30. if (tmpFileName.contains('/')) {
  31. tmpFileName = tmpFileName.mid(tmpFileName.lastIndexOf('/')+1);
  32. }
  33. QVERIFY( tmpFileName.length() > 0);
  34. QVERIFY( tmpFileName.length() <= 254);
  35. }
  36. // with absolute dir
  37. fn = "/Users/guruz/ownCloud/rocks/GPL";
  38. for (int i = 1; i < 1000; i++) {
  39. fn+="F";
  40. QString tmpFileName = createDownloadTmpFileName(fn);
  41. if (tmpFileName.contains('/')) {
  42. tmpFileName = tmpFileName.mid(tmpFileName.lastIndexOf('/')+1);
  43. }
  44. QVERIFY( tmpFileName.length() > 0);
  45. QVERIFY( tmpFileName.length() <= 254);
  46. }
  47. // with relative dir
  48. fn = "rocks/GPL";
  49. for (int i = 1; i < 1000; i++) {
  50. fn+="F";
  51. QString tmpFileName = createDownloadTmpFileName(fn);
  52. if (tmpFileName.contains('/')) {
  53. tmpFileName = tmpFileName.mid(tmpFileName.lastIndexOf('/')+1);
  54. }
  55. QVERIFY( tmpFileName.length() > 0);
  56. QVERIFY( tmpFileName.length() <= 254);
  57. }
  58. }
  59. void testParseEtag()
  60. {
  61. using Test = QPair<const char*, const char*>;
  62. QList<Test> tests;
  63. tests.append(Test("\"abcd\"", "abcd"));
  64. tests.append(Test("\"\"", ""));
  65. tests.append(Test("\"fii\"-gzip", "fii"));
  66. tests.append(Test("W/\"foo\"", "foo"));
  67. foreach (const auto& test, tests) {
  68. QCOMPARE(parseEtag(test.first), QByteArray(test.second));
  69. }
  70. }
  71. };
  72. QTEST_APPLESS_MAIN(TestNextcloudPropagator)
  73. #include "testnextcloudpropagator.moc"