From b568518d0d5623d19c2a4deb94ca670123d94f31 Mon Sep 17 00:00:00 2001 From: James Swan <122404367+swan-amazon@users.noreply.github.com> Date: Mon, 7 Oct 2024 20:36:20 +0000 Subject: [PATCH] wip --- .../TestDefaultTermsAndConditionsProvider.cpp | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/src/app/tests/TestDefaultTermsAndConditionsProvider.cpp b/src/app/tests/TestDefaultTermsAndConditionsProvider.cpp index 927c63ef327c7b..a39478b8ff8eda 100644 --- a/src/app/tests/TestDefaultTermsAndConditionsProvider.cpp +++ b/src/app/tests/TestDefaultTermsAndConditionsProvider.cpp @@ -314,3 +314,66 @@ TEST(DefaultTermsAndConditionsProvider, TestAcceptanceCommitCheckSetRevertCheckE EXPECT_EQ(outTermsAndConditions.Value().value, acceptedTermsAndConditions.Value().value); EXPECT_EQ(outTermsAndConditions.Value().version, acceptedTermsAndConditions.Value().version); } + +TEST(DefaultTermsAndConditionsProvider, TestRevertAcceptenceWhileMissing) +{ + CHIP_ERROR err; + + chip::TestPersistentStorageDelegate storageDelegate; + chip::app::DefaultTermsAndConditionsProvider tncProvider; + + chip::Optional requiredTermsAndConditions = chip::Optional({ + .value = 1, + .version = 1, + }); + + chip::Optional outTermsAndConditions; + + // Initialize unit under test [No conditions previously accepted] + err = tncProvider.Init(&storageDelegate, requiredTermsAndConditions); + EXPECT_EQ(CHIP_NO_ERROR, err); + + // [Fail-safe started] No conditions set during the fail-safe. No commit. + err = tncProvider.GetAcceptance(outTermsAndConditions); + EXPECT_EQ(CHIP_NO_ERROR, err); + EXPECT_FALSE(outTermsAndConditions.HasValue()); + + // [Fail-safe expires] Revert is called. + err = tncProvider.RevertAcceptance(); + EXPECT_EQ(CHIP_NO_ERROR, err); + + // [New fail safe started (to retry the commissioning operations)] Confirm acceptance returns previous values (empty) + err = tncProvider.GetAcceptance(outTermsAndConditions); + EXPECT_EQ(CHIP_NO_ERROR, err); + EXPECT_FALSE(outTermsAndConditions.HasValue()); +} + +TEST(DefaultTermsAndConditionsProvider, TestRevertAcceptenceWhileAccepted) +{ + CHIP_ERROR err; + + chip::TestPersistentStorageDelegate storageDelegate; + chip::app::DefaultTermsAndConditionsProvider tncProvider; + + chip::Optional requiredTermsAndConditions = chip::Optional({ + .value = 1, + .version = 1, + }); + + chip::Optional outTermsAndConditions; + + // Initialize unit under test [Conditions previously accepted] + err = tncProvider.Init(&storageDelegate, requiredTermsAndConditions); + EXPECT_EQ(CHIP_NO_ERROR, err); + + // [Fail-safe started] No conditions set during the fail-safe. No commit. + + // [Fail-safe expires] Revert is called. + err = tncProvider.RevertAcceptance(); + EXPECT_EQ(CHIP_NO_ERROR, err); + + // [New fail safe started (to retry the commissioning operations)] Confirm acceptance returns previous values (accepted) + err = tncProvider.GetAcceptance(outTermsAndConditions); + EXPECT_EQ(CHIP_NO_ERROR, err); + EXPECT_FALSE(outTermsAndConditions.HasValue()); +}