From 589134166b9bf000fc9384c5cad97f4885eab7b0 Mon Sep 17 00:00:00 2001 From: James Swan <122404367+swan-amazon@users.noreply.github.com> Date: Mon, 7 Oct 2024 21:54:22 +0000 Subject: [PATCH] restyle --- .../DefaultTermsAndConditionsProvider.cpp | 19 +++++--- .../DefaultTermsAndConditionsProvider.h | 6 ++- src/app/server/Server.h | 3 +- .../TestDefaultTermsAndConditionsProvider.cpp | 45 ++++++++++--------- 4 files changed, 43 insertions(+), 30 deletions(-) diff --git a/src/app/server/DefaultTermsAndConditionsProvider.cpp b/src/app/server/DefaultTermsAndConditionsProvider.cpp index ab63cd6405411a..c06d45f521be35 100644 --- a/src/app/server/DefaultTermsAndConditionsProvider.cpp +++ b/src/app/server/DefaultTermsAndConditionsProvider.cpp @@ -39,14 +39,15 @@ constexpr size_t kEstimatedTlvBufferSize = chip::TLV::EstimateStructOverhead(siz 8 * sizeof(uint16_t); // Extra space for rollback compatibility } // namespace - -CHIP_ERROR chip::app::DefaultTermsAndConditionsStorageDelegate::Init(PersistentStorageDelegate * const inPersistentStorageDelegate) { +CHIP_ERROR chip::app::DefaultTermsAndConditionsStorageDelegate::Init(PersistentStorageDelegate * const inPersistentStorageDelegate) +{ VerifyOrReturnError(nullptr != inPersistentStorageDelegate, CHIP_ERROR_INVALID_ARGUMENT); mPersistentStorageDelegate = inPersistentStorageDelegate; return CHIP_NO_ERROR; } -CHIP_ERROR chip::app::DefaultTermsAndConditionsStorageDelegate::Delete() { +CHIP_ERROR chip::app::DefaultTermsAndConditionsStorageDelegate::Delete() +{ VerifyOrReturnError(nullptr != mPersistentStorageDelegate, CHIP_ERROR_UNINITIALIZED); const chip::StorageKeyName storageKey = DefaultStorageKeyAllocator::TermsAndConditionsAcceptance(); @@ -54,7 +55,8 @@ CHIP_ERROR chip::app::DefaultTermsAndConditionsStorageDelegate::Delete() { return mPersistentStorageDelegate->SyncDeleteKeyValue(storageKey.KeyName()); } -CHIP_ERROR chip::app::DefaultTermsAndConditionsStorageDelegate::Get(Optional & outTermsAndConditions) { +CHIP_ERROR chip::app::DefaultTermsAndConditionsStorageDelegate::Get(Optional & outTermsAndConditions) +{ uint8_t serializationVersion = 0; uint16_t acknowledgements = 0; uint16_t acknowledgementsVersion = 0; @@ -100,7 +102,8 @@ CHIP_ERROR chip::app::DefaultTermsAndConditionsStorageDelegate::Get(Optional & inTermsAndConditions) { +CHIP_ERROR chip::app::DefaultTermsAndConditionsStorageDelegate::Set(const Optional & inTermsAndConditions) +{ uint8_t buffer[kEstimatedTlvBufferSize] = { 0 }; chip::TLV::TLVWriter tlvWriter; chip::TLV::TLVType tlvContainer; @@ -126,11 +129,13 @@ CHIP_ERROR chip::app::DefaultTermsAndConditionsStorageDelegate::Set(const Option } CHIP_ERROR -chip::app::DefaultTermsAndConditionsProvider::Init(TermsAndConditionsStorageDelegate * const inStorageDelegate, const chip::Optional & inRequiredTermsAndConditions) +chip::app::DefaultTermsAndConditionsProvider::Init( + TermsAndConditionsStorageDelegate * const inStorageDelegate, + const chip::Optional & inRequiredTermsAndConditions) { VerifyOrReturnError(nullptr != inStorageDelegate, CHIP_ERROR_INVALID_ARGUMENT); mTermsAndConditionsStorageDelegate = inStorageDelegate; - mRequiredAcknowledgements = inRequiredTermsAndConditions; + mRequiredAcknowledgements = inRequiredTermsAndConditions; if (CHIP_NO_ERROR == mTermsAndConditionsStorageDelegate->Get(mLatchedTermsAndConditions)) { diff --git a/src/app/server/DefaultTermsAndConditionsProvider.h b/src/app/server/DefaultTermsAndConditionsProvider.h index bbe22f8aac8af3..d88f186d51edf4 100644 --- a/src/app/server/DefaultTermsAndConditionsProvider.h +++ b/src/app/server/DefaultTermsAndConditionsProvider.h @@ -64,9 +64,11 @@ class DefaultTermsAndConditionsProvider : public TermsAndConditionsProvider * * @param[in] inStorageDelegate Storage delegate dependency. */ - CHIP_ERROR Init(TermsAndConditionsStorageDelegate * const inStorageDelegate, const chip::Optional & inRequiredTermsAndConditions); + CHIP_ERROR Init(TermsAndConditionsStorageDelegate * const inStorageDelegate, + const chip::Optional & inRequiredTermsAndConditions); - CHIP_ERROR CheckAcceptance(const Optional & inTermsAndConditions, TermsAndConditionsState & outState) const override; + CHIP_ERROR CheckAcceptance(const Optional & inTermsAndConditions, + TermsAndConditionsState & outState) const override; CHIP_ERROR CommitAcceptance() override; diff --git a/src/app/server/Server.h b/src/app/server/Server.h index 95d77fa90ffab9..a108c22f7c4551 100644 --- a/src/app/server/Server.h +++ b/src/app/server/Server.h @@ -329,7 +329,8 @@ struct CommonCaseDeviceServerInitParams : public ServerInitParams }); ReturnErrorOnFailure(sDefaultTermsAndConditionsStorageDelegateInstance.Init(this->persistentStorageDelegate)); - ReturnErrorOnFailure(sDefaultTermsAndConditionsProviderInstance.Init(&sDefaultTermsAndConditionsStorageDelegateInstance, termsAndConditions)); + ReturnErrorOnFailure(sDefaultTermsAndConditionsProviderInstance.Init(&sDefaultTermsAndConditionsStorageDelegateInstance, + termsAndConditions)); this->termsAndConditionsProvider = &sDefaultTermsAndConditionsProviderInstance; } #endif diff --git a/src/app/tests/TestDefaultTermsAndConditionsProvider.cpp b/src/app/tests/TestDefaultTermsAndConditionsProvider.cpp index 3bdfa8963358a2..06aedd3a5cdf1a 100644 --- a/src/app/tests/TestDefaultTermsAndConditionsProvider.cpp +++ b/src/app/tests/TestDefaultTermsAndConditionsProvider.cpp @@ -28,27 +28,30 @@ class TestTermsAndConditionsStorageDelegate : public chip::app::TermsAndConditionsStorageDelegate { public: - TestTermsAndConditionsStorageDelegate(chip::Optional &initialTermsAndConditions) - : mTermsAndConditions(initialTermsAndConditions) { - } + TestTermsAndConditionsStorageDelegate(chip::Optional & initialTermsAndConditions) : + mTermsAndConditions(initialTermsAndConditions) + {} - CHIP_ERROR Delete() { + CHIP_ERROR Delete() + { mTermsAndConditions.ClearValue(); return CHIP_NO_ERROR; } - CHIP_ERROR Get(chip::Optional & outTermsAndConditions) { + CHIP_ERROR Get(chip::Optional & outTermsAndConditions) + { outTermsAndConditions = mTermsAndConditions; return CHIP_NO_ERROR; } - CHIP_ERROR Set(const chip::Optional & inTermsAndConditions) { + CHIP_ERROR Set(const chip::Optional & inTermsAndConditions) + { mTermsAndConditions = inTermsAndConditions; return CHIP_NO_ERROR; } private: - chip::Optional &mTermsAndConditions; + chip::Optional & mTermsAndConditions; }; TEST(DefaultTermsAndConditionsProvider, TestInitSuccess) @@ -120,7 +123,7 @@ TEST(DefaultTermsAndConditionsProvider, TestTermsAcceptedPersistsSuccess) chip::app::DefaultTermsAndConditionsStorageDelegate defaultTermsAndConditionsStorageDelegate; err = defaultTermsAndConditionsStorageDelegate.Init(&testPersistentStorageDelegate); EXPECT_EQ(CHIP_NO_ERROR, err); - + chip::app::DefaultTermsAndConditionsProvider defaultTermsAndConditionsProvider; chip::Optional requiredTermsAndConditions = chip::Optional({ .value = 1, @@ -400,9 +403,9 @@ TEST(DefaultTermsAndConditionsProvider, TestRevertAcceptenceWhenPreviouslyAccept CHIP_ERROR err; // Initialize unit under test [Conditions previously accepted] - chip::Optional initialTermsAndConditions = chip::Optional({ - .value = 1, - .version = 1, + chip::Optional initialTermsAndConditions = chip::Optional({ + .value = 1, + .version = 1, }); chip::Optional requiredTermsAndConditions = chip::Optional({ .value = 0b11, @@ -434,10 +437,11 @@ TEST(DefaultTermsAndConditionsProvider, TestRevertAcceptenceWhenPreviouslyAccept CHIP_ERROR err; // Initialize unit under test dependency - chip::Optional initiallyAcceptedTermsAndConditions = chip::Optional({ - .value = 1, - .version = 1, - }); + chip::Optional initiallyAcceptedTermsAndConditions = + chip::Optional({ + .value = 1, + .version = 1, + }); TestTermsAndConditionsStorageDelegate testTermsAndConditionsStorageDelegate(initiallyAcceptedTermsAndConditions); // Initialize unit under test [Conditions previously accepted] @@ -450,10 +454,11 @@ TEST(DefaultTermsAndConditionsProvider, TestRevertAcceptenceWhenPreviouslyAccept EXPECT_EQ(CHIP_NO_ERROR, err); // [Fail-safe started] Acceptance updated. - chip::Optional updatedAcceptedTermsAndConditions = chip::Optional({ - .value = 0b111, - .version = 3, - }); + chip::Optional updatedAcceptedTermsAndConditions = + chip::Optional({ + .value = 0b111, + .version = 3, + }); err = defaultTermsAndConditionsProvider.SetAcceptance(updatedAcceptedTermsAndConditions); EXPECT_EQ(CHIP_NO_ERROR, err); @@ -469,4 +474,4 @@ TEST(DefaultTermsAndConditionsProvider, TestRevertAcceptenceWhenPreviouslyAccept EXPECT_TRUE(outTermsAndConditions.HasValue()); EXPECT_EQ(outTermsAndConditions.Value().value, initiallyAcceptedTermsAndConditions.Value().value); EXPECT_EQ(outTermsAndConditions.Value().version, initiallyAcceptedTermsAndConditions.Value().version); -} \ No newline at end of file +}