| 208 | } |
| 209 | |
| 210 | void TestPath::testPath() |
| 211 | { |
| 212 | QFETCH(QString, input); |
| 213 | |
| 214 | QUrl url = QUrl::fromUserInput(input); |
| 215 | url = url.adjusted(QUrl::StripTrailingSlash | QUrl::NormalizePathSegments); |
| 216 | |
| 217 | Path optUrl(input); |
| 218 | |
| 219 | if (!url.password().isEmpty()) { |
| 220 | QUrl urlNoPass = url.adjusted(QUrl::RemovePassword); |
| 221 | QCOMPARE(optUrl.toUrl(), urlNoPass); |
| 222 | } else { |
| 223 | QCOMPARE(optUrl.toUrl(), url); |
| 224 | } |
| 225 | QCOMPARE(optUrl.isLocalFile(), url.isLocalFile()); |
| 226 | QCOMPARE(optUrl.pathOrUrl(), url.toDisplayString(QUrl::PreferLocalFile)); |
| 227 | QCOMPARE(optUrl.isValid(), url.isValid()); |
| 228 | QCOMPARE(optUrl.isEmpty(), url.isEmpty()); |
| 229 | QCOMPARE(optUrl.lastPathSegment(), url.fileName()); |
| 230 | QCOMPARE(optUrl.path(), url.isLocalFile() ? url.toLocalFile() : url.path()); |
| 231 | QCOMPARE(optUrl.parent().toUrl(), comparableUpUrl(url)); |
| 232 | QCOMPARE(optUrl.toLocalFile(), url.toLocalFile()); |
| 233 | |
| 234 | QCOMPARE(optUrl, Path(input)); |
| 235 | QCOMPARE(optUrl, Path(optUrl)); |
| 236 | QVERIFY(optUrl != Path(input + "/asdf")); |
| 237 | |
| 238 | if (url.isLocalFile() && !input.startsWith(QLatin1String("file://"))) { |
| 239 | QCOMPARE(optUrl, Path(QUrl::fromLocalFile(input))); |
| 240 | } |
| 241 | |
| 242 | QCOMPARE(optUrl, Path(url)); |
| 243 | |
| 244 | if (url.isValid()) { |
| 245 | QVERIFY(optUrl.relativePath(optUrl).isEmpty()); |
| 246 | |
| 247 | Path relativePath(optUrl, QStringLiteral("foo/bar")); |
| 248 | QCOMPARE(optUrl.relativePath(relativePath), QLatin1String("foo/bar")); |
| 249 | QCOMPARE(relativePath.relativePath(optUrl), QLatin1String("../../")); |
| 250 | QVERIFY(optUrl.isParentOf(relativePath)); |
| 251 | QVERIFY(!relativePath.isParentOf(optUrl)); |
| 252 | |
| 253 | #ifndef Q_OS_WIN |
| 254 | Path absolutePath(optUrl, QStringLiteral("/laa/loo")); |
| 255 | QCOMPARE(absolutePath.path(), QLatin1String("/laa/loo")); |
| 256 | QCOMPARE(url.resolved(QUrl(QStringLiteral("/laa/loo"))).path(), QLatin1String("/laa/loo")); |
| 257 | |
| 258 | Path absolutePath2(optUrl, QStringLiteral("/")); |
| 259 | QCOMPARE(absolutePath2.path(), QLatin1String("/")); |
| 260 | QCOMPARE(url.resolved(QUrl(QStringLiteral("/"))).path(), QLatin1String("/")); |
| 261 | #endif |
| 262 | |
| 263 | Path unrelatedPath(QStringLiteral("https://test@blubasdf.com:12345/")); |
| 264 | QCOMPARE(optUrl.relativePath(unrelatedPath), unrelatedPath.pathOrUrl()); |
| 265 | QCOMPARE(unrelatedPath.relativePath(optUrl), optUrl.pathOrUrl()); |
| 266 | QVERIFY(!unrelatedPath.isParentOf(optUrl)); |
| 267 | QVERIFY(!optUrl.isParentOf(unrelatedPath)); |
nothing calls this directly
no test coverage detected