Z-Wave Protocol Controller Reference
zpc_attribute_store_test_helper_cpp.hpp
Go to the documentation of this file.
1/******************************************************************************
2 * # License
3 * <b>Copyright 2024 Silicon Laboratories Inc. www.silabs.com</b>
4 ******************************************************************************
5 * The licensor of this software is Silicon Laboratories Inc. Your use of this
6 * software is governed by the terms of Silicon Labs Master Software License
7 * Agreement (MSLA) available at
8 * www.silabs.com/about-us/legal/master-software-license-agreement. This
9 * software is distributed to you in Source Code format and is governed by the
10 * sections of the MSLA applicable to Source Code.
11 *
12 *****************************************************************************/
13
14#ifndef ZPC_ATTRIBUTE_STORE_TEST_HELPER_CPP_HPP
15#define ZPC_ATTRIBUTE_STORE_TEST_HELPER_CPP_HPP
16
17// Unify cpp
18#include "attribute.hpp"
19
20extern "C" {
21// Z-Wave types
22#include "zwave_generic_types.h"
25
26// Test framework
27#include "unity.h"
28
36{
37
39// Global variables
40// Must be declared as "extern" and defined in the cpp to avoid multiple definition
41// More information : https://stackoverflow.com/questions/11478152/how-to-work-with-variable-in-namespace
43// Endpoint id node wrapper
44extern attribute_store::attribute cpp_endpoint_id_node; //NOSONAR - false positive
45
46
53
55// Version
57
65 const zwave_cc_version_t &version,
66 attribute_store::attribute parent
68
78
80// Generic Node/Attribute Test Helpers
82
92attribute_store::attribute
93 helper_test_and_get_node(attribute_store_type_t node_type,
94 attribute_store::attribute parent
96
103void helper_test_node_exists(attribute_store_type_t node_type,
104 attribute_store::attribute parent
112void helper_test_node_does_not_exists(attribute_store_type_t node_type,
113 attribute_store::attribute parent
115} // namespace zpc_attribute_store_test_helper
116
117} // extern "C"
118
119// Cpp template functions
121{
122template<typename T> attribute_store::attribute helper_test_attribute_value(
123 attribute_store_type_t node_type,
124 T expected_value,
125 attribute_store::attribute parent = cpp_endpoint_id_node,
126 attribute_store_node_value_state_t state = REPORTED_ATTRIBUTE)
127{
128 auto current_node = helper_test_and_get_node(node_type, parent);
129
130 try {
131 const std::string error_message
132 = (std::string("Value mismatch for ") + current_node.name_and_id())
133 .c_str();
134
135 if constexpr (std::is_same<T, std::vector<uint8_t>>::value) {
136 TEST_ASSERT_EQUAL_UINT8_ARRAY_MESSAGE(
137 expected_value.data(),
138 current_node.reported<std::vector<uint8_t>>().data(),
139 expected_value.size(),
140 error_message.c_str());
141 } else if constexpr (std::is_same<T, std::string>::value) {
142 TEST_ASSERT_EQUAL_STRING_MESSAGE(
143 expected_value.c_str(),
144 current_node.reported<std::string>().c_str(),
145 error_message.c_str());
146 } else {
147 TEST_ASSERT_EQUAL_MESSAGE(expected_value,
148 current_node.get<T>(state),
149 error_message.c_str());
150 }
151 } catch (std::exception &e) {
152 TEST_FAIL_MESSAGE(e.what());
153 }
154
155 return current_node;
156}
157} // namespace zpc_attribute_store_test_helper
158#endif // ZPC_ATTRIBUTE_STORE_TEST_HELPER_CPP_HPP
uint8_t zwave_cc_version_t
‍Version of a Z-Wave Command Class
Definition: zwave_command_class_version_types.h:26
uint16_t zwave_command_class_t
Definition: zwave_generic_types.h:29
Helper namespace for the ZPC attribute store tests.
Definition: zpc_attribute_store_test_helper_cpp.hpp:36
attribute_store::attribute helper_test_and_get_node(attribute_store_type_t node_type, attribute_store::attribute parent=cpp_endpoint_id_node)
Get a node and check that it exists.
zwave_cc_version_t helper_get_command_class_version(zwave_command_class_t command_class_id)
Get version for current class.
attribute_store::attribute helper_test_attribute_value(attribute_store_type_t node_type, T expected_value, attribute_store::attribute parent=cpp_endpoint_id_node, attribute_store_node_value_state_t state=REPORTED_ATTRIBUTE)
Definition: zpc_attribute_store_test_helper_cpp.hpp:122
void helper_test_node_exists(attribute_store_type_t node_type, attribute_store::attribute parent=cpp_endpoint_id_node)
Test that a node exists.
void zpc_attribute_store_test_helper_init()
Initialize the test helper.
attribute_store::attribute cpp_endpoint_id_node
void helper_test_node_does_not_exists(attribute_store_type_t node_type, attribute_store::attribute parent=cpp_endpoint_id_node)
Test that a node doesn't exists.
void helper_set_command_class_version(zwave_command_class_t command_class_id, const zwave_cc_version_t &version, attribute_store::attribute parent=cpp_endpoint_id_node)
Set version for current class.
Test helper for using the zpc attribute store.
static send_data_state_t state
Definition: zwave_crc16_transport.c:52