testconcaturl.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. */
  7. #ifndef MIRALL_TESTCONCATURL_H
  8. #define MIRALL_TESTCONCATURL_H
  9. #include <QtTest>
  10. #include <QUrl>
  11. #include <QString>
  12. #include "account.h"
  13. using namespace OCC;
  14. typedef QList< QPair<QString,QString> > QueryItems;
  15. Q_DECLARE_METATYPE(QueryItems)
  16. static QueryItems make()
  17. {
  18. return QueryItems();
  19. }
  20. static QueryItems make(QString key, QString value)
  21. {
  22. QueryItems q;
  23. q.append(qMakePair(key, value));
  24. return q;
  25. }
  26. static QueryItems make(QString key1, QString value1,
  27. QString key2, QString value2)
  28. {
  29. QueryItems q;
  30. q.append(qMakePair(key1, value1));
  31. q.append(qMakePair(key2, value2));
  32. return q;
  33. }
  34. class TestConcatUrl: public QObject
  35. {
  36. Q_OBJECT
  37. private slots:
  38. void testFolder()
  39. {
  40. QFETCH(QString, base);
  41. QFETCH(QString, concat);
  42. QFETCH(QueryItems, query);
  43. QFETCH(QString, expected);
  44. QUrl baseUrl("http://example.com" + base);
  45. QUrl resultUrl = Account::concatUrlPath(baseUrl, concat, query);
  46. QString result = QString::fromUtf8(resultUrl.toEncoded());
  47. QString expectedFull = "http://example.com" + expected;
  48. QCOMPARE(result, expectedFull);
  49. }
  50. void testFolder_data()
  51. {
  52. QTest::addColumn<QString>("base");
  53. QTest::addColumn<QString>("concat");
  54. QTest::addColumn<QueryItems>("query");
  55. QTest::addColumn<QString>("expected");
  56. // Tests about slashes
  57. QTest::newRow("noslash1") << "/baa" << "foo" << make() << "/baa/foo";
  58. QTest::newRow("noslash2") << "" << "foo" << make() << "/foo";
  59. QTest::newRow("noslash3") << "/foo" << "" << make() << "/foo";
  60. QTest::newRow("noslash4") << "" << "" << make() << "";
  61. QTest::newRow("oneslash1") << "/bar/" << "foo" << make() << "/bar/foo";
  62. QTest::newRow("oneslash2") << "/" << "foo" << make() << "/foo";
  63. QTest::newRow("oneslash3") << "/foo" << "/" << make() << "/foo/";
  64. QTest::newRow("oneslash4") << "" << "/" << make() << "/";
  65. QTest::newRow("twoslash1") << "/bar/" << "/foo" << make() << "/bar/foo";
  66. QTest::newRow("twoslash2") << "/" << "/foo" << make() << "/foo";
  67. QTest::newRow("twoslash3") << "/foo/" << "/" << make() << "/foo/";
  68. QTest::newRow("twoslash4") << "/" << "/" << make() << "/";
  69. // Tests about path encoding
  70. QTest::newRow("encodepath")
  71. << "/a f/b"
  72. << "/a f/c"
  73. << make()
  74. << "/a%20f/b/a%20f/c";
  75. // Tests about query args
  76. QTest::newRow("query1")
  77. << "/baa"
  78. << "/foo"
  79. << make("a=a", "b=b",
  80. "c", "d")
  81. << "/baa/foo?a%3Da=b%3Db&c=d";
  82. QTest::newRow("query2")
  83. << ""
  84. << ""
  85. << make("foo", "bar")
  86. << "?foo=bar";
  87. }
  88. };
  89. #endif