aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorHubert Chathi <uhoreg@debian.org>2021-10-16 00:03:36 -0400
committerHubert Chathi <uhoreg@debian.org>2021-10-16 00:03:36 -0400
commit5a8c406749160a01865cbac8b4591a8e3c31e4c6 (patch)
tree0bafb35b381954589f90fccfa3e5ff34e871c494 /tests
parenteb2f105aea98f640e2f95854983bb06ade95bb3e (diff)
parent0a342369406e2d259ce20e5fa6d53ac271cbf3c2 (diff)
downloadlibquotient-5a8c406749160a01865cbac8b4591a8e3c31e4c6.tar.gz
libquotient-5a8c406749160a01865cbac8b4591a8e3c31e4c6.zip
Update to upstream version 0.6.11
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt2
-rw-r--r--tests/quotest.cpp69
2 files changed, 65 insertions, 6 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index cb8c99f8..46f6adfd 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -1,4 +1,4 @@
-cmake_minimum_required(VERSION 3.1)
+cmake_minimum_required(VERSION 3.10)
# This CMakeLists file assumes that the library is installed to CMAKE_INSTALL_PREFIX
# and ignores the in-tree library code. You can use this to start work on your own client.
diff --git a/tests/quotest.cpp b/tests/quotest.cpp
index 6ad5e8a8..8930816e 100644
--- a/tests/quotest.cpp
+++ b/tests/quotest.cpp
@@ -102,6 +102,7 @@ private slots:
TEST_DECL(addAndRemoveTag)
TEST_DECL(markDirectChat)
TEST_DECL(visitResources)
+ TEST_DECL(prettyPrintTests)
// Add more tests above here
public:
@@ -134,7 +135,7 @@ private:
// connectUntil() to break the QMetaObject::Connection upon finishing the test
// item.
#define FINISH_TEST(Condition) \
- return (finishTest(thisTest, Condition, __FILE__, __LINE__), true)
+ return (finishTest(thisTest, (Condition), __FILE__, __LINE__), true)
#define FAIL_TEST() FINISH_TEST(false)
@@ -238,7 +239,7 @@ void TestManager::setupAndRun()
clog << "Sync " << ++i << " complete" << endl;
if (auto* r = testSuite->room()) {
clog << "Test room timeline size = " << r->timelineSize();
- if (r->pendingEvents().empty())
+ if (!r->pendingEvents().empty())
clog << ", pending size = " << r->pendingEvents().size();
clog << endl;
}
@@ -549,7 +550,7 @@ bool TestSuite::checkRedactionOutcome(const QByteArray& thisTest,
// redacted at the next sync, or the nearest sync completes with
// the unredacted event but the next one brings redaction.
auto it = targetRoom->findInTimeline(evtIdToRedact);
- if (it == targetRoom->timelineEdge())
+ if (it == targetRoom->historyEdge())
return false; // Waiting for the next sync
if ((*it)->isRedacted()) {
@@ -779,6 +780,52 @@ TEST_IMPL(visitResources)
FINISH_TEST(true);
}
+bool checkPrettyPrint(
+ std::initializer_list<std::pair<const char*, const char*>> tests)
+{
+ bool result = true;
+ for (const auto& [test, etalon] : tests) {
+ const auto is = prettyPrint(test).toStdString();
+ const auto shouldBe = std::string("<span style='white-space:pre-wrap'>")
+ + etalon + "</span>";
+ if (is == shouldBe)
+ continue;
+ clog << is << " != " << shouldBe << endl;
+ result = false;
+ }
+ return result;
+}
+
+TEST_IMPL(prettyPrintTests)
+{
+ const bool prettyPrintTestResult = checkPrettyPrint(
+ { { "https://www.matrix.org",
+ R"(<a href="https://www.matrix.org">https://www.matrix.org</a>)" },
+// { "www.matrix.org", // Doesn't work yet
+// R"(<a href="https://www.matrix.org">www.matrix.org</a>)" },
+ { "smb://somewhere/file", "smb://somewhere/file" }, // Disallowed scheme
+ { "https:/something", "https:/something" }, // Malformed URL
+ { "https://matrix.to/#/!roomid:example.org",
+ R"(<a href="https://matrix.to/#/!roomid:example.org">https://matrix.to/#/!roomid:example.org</a>)" },
+ { "https://matrix.to/#/@user_id:example.org",
+ R"(<a href="https://matrix.to/#/@user_id:example.org">https://matrix.to/#/@user_id:example.org</a>)" },
+ { "https://matrix.to/#/#roomalias:example.org",
+ R"(<a href="https://matrix.to/#/#roomalias:example.org">https://matrix.to/#/#roomalias:example.org</a>)" },
+ { "https://matrix.to/#/##ircroomalias:example.org",
+ R"(<a href="https://matrix.to/#/##ircroomalias:example.org">https://matrix.to/#/##ircroomalias:example.org</a>)" },
+ { "me@example.org",
+ R"(<a href="mailto:me@example.org">me@example.org</a>)" },
+ { "mailto:me@example.org",
+ R"(<a href="mailto:me@example.org">mailto:me@example.org</a>)" },
+ { "!room_id:example.org",
+ R"(<a href="https://matrix.to/#/!room_id:example.org">!room_id:example.org</a>)" },
+ { "@user_id:example.org",
+ R"(<a href="https://matrix.to/#/@user_id:example.org">@user_id:example.org</a>)" },
+ { "#room_alias:example.org",
+ R"(<a href="https://matrix.to/#/#room_alias:example.org">#room_alias:example.org</a>)" } });
+ FINISH_TEST(prettyPrintTestResult);
+}
+
void TestManager::conclude()
{
// Clean up the room (best effort)
@@ -847,10 +894,22 @@ void TestManager::conclude()
void TestManager::finalize()
{
+ if (!c->isUsable() || !c->isLoggedIn()) {
+ clog << "No usable connection reached" << endl;
+ QCoreApplication::exit(-2);
+ return; // NB: QCoreApplication::exit() does return to the caller
+ }
clog << "Logging out" << endl;
c->logout();
- connect(c, &Connection::loggedOut, this,
- [this] { QCoreApplication::exit(failed.size() + running.size()); },
+ connect(
+ c, &Connection::loggedOut, this,
+ [this] {
+ QCoreApplication::exit(!testSuite ? -3
+ : succeeded.empty() && failed.empty()
+ && running.empty()
+ ? -4
+ : failed.size() + running.size());
+ },
Qt::QueuedConnection);
}