mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-14 01:27:41 +00:00
mesh: add unit test for elements descriptions iterator, add missing getter for CONFIGURATION_COMPOSITION_DATA event, fix offsets in existing getters
This commit is contained in:
parent
873d831b6a
commit
d61023b23c
@ -348,26 +348,30 @@ static void mesh_configuration_client_composition_data_status_handler(mesh_model
|
||||
mesh_access_message_processed(pdu);
|
||||
}
|
||||
|
||||
uint8_t mesh_subevent_configuration_composition_data_get_cid(const uint8_t * event){
|
||||
return little_endian_read_16(event, 1);
|
||||
uint8_t mesh_subevent_configuration_composition_data_get_page(const uint8_t * event){
|
||||
return event[6];
|
||||
}
|
||||
|
||||
uint8_t mesh_subevent_configuration_composition_data_get_pid(const uint8_t * event){
|
||||
return little_endian_read_16(event, 3);
|
||||
}
|
||||
|
||||
uint8_t mesh_subevent_configuration_composition_data_get_vid(const uint8_t * event){
|
||||
return little_endian_read_16(event, 5);
|
||||
}
|
||||
|
||||
uint8_t mesh_subevent_configuration_composition_data_get_crpl(const uint8_t * event){
|
||||
uint16_t mesh_subevent_configuration_composition_data_get_cid(const uint8_t * event){
|
||||
return little_endian_read_16(event, 7);
|
||||
}
|
||||
|
||||
uint8_t mesh_subevent_configuration_composition_data_get_features(const uint8_t * event){
|
||||
uint16_t mesh_subevent_configuration_composition_data_get_pid(const uint8_t * event){
|
||||
return little_endian_read_16(event, 9);
|
||||
}
|
||||
|
||||
uint16_t mesh_subevent_configuration_composition_data_get_vid(const uint8_t * event){
|
||||
return little_endian_read_16(event, 11);
|
||||
}
|
||||
|
||||
uint16_t mesh_subevent_configuration_composition_data_get_crpl(const uint8_t * event){
|
||||
return little_endian_read_16(event, 13);
|
||||
}
|
||||
|
||||
uint16_t mesh_subevent_configuration_composition_data_get_features(const uint8_t * event){
|
||||
return little_endian_read_16(event, 15);
|
||||
}
|
||||
|
||||
|
||||
static inline void mesh_configuration_client_handle_uint8_value(mesh_model_t *mesh_model, mesh_pdu_t * pdu, uint8_t subevent_type){
|
||||
mesh_access_parser_state_t parser;
|
||||
|
@ -137,6 +137,60 @@ void mesh_composition_data_iterator_next_vendor_model(mesh_composite_data_iterat
|
||||
*/
|
||||
uint32_t mesh_composition_data_iterator_vendor_model_id(mesh_composite_data_iterator_t * iterator);
|
||||
|
||||
/**
|
||||
* @brief Get field page from event MESH_SUBEVENT_CONFIGURATION_COMPOSITION_DATA
|
||||
* @param event packet
|
||||
* @return page
|
||||
* @note: btstack_type 1
|
||||
*/
|
||||
uint8_t mesh_subevent_configuration_composition_data_get_page(const uint8_t * event);
|
||||
|
||||
/**
|
||||
* @brief Get field cid from event MESH_SUBEVENT_CONFIGURATION_COMPOSITION_DATA
|
||||
* @param event packet
|
||||
* @return cid
|
||||
* @note: btstack_type 2
|
||||
*/
|
||||
uint16_t mesh_subevent_configuration_composition_data_get_cid(const uint8_t * event);
|
||||
|
||||
/**
|
||||
* @brief Get field pid from event MESH_SUBEVENT_CONFIGURATION_COMPOSITION_DATA
|
||||
* @param event packet
|
||||
* @return pid
|
||||
* @note: btstack_type 2
|
||||
*/
|
||||
uint16_t mesh_subevent_configuration_composition_data_get_pid(const uint8_t * event);
|
||||
|
||||
/**
|
||||
* @brief Get field vid from event MESH_SUBEVENT_CONFIGURATION_COMPOSITION_DATA
|
||||
* @param event packet
|
||||
* @return vid
|
||||
* @note: btstack_type 2
|
||||
*/
|
||||
uint16_t mesh_subevent_configuration_composition_data_get_vid(const uint8_t * event);
|
||||
|
||||
/**
|
||||
* @brief Get field crpl from event MESH_SUBEVENT_CONFIGURATION_COMPOSITION_DATA
|
||||
* @param event packet
|
||||
* @return crpl
|
||||
* @note: btstack_type 2
|
||||
*/
|
||||
uint16_t mesh_subevent_configuration_composition_data_get_crpl(const uint8_t * event);
|
||||
|
||||
/**
|
||||
* @brief Get field features from event MESH_SUBEVENT_CONFIGURATION_COMPOSITION_DATA
|
||||
* @param event packet
|
||||
* @return features
|
||||
* @note: btstack_type 2
|
||||
*/
|
||||
uint16_t mesh_subevent_configuration_composition_data_get_features(const uint8_t * event);
|
||||
|
||||
/**
|
||||
* @brief Get number elements from event MESH_SUBEVENT_CONFIGURATION_COMPOSITION_DATA
|
||||
**/
|
||||
uint16_t mesh_subevent_configuration_composition_data_get_num_elements(const uint8_t * event, uint16_t size);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Register packet handler
|
||||
* @param configuration_client_model
|
||||
@ -176,36 +230,6 @@ uint8_t mesh_configuration_client_send_beacon_set(mesh_model_t * mesh_model, uin
|
||||
*/
|
||||
uint8_t mesh_configuration_client_send_composition_data_get(mesh_model_t * mesh_model, uint16_t dest, uint16_t netkey_index, uint16_t appkey_index, uint8_t page);
|
||||
|
||||
/**
|
||||
* @brief Get field cid from event MESH_SUBEVENT_CONFIGURATION_COMPOSITION_DATA
|
||||
**/
|
||||
uint8_t mesh_subevent_configuration_composition_data_get_cid(const uint8_t * event);
|
||||
|
||||
/**
|
||||
* @brief Get field pid from event MESH_SUBEVENT_CONFIGURATION_COMPOSITION_DATA
|
||||
**/
|
||||
uint8_t mesh_subevent_configuration_composition_data_get_pid(const uint8_t * event);
|
||||
|
||||
/**
|
||||
* @brief Get field vid from event MESH_SUBEVENT_CONFIGURATION_COMPOSITION_DATA
|
||||
**/
|
||||
uint8_t mesh_subevent_configuration_composition_data_get_vid(const uint8_t * event);
|
||||
|
||||
/**
|
||||
* @brief Get field crpl from event MESH_SUBEVENT_CONFIGURATION_COMPOSITION_DATA
|
||||
**/
|
||||
uint8_t mesh_subevent_configuration_composition_data_get_crpl(const uint8_t * event);
|
||||
|
||||
/**
|
||||
* @brief Get field features from event MESH_SUBEVENT_CONFIGURATION_COMPOSITION_DATA
|
||||
**/
|
||||
uint8_t mesh_subevent_configuration_composition_data_get_features(const uint8_t * event);
|
||||
|
||||
/**
|
||||
* @brief Get number elements from event MESH_SUBEVENT_CONFIGURATION_COMPOSITION_DATA
|
||||
**/
|
||||
uint16_t mesh_subevent_configuration_composition_data_get_num_elements(const uint8_t * event, uint16_t size);
|
||||
|
||||
/**
|
||||
* @brief Get the current Default TTL state of a node
|
||||
* @param mesh_model
|
||||
|
5
test/mesh/.gitignore
vendored
5
test/mesh/.gitignore
vendored
@ -1,4 +1,4 @@
|
||||
mesh_pts
|
||||
mesh_configuration_composition_data_message_test
|
||||
mesh_message_test
|
||||
mesh_provisioning_device
|
||||
mesh_provisioning_device.h
|
||||
@ -6,8 +6,9 @@ mesh_proxy_device
|
||||
mesh_proxy_device.h
|
||||
mesh_proxy_server
|
||||
mesh_proxy_server.h
|
||||
mesh_pts
|
||||
mesh_pts.h
|
||||
provisioner
|
||||
provisioning_device_test
|
||||
provisioning_provisioner_test
|
||||
sniffer
|
||||
mesh_pts.h
|
||||
|
@ -24,7 +24,7 @@ CORE += \
|
||||
l2cap.c \
|
||||
uECC.c \
|
||||
rijndael.c \
|
||||
main.c \
|
||||
|
||||
|
||||
|
||||
# examples
|
||||
@ -59,16 +59,16 @@ LDFLAGS += $(shell pkg-config libusb-1.0 --libs)
|
||||
LDFLAGS += -lCppUTest -lCppUTestExt
|
||||
|
||||
|
||||
mesh_pts: mesh_pts.h ${CORE_OBJ} ${COMMON_OBJ} ${ATT_OBJ} ${GATT_SERVER_OBJ} ${SM_OBJ} ${MESH_OBJ} mesh_pts.o
|
||||
mesh_pts: mesh_pts.h ${CORE_OBJ} ${COMMON_OBJ} ${ATT_OBJ} ${GATT_SERVER_OBJ} ${SM_OBJ} ${MESH_OBJ} main.o mesh_pts.o
|
||||
${CC} $(filter-out mesh_pts.h,$^) ${CFLAGS} ${LDFLAGS} -o $@
|
||||
|
||||
provisioner: ${CORE_OBJ} ${COMMON_OBJ} ${ATT_OBJ} ${SM_OBJ} pb_adv.o mesh_crypto.o provisioning_provisioner.o mesh_keys.o mesh_foundation.o mesh_network.o provisioner.o
|
||||
provisioner: ${CORE_OBJ} ${COMMON_OBJ} ${ATT_OBJ} ${SM_OBJ} main.o pb_adv.o mesh_crypto.o provisioning_provisioner.o mesh_keys.o mesh_foundation.o mesh_network.o provisioner.o
|
||||
${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@
|
||||
|
||||
mesh_message_test: mesh_message_test.cpp mesh_foundation.o mesh_node.o mesh_iv_index_seq_number.o mesh_network.o mesh_peer.o mesh_lower_transport.o mesh_upper_transport.o mesh_virtual_addresses.o mesh_keys.o mesh_crypto.o btstack_memory.o btstack_memory_pool.o btstack_util.o btstack_crypto.o btstack_linked_list.o hci_dump.o uECC.o mock.o rijndael.o hci_cmd.o
|
||||
g++ $^ ${CFLAGS} ${LDFLAGS} -o $@
|
||||
|
||||
sniffer: ${CORE_OBJ} ${COMMON_OBJ} ${ATT_OBJ} ${SM_OBJ} mesh_keys.o mesh_network.o mesh_foundation.o sniffer.c
|
||||
sniffer: ${CORE_OBJ} ${COMMON_OBJ} ${ATT_OBJ} ${SM_OBJ} main.o mesh_keys.o mesh_network.o mesh_foundation.o sniffer.c
|
||||
${CC} $^ ${CFLAGS} ${LDFLAGS} -o $@
|
||||
|
||||
provisioning_device_test: provisioning_device_test.cpp uECC.o mesh_crypto.o provisioning_device.o btstack_crypto.o btstack_util.o btstack_linked_list.o mesh_node.o mock.o rijndael.o hci_cmd.o hci_dump.o
|
||||
@ -77,8 +77,10 @@ provisioning_device_test: provisioning_device_test.cpp uECC.o mesh_crypto.o prov
|
||||
provisioning_provisioner_test: provisioning_provisioner_test.cpp uECC.o mesh_crypto.o provisioning_provisioner.o btstack_crypto.o btstack_util.o btstack_linked_list.o mock.o rijndael.o hci_cmd.o hci_dump.o
|
||||
${CC_UNIT} ${CFLAGS} ${LDFLAGS} $^ -lCppUTest -lCppUTestExt -o $@
|
||||
|
||||
mesh_configuration_composition_data_message_test: ${CORE_OBJ} ${COMMON_OBJ} ${ATT_OBJ} ${MESH_OBJ} mesh_configuration_composition_data_message_test.cpp
|
||||
${CC_UNIT} ${CFLAGS} ${LDFLAGS} $^ -lCppUTest -lCppUTestExt -o $@
|
||||
|
||||
EXAMPLES = mesh_pts provisioner sniffer provisioning_device_test provisioning_provisioner_test mesh_message_test
|
||||
EXAMPLES = mesh_pts provisioner sniffer provisioning_device_test provisioning_provisioner_test mesh_message_test mesh_configuration_composition_data_message_test
|
||||
|
||||
all: ${EXAMPLES}
|
||||
|
||||
|
118
test/mesh/mesh_configuration_composition_data_message_test.cpp
Normal file
118
test/mesh/mesh_configuration_composition_data_message_test.cpp
Normal file
@ -0,0 +1,118 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "CppUTest/TestHarness.h"
|
||||
#include "CppUTest/CommandLineTestRunner.h"
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "CppUTest/TestHarness.h"
|
||||
#include "CppUTest/CommandLineTestRunner.h"
|
||||
|
||||
#include "btstack_util.h"
|
||||
#include "bluetooth.h"
|
||||
#include "mesh/mesh_configuration_client.h"
|
||||
|
||||
static uint8_t composition_data_valid_elements[] = {
|
||||
// header
|
||||
HCI_EVENT_MESH_META, 0x21, MESH_SUBEVENT_CONFIGURATION_COMPOSITION_DATA, 0xff, 0xee, 0x00,
|
||||
// page
|
||||
0x00,
|
||||
// cid, pid, vid, crpl, feature
|
||||
0x11, 0x10, 0x22, 0x20, 0x33, 0x30, 0x44, 0x40, 0x55, 0x50,
|
||||
|
||||
// loc (2), num SIG models(1), num vendor models(1)
|
||||
0xBB, 0xAA, 0x03, 0x02,
|
||||
// SIG models
|
||||
0x10, 0x11, 0x20, 0x22, 0x30, 0x33,
|
||||
// Vendor models
|
||||
0xa2, 0xa1, 0xa4, 0xa3,
|
||||
0xb2, 0xb1, 0xb4, 0xb3
|
||||
};
|
||||
|
||||
static uint8_t composition_data_no_models[] = {
|
||||
// header
|
||||
HCI_EVENT_MESH_META, 0x21, MESH_SUBEVENT_CONFIGURATION_COMPOSITION_DATA, 0xff, 0xee, 0x00,
|
||||
// page
|
||||
0x00,
|
||||
// cid, pid, vid, crpl, feature
|
||||
0x11, 0x10, 0x22, 0x20, 0x33, 0x30, 0x44, 0x40, 0x55, 0x50,
|
||||
|
||||
// loc (2), num SIG models(1), num vendor models(1)
|
||||
0xBB, 0xAA, 0x00, 0x00
|
||||
};
|
||||
|
||||
static uint8_t composition_data_invalid[] = {
|
||||
// header
|
||||
HCI_EVENT_MESH_META, 0x21, MESH_SUBEVENT_CONFIGURATION_COMPOSITION_DATA, 0xff, 0xee, 0x00
|
||||
};
|
||||
|
||||
TEST_GROUP(CompositionData){
|
||||
mesh_composite_data_iterator_t it;
|
||||
int expected_num_elements;
|
||||
int expected_num_sig_models;
|
||||
int expected_num_vendor_models;
|
||||
|
||||
void setup(void){
|
||||
}
|
||||
|
||||
void composition_data_validate(const uint8_t * elements, uint16_t elements_size){
|
||||
int num_elements = 0;
|
||||
int num_sig_models = 0;
|
||||
int num_vendor_models = 0;
|
||||
mesh_composition_data_iterator_init(&it, elements, elements_size);
|
||||
while (mesh_composition_data_iterator_has_next_element(&it)){
|
||||
num_elements++;
|
||||
mesh_composition_data_iterator_next_element(&it);
|
||||
CHECK_EQUAL(0xAABB, mesh_composition_data_iterator_element_loc(&it));
|
||||
|
||||
while (mesh_composition_data_iterator_has_next_sig_model(&it)){
|
||||
num_sig_models++;
|
||||
mesh_composition_data_iterator_next_sig_model(&it);
|
||||
}
|
||||
while (mesh_composition_data_iterator_has_next_vendor_model(&it)){
|
||||
num_vendor_models++;
|
||||
mesh_composition_data_iterator_next_vendor_model(&it);
|
||||
}
|
||||
}
|
||||
|
||||
CHECK_EQUAL(expected_num_elements, num_elements);
|
||||
CHECK_EQUAL(expected_num_sig_models, num_sig_models);
|
||||
CHECK_EQUAL(expected_num_vendor_models, num_vendor_models);
|
||||
}
|
||||
};
|
||||
|
||||
TEST(CompositionData, CompositionDataEventHeader){
|
||||
CHECK_EQUAL(0, mesh_subevent_configuration_composition_data_get_page(composition_data_valid_elements));
|
||||
CHECK_EQUAL(0x1011, mesh_subevent_configuration_composition_data_get_cid(composition_data_valid_elements));
|
||||
CHECK_EQUAL(0x2022, mesh_subevent_configuration_composition_data_get_pid(composition_data_valid_elements));
|
||||
CHECK_EQUAL(0x3033, mesh_subevent_configuration_composition_data_get_vid(composition_data_valid_elements));
|
||||
CHECK_EQUAL(0x4044, mesh_subevent_configuration_composition_data_get_crpl(composition_data_valid_elements));
|
||||
CHECK_EQUAL(0x5055, mesh_subevent_configuration_composition_data_get_features(composition_data_valid_elements));
|
||||
}
|
||||
|
||||
TEST(CompositionData, CompositionDataElementsValid){
|
||||
expected_num_elements = 1;
|
||||
expected_num_sig_models = 3;
|
||||
expected_num_vendor_models = 2;
|
||||
composition_data_validate(composition_data_valid_elements, sizeof(composition_data_valid_elements));
|
||||
}
|
||||
|
||||
TEST(CompositionData, CompositionDataElementsNoModels){
|
||||
expected_num_elements = 1;
|
||||
expected_num_sig_models = 0;
|
||||
expected_num_vendor_models = 0;
|
||||
composition_data_validate(composition_data_no_models, sizeof(composition_data_no_models));
|
||||
}
|
||||
|
||||
TEST(CompositionData, CompositionDataElementsInvalid){
|
||||
expected_num_elements = 0;
|
||||
expected_num_sig_models = 0;
|
||||
expected_num_vendor_models = 0;
|
||||
composition_data_validate(composition_data_invalid, sizeof(composition_data_invalid));
|
||||
}
|
||||
|
||||
int main (int argc, const char * argv[]){
|
||||
return CommandLineTestRunner::RunAllTests(argc, argv);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user