From 1896baa539f784cd8952abc837609a16c5c354dc Mon Sep 17 00:00:00 2001 From: Ashod Nakashian Date: Sun, 3 Mar 2024 09:07:36 -0500 Subject: [PATCH] wsd: test: use STATE_ENUM in tests Change-Id: Ie37bfdb7aba986dc17c1ebaac80d9b1b662a5df6 Signed-off-by: Ashod Nakashian --- test/UnitWOPIFileUrl.cpp | 21 +++++++-------------- test/UnitWOPIHttpRedirect.cpp | 2 +- test/UnitWOPITemplate.cpp | 14 ++++---------- wsd/COOLWSD.cpp | 2 +- 4 files changed, 13 insertions(+), 26 deletions(-) diff --git a/test/UnitWOPIFileUrl.cpp b/test/UnitWOPIFileUrl.cpp index 82b51aded9..3f50a5a891 100644 --- a/test/UnitWOPIFileUrl.cpp +++ b/test/UnitWOPIFileUrl.cpp @@ -42,14 +42,7 @@ class UnitWOPIFileUrl : public WopiTestServer /// then save. Validations are done during /// GetFile and PutFile to check that FileUrl /// is used, or not, as expected. - enum class Phase - { - Load, - WaitLoadStatus, - WaitModifiedStatus, - WaitPutFile, - Polling - } _phase; + STATE_ENUM(Phase, Load, WaitLoadStatus, WaitModifiedStatus, WaitPutFile, Polling) _phase; /// We have three tests, one for each /// of the following cases of FileUrl: @@ -180,18 +173,18 @@ public: { LOG_TST("Valid FileUrl test successful. Now testing Invalid FileUrl."); _fileUrlState = FileUrlState::Invalid; - _phase = Phase::Load; + TRANSITION_STATE(_phase, Phase::Load); } else if (_fileUrlState == FileUrlState::Invalid) { LOG_TST("Invalid FileUrl test successful. Now testing without FileUrl."); _fileUrlState = FileUrlState::Absent; - _phase = Phase::Load; + TRANSITION_STATE(_phase, Phase::Load); } else if (_fileUrlState == FileUrlState::Absent) { LOG_TST("Testing of FileUrl completed successfully."); - _phase = Phase::Polling; + TRANSITION_STATE(_phase, Phase::Polling); exitTest(TestResult::Ok); } @@ -209,7 +202,7 @@ public: LOG_TST( "onDocumentLoaded: Modifying the document and switching to Phase::WaitModifiedStatus"); - _phase = Phase::WaitModifiedStatus; + TRANSITION_STATE(_phase, Phase::WaitModifiedStatus); WSD_CMD("key type=input char=97 key=0"); WSD_CMD("key type=up char=0 key=512"); @@ -224,7 +217,7 @@ public: _phase == Phase::WaitModifiedStatus); LOG_TST("onDocumentModified: Saving document and switching to Phase::WaitPutFile"); - _phase = Phase::WaitPutFile; + TRANSITION_STATE(_phase, Phase::WaitPutFile); WSD_CMD("save dontTerminateEdit=0 dontSaveIfUnmodified=0 " "extendedData=CustomFlag%3DCustom%20Value%3BAnotherFlag%3DAnotherValue"); @@ -239,7 +232,7 @@ public: case Phase::Load: { LOG_TST("Phase::Load"); - _phase = Phase::WaitLoadStatus; + TRANSITION_STATE(_phase, Phase::WaitLoadStatus); initWebsocket("/wopi/files/" + std::to_string(_docId) + "?access_token=anything"); diff --git a/test/UnitWOPIHttpRedirect.cpp b/test/UnitWOPIHttpRedirect.cpp index 8f692662e0..86922e47ad 100644 --- a/test/UnitWOPIHttpRedirect.cpp +++ b/test/UnitWOPIHttpRedirect.cpp @@ -57,7 +57,7 @@ public: assertCheckFileInfoRequest(request); LOK_ASSERT_MESSAGE("Expected to be in Phase::Load", _phase == Phase::Load); - _phase = Phase::Redirected; + TRANSITION_STATE(_phase, Phase::Redirected); http::Response httpResponse(http::StatusCode::Found); httpResponse.set("Location", helpers::getTestServerURI() + redirectUri + '?' + params); diff --git a/test/UnitWOPITemplate.cpp b/test/UnitWOPITemplate.cpp index d2ff000bb6..104c6a1385 100644 --- a/test/UnitWOPITemplate.cpp +++ b/test/UnitWOPITemplate.cpp @@ -22,13 +22,7 @@ class UnitWOPITemplate : public WopiTestServer { - enum class Phase - { - LoadTemplate, - SaveDoc, - CloseDoc, - Polling - } _phase; + STATE_ENUM(Phase, LoadTemplate, SaveDoc, CloseDoc, Polling) _phase; bool _savedTemplate; @@ -99,7 +93,7 @@ public: LOK_ASSERT_EQUAL(static_cast(Phase::SaveDoc), static_cast(_phase)); _savedTemplate = true; LOG_TST("SaveDoc => CloseDoc"); - _phase = Phase::CloseDoc; + TRANSITION_STATE(_phase, Phase::CloseDoc); } else { @@ -133,7 +127,7 @@ public: case Phase::LoadTemplate: { LOG_TST("LoadTemplate => SaveDoc"); - _phase = Phase::SaveDoc; + TRANSITION_STATE(_phase, Phase::SaveDoc); initWebsocket("/wopi/files/10?access_token=anything"); WSD_CMD("load url=" + getWopiSrc()); @@ -143,7 +137,7 @@ public: case Phase::CloseDoc: { LOG_TST("CloseDoc => Polling"); - _phase = Phase::Polling; + TRANSITION_STATE(_phase, Phase::Polling); WSD_CMD("closedocument"); break; } diff --git a/wsd/COOLWSD.cpp b/wsd/COOLWSD.cpp index 180b4a8434..4dee956393 100644 --- a/wsd/COOLWSD.cpp +++ b/wsd/COOLWSD.cpp @@ -4283,7 +4283,7 @@ int COOLWSD::innerMain() // It is not at all obvious that this is the ideal place to do the HULLO thing and call onopen // on TheFakeWebSocket. But it seems to work. handle_cool_message("HULLO"); - MAIN_THREAD_EM_ASM(window.TheFakeWebSocket.onopen();); + MAIN_THREAD_EM_ASM(window.TheFakeWebSocket.onopen()); #endif /// The main-poll does next to nothing: