Skip to content

Commit 12285a0

Browse files
authored
Merge pull request #5 from rzr/GH-24/UIC-3082/phcoval/main
GH-14: zpc: Enable testing by default
2 parents 75be48b + 3bcf29f commit 12285a0

File tree

3 files changed

+105
-29
lines changed

3 files changed

+105
-29
lines changed

applications/zpc/components/zwave_command_classes/src/zwave_command_class_switch_color.c

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -37,31 +37,17 @@
3737

3838
#define LOG_TAG "zwave_command_class_switch_color"
3939

40-
[[maybe_unused]]
41-
static void set_desired_duration(attribute_store_node_t state_node,
42-
uint32_t duration)
40+
static void set_duration(attribute_store_node_t state_node,
41+
attribute_store_node_value_state_t state,
42+
uint32_t duration)
4343
{
4444
attribute_store_node_t duration_node
4545
= attribute_store_get_first_child_by_type(
4646
state_node,
4747
ATTRIBUTE_COMMAND_CLASS_SWITCH_COLOR_DURATION);
4848

4949
attribute_store_set_node_attribute_value(duration_node,
50-
DESIRED_ATTRIBUTE,
51-
(uint8_t *)&duration,
52-
sizeof(duration));
53-
}
54-
55-
static void set_reported_duration(attribute_store_node_t state_node,
56-
uint32_t duration)
57-
{
58-
attribute_store_node_t duration_node
59-
= attribute_store_get_first_child_by_type(
60-
state_node,
61-
ATTRIBUTE_COMMAND_CLASS_SWITCH_COLOR_DURATION);
62-
63-
attribute_store_set_node_attribute_value(duration_node,
64-
REPORTED_ATTRIBUTE,
50+
state,
6551
(uint8_t *)&duration,
6652
sizeof(duration));
6753
}
@@ -80,15 +66,7 @@ static void
8066
while (component_node != ATTRIBUTE_STORE_INVALID_NODE) {
8167
index += 1;
8268

83-
attribute_store_node_t duration_node
84-
= attribute_store_get_first_child_by_type(
85-
component_node,
86-
ATTRIBUTE_COMMAND_CLASS_SWITCH_COLOR_DURATION);
87-
88-
attribute_store_set_node_attribute_value(duration_node,
89-
value_state,
90-
(uint8_t *)&duration,
91-
sizeof(duration));
69+
set_duration(component_node, value_state, duration);
9270

9371
component_node = attribute_store_get_node_child_by_type(
9472
state_node,
@@ -166,7 +144,7 @@ static void
166144
state_node,
167145
ATTRIBUTE_COMMAND_CLASS_SWITCH_COLOR_VALUE,
168146
&attribute_store_undefine_desired);
169-
set_reported_duration(state_node, 0);
147+
set_duration(state_node, REPORTED_ATTRIBUTE, 0);
170148
attribute_store_undefine_desired(duration_node);
171149
break;
172150

applications/zpc/components/zwave_command_classes/test/zwave_command_class_switch_color_test.c

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
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"
@@ -47,6 +48,7 @@
4748

4849
// Static variables
4950
static 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
5254
static 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)
6680
void 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+
}

helper.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ zpc/build: zpc/configure build
156156
zpc/test: ${build_dir}/applications/zpc/components/zwave_command_classes/test/
157157
ctest --test-dir ${<}
158158

159-
zpc/default: zpc/configure zpc/build
159+
zpc/default: zpc/configure zpc/build zpc/test
160160
@date -u
161161

162162
### @rootfs is faster than docker for env check

0 commit comments

Comments
 (0)