testconcaturl.cpp 3.1 KB

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