34
34
#include < lib/core/StringBuilderAdapters.h>
35
35
#include < lib/support/CHIPMem.h>
36
36
#include < lib/support/CodeUtils.h>
37
+ #include < lib/support/DefaultStorageKeyAllocator.h>
37
38
#include < lib/support/TestPersistentStorageDelegate.h>
38
39
#include < platform/CHIPDeviceLayer.h>
39
40
@@ -77,12 +78,14 @@ TEST_F(TestFailSafeContext, TestFailSafeContext_ArmFailSafe)
77
78
EXPECT_EQ (failSafeContext.GetFabricIndex (), kTestAccessingFabricIndex1 );
78
79
EXPECT_TRUE (failSafeContext.IsFailSafeArmed (kTestAccessingFabricIndex1 ));
79
80
EXPECT_FALSE (failSafeContext.IsFailSafeArmed (kTestAccessingFabricIndex2 ));
81
+ EXPECT_FALSE (testStorage.SyncDoesKeyExist (DefaultStorageKeyAllocator::FailSafeMarkerKey ().KeyName ()));
80
82
81
83
failSafeContext.DisarmFailSafe ();
82
84
EXPECT_FALSE (failSafeContext.IsFailSafeArmed ());
85
+ EXPECT_FALSE (testStorage.SyncDoesKeyExist (DefaultStorageKeyAllocator::FailSafeMarkerKey ().KeyName ()));
83
86
}
84
87
85
- TEST_F (TestFailSafeContext, TestFailSafeContext_NocCommandInvoked )
88
+ TEST_F (TestFailSafeContext, TestFailSafeContext_AddNocCommandInvoked )
86
89
{
87
90
chip::TestPersistentStorageDelegate testStorage;
88
91
chip::app::FailSafeContext failSafeContext;
@@ -91,17 +94,67 @@ TEST_F(TestFailSafeContext, TestFailSafeContext_NocCommandInvoked)
91
94
92
95
EXPECT_EQ (failSafeContext.ArmFailSafe (kTestAccessingFabricIndex1 , System::Clock::Seconds16 (1 )), CHIP_NO_ERROR);
93
96
EXPECT_EQ (failSafeContext.GetFabricIndex (), kTestAccessingFabricIndex1 );
97
+ EXPECT_FALSE (testStorage.SyncDoesKeyExist (DefaultStorageKeyAllocator::FailSafeMarkerKey ().KeyName ()));
98
+
99
+ failSafeContext.SetAddNocCommandStarted (kTestAccessingFabricIndex2 );
100
+ EXPECT_EQ (failSafeContext.GetFabricIndex (), kTestAccessingFabricIndex2 );
101
+ EXPECT_TRUE (testStorage.SyncDoesKeyExist (DefaultStorageKeyAllocator::FailSafeMarkerKey ().KeyName ()));
94
102
95
103
failSafeContext.SetAddNocCommandInvoked (kTestAccessingFabricIndex2 );
96
104
EXPECT_TRUE (failSafeContext.NocCommandHasBeenInvoked ());
97
105
EXPECT_TRUE (failSafeContext.AddNocCommandHasBeenInvoked ());
98
106
EXPECT_EQ (failSafeContext.GetFabricIndex (), kTestAccessingFabricIndex2 );
99
107
108
+ failSafeContext.DisarmFailSafe ();
109
+ EXPECT_FALSE (testStorage.SyncDoesKeyExist (DefaultStorageKeyAllocator::FailSafeMarkerKey ().KeyName ()));
110
+ }
111
+
112
+ TEST_F (TestFailSafeContext, TestFailSafeContext_UpdateNocCommandInvoked)
113
+ {
114
+ chip::TestPersistentStorageDelegate testStorage;
115
+ chip::app::FailSafeContext failSafeContext;
116
+
117
+ failSafeContext.Init ({ &testStorage });
118
+
119
+ EXPECT_EQ (failSafeContext.ArmFailSafe (kTestAccessingFabricIndex1 , System::Clock::Seconds16 (1 )), CHIP_NO_ERROR);
120
+ EXPECT_EQ (failSafeContext.GetFabricIndex (), kTestAccessingFabricIndex1 );
121
+ EXPECT_FALSE (testStorage.SyncDoesKeyExist (DefaultStorageKeyAllocator::FailSafeMarkerKey ().KeyName ()));
122
+
100
123
failSafeContext.SetUpdateNocCommandInvoked ();
101
124
EXPECT_TRUE (failSafeContext.NocCommandHasBeenInvoked ());
102
125
EXPECT_TRUE (failSafeContext.UpdateNocCommandHasBeenInvoked ());
126
+ EXPECT_FALSE (testStorage.SyncDoesKeyExist (DefaultStorageKeyAllocator::FailSafeMarkerKey ().KeyName ()));
103
127
104
128
failSafeContext.DisarmFailSafe ();
129
+ EXPECT_FALSE (testStorage.SyncDoesKeyExist (DefaultStorageKeyAllocator::FailSafeMarkerKey ().KeyName ()));
130
+ }
131
+
132
+ TEST_F (TestFailSafeContext, TestFailSafeContext_NocCommandInvokedTimerExpiry)
133
+ {
134
+ chip::TestPersistentStorageDelegate testStorage;
135
+ chip::app::FailSafeContext failSafeContext;
136
+
137
+ failSafeContext.Init ({ &testStorage });
138
+
139
+ EXPECT_EQ (failSafeContext.ArmFailSafe (kTestAccessingFabricIndex1 , System::Clock::Seconds16 (1 )), CHIP_NO_ERROR);
140
+ EXPECT_EQ (failSafeContext.GetFabricIndex (), kTestAccessingFabricIndex1 );
141
+ EXPECT_FALSE (testStorage.SyncDoesKeyExist (DefaultStorageKeyAllocator::FailSafeMarkerKey ().KeyName ()));
142
+
143
+ failSafeContext.SetAddNocCommandStarted (kTestAccessingFabricIndex2 );
144
+ EXPECT_EQ (failSafeContext.GetFabricIndex (), kTestAccessingFabricIndex2 );
145
+ EXPECT_TRUE (testStorage.SyncDoesKeyExist (DefaultStorageKeyAllocator::FailSafeMarkerKey ().KeyName ()));
146
+
147
+ failSafeContext.SetAddNocCommandInvoked (kTestAccessingFabricIndex2 );
148
+ EXPECT_TRUE (failSafeContext.NocCommandHasBeenInvoked ());
149
+ EXPECT_TRUE (failSafeContext.AddNocCommandHasBeenInvoked ());
150
+ EXPECT_EQ (failSafeContext.GetFabricIndex (), kTestAccessingFabricIndex2 );
151
+
152
+ failSafeContext.ForceFailSafeTimerExpiry ();
153
+
154
+ PlatformMgr ().ScheduleWork ([](intptr_t ) -> void { PlatformMgr ().StopEventLoopTask (); }, (intptr_t ) nullptr );
155
+ PlatformMgr ().RunEventLoop ();
156
+
157
+ EXPECT_FALSE (testStorage.SyncDoesKeyExist (DefaultStorageKeyAllocator::FailSafeMarkerKey ().KeyName ()));
105
158
}
106
159
107
160
} // namespace
0 commit comments