From 25784d86778a8893071c09ec147bd0d75a6ca0f3 Mon Sep 17 00:00:00 2001 From: Ashod Nakashian Date: Sun, 3 Mar 2024 09:37:32 -0500 Subject: [PATCH] wsd: test: use LOK_ASSERT_STATE for more informative report Change-Id: Ibd8589e3d6a2ca226578258c3cc1b9d85cad2d2c Signed-off-by: Ashod Nakashian --- test/UnitQuarantine.cpp | 3 +-- test/UnitWOPIFailUpload.cpp | 6 ++---- test/UnitWOPIFileUrl.cpp | 9 +++------ test/UnitWOPIHttpRedirect.cpp | 6 +++--- test/UnitWOPISlow.cpp | 16 ++++++---------- test/WOPIUploadConflictCommon.hpp | 4 ++-- 6 files changed, 17 insertions(+), 27 deletions(-) diff --git a/test/UnitQuarantine.cpp b/test/UnitQuarantine.cpp index 4050122a3b..24488e0baf 100644 --- a/test/UnitQuarantine.cpp +++ b/test/UnitQuarantine.cpp @@ -173,8 +173,7 @@ public: // because only in that case there is no user input. LOK_ASSERT_MESSAGE("Expected reason to be 'Data-loss detected'", reason.starts_with("Data-loss detected")); - LOK_ASSERT_MESSAGE("Expected to be in Phase::WaitDocClose but was " + toString(_phase), - _phase == Phase::WaitDocClose); + LOK_ASSERT_STATE(_phase, Phase::WaitDocClose); _unloadingModifiedDocDetected = true; return failed(); diff --git a/test/UnitWOPIFailUpload.cpp b/test/UnitWOPIFailUpload.cpp index 4952f4bbb6..badb2d9e15 100644 --- a/test/UnitWOPIFailUpload.cpp +++ b/test/UnitWOPIFailUpload.cpp @@ -168,8 +168,7 @@ public: // because only in that case there is no user input. LOK_ASSERT_MESSAGE("Expected reason to be 'Data-loss detected'", reason.starts_with("Data-loss detected")); - LOK_ASSERT_MESSAGE("Expected to be in Phase::WaitDocClose but was " + toString(_phase), - _phase == Phase::WaitDocClose); + LOK_ASSERT_STATE(_phase, Phase::WaitDocClose); _unloadingModifiedDocDetected = true; return failed(); @@ -253,8 +252,7 @@ public: // only have one session. LOK_ASSERT_MESSAGE("Expected reason to be 'Data-loss detected'", reason.starts_with("Data-loss detected")); - LOK_ASSERT_MESSAGE("Expected to be in Phase::WaitDocClose but was " + toString(_phase), - _phase == Phase::Done); + LOK_ASSERT_STATE(_phase, Phase::Done); passTest("Data-loss detected as expected"); return failed(); diff --git a/test/UnitWOPIFileUrl.cpp b/test/UnitWOPIFileUrl.cpp index 3f50a5a891..ace7fc84e7 100644 --- a/test/UnitWOPIFileUrl.cpp +++ b/test/UnitWOPIFileUrl.cpp @@ -150,8 +150,7 @@ public: { LOG_TST("FakeWOPIHost: Handling PutFile: " << uriReq.getPath()); - LOK_ASSERT_MESSAGE("Expected to be in Phase::WaitPutFile", - _phase == Phase::WaitPutFile); + LOK_ASSERT_STATE(_phase, Phase::WaitPutFile); LOK_ASSERT_MESSAGE("Always the default URI must be used for PutFile", regContent.match(uriReq.getPath())); @@ -197,8 +196,7 @@ public: bool onDocumentLoaded(const std::string& message) override { LOG_TST("onDocumentLoaded: [" << message << ']'); - LOK_ASSERT_MESSAGE("Expected to be in Phase::WaitLoadStatus", - _phase == Phase::WaitLoadStatus); + LOK_ASSERT_STATE(_phase, Phase::WaitLoadStatus); LOG_TST( "onDocumentLoaded: Modifying the document and switching to Phase::WaitModifiedStatus"); @@ -213,8 +211,7 @@ public: bool onDocumentModified(const std::string& message) override { LOG_TST("onDocumentModified: [" << message << ']'); - LOK_ASSERT_MESSAGE("Expected to be in Phase::WaitModified", - _phase == Phase::WaitModifiedStatus); + LOK_ASSERT_STATE(_phase, Phase::WaitModifiedStatus); LOG_TST("onDocumentModified: Saving document and switching to Phase::WaitPutFile"); TRANSITION_STATE(_phase, Phase::WaitPutFile); diff --git a/test/UnitWOPIHttpRedirect.cpp b/test/UnitWOPIHttpRedirect.cpp index 86922e47ad..cd8b688f3e 100644 --- a/test/UnitWOPIHttpRedirect.cpp +++ b/test/UnitWOPIHttpRedirect.cpp @@ -56,7 +56,7 @@ public: assertCheckFileInfoRequest(request); - LOK_ASSERT_MESSAGE("Expected to be in Phase::Load", _phase == Phase::Load); + LOK_ASSERT_STATE(_phase, Phase::Load); TRANSITION_STATE(_phase, Phase::Redirected); http::Response httpResponse(http::StatusCode::Found); @@ -99,7 +99,7 @@ public: assertGetFileRequest(request); - LOK_ASSERT_MESSAGE("Expected to be in Phase::GetFile", _phase == Phase::GetFile); + LOK_ASSERT_STATE(_phase, Phase::GetFile); TRANSITION_STATE(_phase, Phase::Redirected2); http::Response httpResponse(http::StatusCode::Found); @@ -115,7 +115,7 @@ public: assertGetFileRequest(request); - LOK_ASSERT_MESSAGE("Expected to be in Phase::Redirected2", _phase == Phase::Redirected2); + LOK_ASSERT_STATE(_phase, Phase::Redirected2); TRANSITION_STATE(_phase, Phase::Done); http::Response httpResponse(http::StatusCode::OK); diff --git a/test/UnitWOPISlow.cpp b/test/UnitWOPISlow.cpp index ec288c7f02..2964989531 100644 --- a/test/UnitWOPISlow.cpp +++ b/test/UnitWOPISlow.cpp @@ -63,7 +63,7 @@ public: assertPutFileRequest(const Poco::Net::HTTPRequest& request) override { LOG_TST("PutFile"); - LOK_ASSERT_MESSAGE("Expected to be in Phase::WaitPutFile", _phase == Phase::WaitPutFile); + LOK_ASSERT_STATE(_phase, Phase::WaitPutFile); // Triggered while closing. LOK_ASSERT_EQUAL(std::string("false"), request.get("X-COOL-WOPI-IsAutosave")); @@ -83,8 +83,7 @@ public: bool onDocumentLoaded(const std::string& message) override { LOG_TST("Doc (" << toString(_phase) << "): [" << message << ']'); - LOK_ASSERT_MESSAGE("Expected to be in Phase::WaitLoadStatus", - _phase == Phase::WaitLoadStatus); + LOK_ASSERT_STATE(_phase, Phase::WaitLoadStatus); // Modify and wait for the notification. TRANSITION_STATE(_phase, Phase::WaitModifiedStatus); @@ -104,8 +103,7 @@ public: if (_phase == Phase::WaitModifiedStatus) { LOG_TST("Doc (" << toString(_phase) << "): [" << message << ']'); - LOK_ASSERT_MESSAGE("Expected to be in Phase::WaitModifiedStatus", - _phase == Phase::WaitModifiedStatus); + LOK_ASSERT_STATE(_phase, Phase::WaitModifiedStatus); // Save and immediately modify, then close the connection. WSD_CMD("save dontTerminateEdit=0 dontSaveIfUnmodified=0 " @@ -189,7 +187,7 @@ public: else { LOK_ASSERT_EQUAL(std::string("false"), request.get("X-COOL-WOPI-IsModifiedByUser")); - LOK_ASSERT_MESSAGE("Expected to be in Phase::WaitPutFile", _phase == Phase::Done); + LOK_ASSERT_STATE(_phase, Phase::Done); // LOK_ASSERT_EQUAL_MESSAGE("Expected to be in Phase::WaitPutFile", 2, _uploadCount); } @@ -200,8 +198,7 @@ public: bool onDocumentLoaded(const std::string& message) override { LOG_TST("Doc (" << toString(_phase) << "): [" << message << ']'); - LOK_ASSERT_MESSAGE("Expected to be in Phase::WaitLoadStatus", - _phase == Phase::WaitLoadStatus); + LOK_ASSERT_STATE(_phase, Phase::WaitLoadStatus); // Modify and wait for the notification. TRANSITION_STATE(_phase, Phase::WaitModifiedStatus); @@ -216,8 +213,7 @@ public: bool onDocumentModified(const std::string& message) override { LOG_TST("Doc (" << toString(_phase) << "): [" << message << ']'); - LOK_ASSERT_MESSAGE("Expected to be in Phase::WaitModifiedStatus", - _phase == Phase::WaitModifiedStatus); + LOK_ASSERT_STATE(_phase, Phase::WaitModifiedStatus); _stopwatch.restart(); diff --git a/test/WOPIUploadConflictCommon.hpp b/test/WOPIUploadConflictCommon.hpp index 2b2cbd8bc0..becc7140cb 100644 --- a/test/WOPIUploadConflictCommon.hpp +++ b/test/WOPIUploadConflictCommon.hpp @@ -272,8 +272,8 @@ public: // because only in that case there is no user input. LOK_ASSERT_MESSAGE("Expected reason to be 'Data-loss detected'", reason.starts_with("Data-loss detected")); - LOK_ASSERT_MESSAGE("Expected to be in Phase::WaitDocClose but was " + toString(_phase), - _phase == Phase::WaitDocClose); + LOK_ASSERT_STATE(_phase, Phase::WaitDocClose); + // In SaveOverwrite, we should not be in modified state, because we do save // and upload. But because we don't wait for the modified=false, we can end-up // here. Since we will verify after reloading that we have no data-loss, it's OK.