From 49684766dd0a1916b551374aaa5a37c8f4a83d9d Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Tue, 24 Aug 2021 02:25:24 +0200 Subject: tests/CMakeLists.txt: align CMake required version Following the library's CMakeLists file, it's 3.10. --- tests/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') 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. -- cgit v1.2.3 From bc217e85058fbee1ec81f45e9ffea916f0f89270 Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Tue, 28 Sep 2021 08:41:23 +0200 Subject: quotest: timelineEdge() -> historyEdge() timelineEdge() is deprecated. --- tests/quotest.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/quotest.cpp b/tests/quotest.cpp index 6ad5e8a8..fc71cbbc 100644 --- a/tests/quotest.cpp +++ b/tests/quotest.cpp @@ -549,7 +549,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()) { -- cgit v1.2.3 From c168a0a29f0a4eed2a21933749689b8fe9b0aa42 Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Mon, 4 Oct 2021 09:53:33 +0200 Subject: Add tests for prettyPrint() --- tests/quotest.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/quotest.cpp b/tests/quotest.cpp index fc71cbbc..e6cca1c6 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) @@ -779,6 +780,52 @@ TEST_IMPL(visitResources) FINISH_TEST(true); } +bool checkPrettyPrint( + std::initializer_list> tests) +{ + bool result = true; + for (const auto& [test, etalon] : tests) { + const auto is = prettyPrint(test).toStdString(); + const auto shouldBe = std::string("") + + etalon + ""; + if (is == shouldBe) + continue; + clog << is << " != " << shouldBe << endl; + result = false; + } + return result; +} + +TEST_IMPL(prettyPrintTests) +{ + const bool prettyPrintTestResult = checkPrettyPrint( + { { "https://www.matrix.org", + R"(https://www.matrix.org)" }, +// { "www.matrix.org", // Doesn't work yet +// R"(www.matrix.org)" }, + { "smb://somewhere/file", "smb://somewhere/file" }, // Disallowed scheme + { "https:/something", "https:/something" }, // Malformed URL + { "https://matrix.to/#/!roomid:example.org", + R"(https://matrix.to/#/!roomid:example.org)" }, + { "https://matrix.to/#/@user_id:example.org", + R"(https://matrix.to/#/@user_id:example.org)" }, + { "https://matrix.to/#/#roomalias:example.org", + R"(https://matrix.to/#/#roomalias:example.org)" }, + { "https://matrix.to/#/##ircroomalias:example.org", + R"(https://matrix.to/#/##ircroomalias:example.org)" }, + { "me@example.org", + R"(me@example.org)" }, + { "mailto:me@example.org", + R"(mailto:me@example.org)" }, + { "!room_id:example.org", + R"(!room_id:example.org)" }, + { "@user_id:example.org", + R"(@user_id:example.org)" }, + { "#room_alias:example.org", + R"(#room_alias:example.org)" } }); + FINISH_TEST(prettyPrintTestResult); +} + void TestManager::conclude() { // Clean up the room (best effort) -- cgit v1.2.3 From 06ecefe0645cc60ab213e5b41c9689fa6e020745 Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Tue, 5 Oct 2021 03:52:19 +0200 Subject: Quotest: return non-zero when things go really wrong ...such as stuck login or failure to join the room. Closes #496. --- tests/quotest.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/quotest.cpp b/tests/quotest.cpp index e6cca1c6..8930816e 100644 --- a/tests/quotest.cpp +++ b/tests/quotest.cpp @@ -239,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; } @@ -894,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); } -- cgit v1.2.3