3131#include "ZW_classcmd.h"
3232#include "zwave_utils.h"
3333#include "zwave_controller_types.h"
34+ #include "zwave_command_class_color_switch_types.h"
3435
3536// Test helpers
3637#include "zpc_attribute_store_test_helper.h"
4748
4849// Static variables
4950static zpc_resolver_event_notification_function_t on_send_complete = NULL ;
51+ static attribute_timeout_callback_t switch_color_undefine_reported = NULL ;
5052
5153// Stub functions
5254static sl_status_t register_send_event_handler_stub (
@@ -62,10 +64,23 @@ static sl_status_t register_send_event_handler_stub(
6264 return SL_STATUS_OK ;
6365}
6466
67+ static sl_status_t attribute_timeout_set_callback_stub (
68+ attribute_store_node_t node ,
69+ clock_time_t duration ,
70+ attribute_timeout_callback_t callback_function ,
71+ int cmock_num_calls )
72+ {
73+ TEST_ASSERT_EQUAL (ATTRIBUTE_COMMAND_CLASS_SWITCH_COLOR_STATE , attribute_store_get_node_type (node ));
74+ switch_color_undefine_reported = callback_function ;
75+ return SL_STATUS_OK ;
76+ }
77+
78+
6579/// Setup the test suite (called once before all test_xxx functions are called)
6680void suiteSetUp ()
6781{
6882 on_send_complete = NULL ;
83+ switch_color_undefine_reported = NULL ;
6984
7085 datastore_init (":memory:" );
7186 attribute_store_init ();
@@ -155,10 +170,93 @@ void test_zwave_command_class_on_send_complete()
155170 TEST_ASSERT_TRUE (
156171 attribute_store_is_value_defined (value_1_node , REPORTED_ATTRIBUTE ));
157172
173+ // Test without duration
174+ on_send_complete (state_node ,
175+ RESOLVER_SET_RULE ,
176+ FRAME_SENT_EVENT_OK_NO_SUPERVISION );
177+
178+ TEST_ASSERT_FALSE (
179+ attribute_store_is_value_defined (value_2_node , REPORTED_ATTRIBUTE ));
180+ TEST_ASSERT_FALSE (
181+ attribute_store_is_value_defined (value_2_node , DESIRED_ATTRIBUTE ));
182+ TEST_ASSERT_FALSE (
183+ attribute_store_is_value_defined (value_1_node , REPORTED_ATTRIBUTE ));
184+ TEST_ASSERT_FALSE (
185+ attribute_store_is_value_defined (value_1_node , DESIRED_ATTRIBUTE ));
186+
187+ // Test with duration
188+ value = 0 ;
189+ attribute_store_set_reported (value_1_node , & value , sizeof (value ));
190+ value = 1 ;
191+ attribute_store_set_desired (value_1_node , & value , sizeof (value ));
192+ value = 2 ;
193+ attribute_store_set_reported (value_2_node , & value , sizeof (value ));
194+ value = 3 ;
195+ attribute_store_set_desired (value_2_node , & value , sizeof (value ));
196+
197+ color_component_id_duration_t duration_value = 20 ;
198+ attribute_store_node_t duration_node
199+ = attribute_store_add_node (ATTRIBUTE_COMMAND_CLASS_SWITCH_COLOR_DURATION ,
200+ state_node );
201+ attribute_store_set_desired (duration_node , & duration_value , sizeof (duration_value ));
202+
203+ attribute_timeout_set_callback_ExpectAndReturn (
204+ state_node ,
205+ zwave_duration_to_time (duration_value ) + PROBE_BACK_OFF ,
206+ NULL ,
207+ SL_STATUS_OK );
208+ attribute_timeout_set_callback_IgnoreArg_callback_function ();
209+ attribute_timeout_set_callback_Stub (& attribute_timeout_set_callback_stub );
210+
211+ on_send_complete (state_node ,
212+ RESOLVER_SET_RULE ,
213+ FRAME_SENT_EVENT_OK_NO_SUPERVISION );
214+ TEST_ASSERT_FALSE (
215+ attribute_store_is_value_defined (value_2_node , DESIRED_ATTRIBUTE ));
216+ TEST_ASSERT_FALSE (
217+ attribute_store_is_value_defined (value_1_node , DESIRED_ATTRIBUTE ));
218+ TEST_ASSERT_FALSE (
219+ attribute_store_is_value_defined (duration_node , DESIRED_ATTRIBUTE ));
220+ TEST_ASSERT_TRUE (
221+ attribute_store_is_value_defined (duration_node , REPORTED_ATTRIBUTE ));
222+ TEST_ASSERT_TRUE (
223+ attribute_store_is_value_defined (value_1_node , REPORTED_ATTRIBUTE ));
224+ TEST_ASSERT_TRUE (
225+ attribute_store_is_value_defined (value_2_node , REPORTED_ATTRIBUTE ));
226+
158227 on_send_complete (state_node ,
159228 RESOLVER_SET_RULE ,
160229 FRAME_SENT_EVENT_OK_SUPERVISION_NO_SUPPORT );
161230
162231 TEST_ASSERT_FALSE (
163232 attribute_store_is_value_defined (value_1_node , REPORTED_ATTRIBUTE ));
164233}
234+
235+ void test_switch_color_undefine_reported_happy_case ()
236+ {
237+ //
238+ TEST_ASSERT_NOT_NULL (switch_color_undefine_reported );
239+
240+ const int COLOR_VALUE_COUNT = 3 ;
241+
242+ for (int i = 0 ; i < COLOR_VALUE_COUNT ; i ++ ) {
243+ attribute_store_node_t color_value_node
244+ = attribute_store_add_node (ATTRIBUTE_COMMAND_CLASS_SWITCH_COLOR_VALUE ,
245+ endpoint_id_node );
246+
247+ attribute_store_set_reported (color_value_node , & i , sizeof (i ));
248+ }
249+
250+ switch_color_undefine_reported (endpoint_id_node );
251+
252+ for (int i = 0 ; i < COLOR_VALUE_COUNT ; i ++ ) {
253+ int j ;
254+ attribute_store_node_t color_value_node
255+ = attribute_store_add_node (ATTRIBUTE_COMMAND_CLASS_SWITCH_COLOR_VALUE ,
256+ endpoint_id_node );
257+
258+ TEST_ASSERT_EQUAL (
259+ SL_STATUS_FAIL ,
260+ attribute_store_get_reported (color_value_node , & j , sizeof (j )));
261+ }
262+ }
0 commit comments