Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
swan-amazon committed Oct 7, 2024
1 parent 62a408c commit b568518
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions src/app/tests/TestDefaultTermsAndConditionsProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<chip::app::TermsAndConditions> requiredTermsAndConditions = chip::Optional<chip::app::TermsAndConditions>({
.value = 1,
.version = 1,
});

chip::Optional<chip::app::TermsAndConditions> 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<chip::app::TermsAndConditions> requiredTermsAndConditions = chip::Optional<chip::app::TermsAndConditions>({
.value = 1,
.version = 1,
});

chip::Optional<chip::app::TermsAndConditions> 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());
}

0 comments on commit b568518

Please sign in to comment.