From 3927ae8ee1c4aeec62121322fcf66681b77c85bf Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Mon, 4 Sep 2023 15:04:37 -0500 Subject: [PATCH] Update: Replace f_fss_simple_packet_identify() with f_fss_simple_packet_extract() and f_fss_simple_packet_extract_range(). The implementation of f_fss_simple_packet_identify() appears to be some sort of hybrid between actual code and brainstorming. This appears to be by accident and the resulting logic of the function is nonsense. Fix the logic in f_fss_simple_packet_identify(). I also see no reason to perform an identify call. The FSS Packet design is so simple that I could just add 1, 4, or 5 to determine any of the parts. Therefore, instead implement f_fss_simple_packet_extract() and f_fss_simple_packet_extract_range() to extract the Control bits and the Size integer. The Payload part is not extracted but for the f_fss_simple_packet_extract_range(), the range for the Payload is determined. This allows for the caller to determine how they want to manage the memory allocation. This is a case where object-oriented would shine had I used C++ or some other object-oriented language. I don't have this option available and so I am going to only have f_fss_simple_packet_t and f_fss_simple_packet_range_t with their respective f_fss_simple_packet_extract() and f_fss_simple_packet_extract_range() functions. Unit tests are now provided for these two new functions. --- build/stand_alone/fake.config.h | 3 +- level_0/f_fss/c/fss/simple_packet.c | 115 ++++++++++++++------- level_0/f_fss/c/fss/simple_packet.h | 59 ++++++++--- level_0/f_fss/data/build/settings-tests | 1 + .../tests/unit/c/test-fss-simple_packet_delete.h | 2 +- .../tests/unit/c/test-fss-simple_packet_destroy.h | 2 +- .../tests/unit/c/test-fss-simple_packet_extract.c | 98 ++++++++++++++++++ .../tests/unit/c/test-fss-simple_packet_extract.h | 41 ++++++++ .../unit/c/test-fss-simple_packet_extract_range.c | 98 ++++++++++++++++++ .../unit/c/test-fss-simple_packet_extract_range.h | 41 ++++++++ .../c/test-fss-simple_packets_delete_callback.h | 2 +- .../c/test-fss-simple_packets_destroy_callback.h | 2 +- .../c/test-fss-simple_packetss_delete_callback.h | 2 +- .../c/test-fss-simple_packetss_destroy_callback.h | 2 +- level_0/f_fss/tests/unit/c/test-fss.c | 11 ++ level_0/f_fss/tests/unit/c/test-fss.h | 2 + 16 files changed, 423 insertions(+), 58 deletions(-) create mode 100644 level_0/f_fss/tests/unit/c/test-fss-simple_packet_extract.c create mode 100644 level_0/f_fss/tests/unit/c/test-fss-simple_packet_extract.h create mode 100644 level_0/f_fss/tests/unit/c/test-fss-simple_packet_extract_range.c create mode 100644 level_0/f_fss/tests/unit/c/test-fss-simple_packet_extract_range.h diff --git a/build/stand_alone/fake.config.h b/build/stand_alone/fake.config.h index dd517cb..ccbb1fd 100644 --- a/build/stand_alone/fake.config.h +++ b/build/stand_alone/fake.config.h @@ -586,7 +586,8 @@ #define _di_f_fss_simple_packet_d_ #define _di_f_fss_simple_packet_delete_ #define _di_f_fss_simple_packet_destroy_ -#define _di_f_fss_simple_packet_identify_ +#define _di_f_fss_simple_packet_extract_ +#define _di_f_fss_simple_packet_extract_range_ #define _di_f_fss_simple_packet_ranges_append_ #define _di_f_fss_simple_packet_ranges_append_all_ #define _di_f_fss_simple_packet_rangess_append_ diff --git a/level_0/f_fss/c/fss/simple_packet.c b/level_0/f_fss/c/fss/simple_packet.c index efb57a8..e73cd30 100644 --- a/level_0/f_fss/c/fss/simple_packet.c +++ b/level_0/f_fss/c/fss/simple_packet.c @@ -34,57 +34,100 @@ extern "C" { } #endif // _di_f_fss_simple_packet_destroy_ -#ifndef _di_f_fss_simple_packet_identify_ - f_status_t f_fss_simple_packet_identify(const f_string_static_t buffer, f_fss_simple_packet_range_t * const range) { +#ifndef _di_f_fss_simple_packet_extract_ + f_status_t f_fss_simple_packet_extract(const f_string_static_t buffer, f_fss_simple_packet_t * const packet) { #ifndef _di_level_0_parameter_checking_ - if (!range) return F_status_set_error(F_parameter); + if (!packet) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (!buffer.used) return F_data_not; + if (buffer.used < F_fss_simple_packet_block_header_size_d) return F_packet_too_small; - range->control.start = 1; - range->control.stop = 0; + packet->control = (uint8_t) buffer.string[0]; - range->size.start = 1; - range->size.stop = 0; - - range->payload.start = 1; - range->payload.stop = 0; - - if (buffer.used < F_fss_simple_packet_block_control_size_d) return F_partial; - - range->control.start = 0; - range->control.stop = 0; + #ifdef _is_F_endian_little + // Big Endian. + if (packet->control & F_fss_simple_packet_endian_d) { + packet->size = ((uint8_t) buffer.string[1]); + packet->size += ((uint8_t) buffer.string[2]) << 8; + packet->size += ((uint8_t) buffer.string[3]) << 16; + packet->size += ((uint8_t) buffer.string[4]) << 24; + } + // Little Endian. + else { + packet->size = ((uint8_t) buffer.string[1]) << 24; + packet->size += ((uint8_t) buffer.string[2]) << 16; + packet->size += ((uint8_t) buffer.string[3]) << 8; + packet->size += ((uint8_t) buffer.string[4]); + } + #else + // Big Endian. + if (packet->control & F_fss_simple_packet_endian_d) { + packet->size = ((uint8_t) buffer.string[1]) << 24; + packet->size += ((uint8_t) buffer.string[2]) << 16; + packet->size += ((uint8_t) buffer.string[3]) << 8; + packet->size += ((uint8_t) buffer.string[4]); + } + // Little Endian. + else { + packet->size = ((uint8_t) buffer.string[1]); + packet->size += ((uint8_t) buffer.string[2]) << 8; + packet->size += ((uint8_t) buffer.string[3]) << 16; + packet->size += ((uint8_t) buffer.string[4]) << 24; + } + #endif // _is_F_endian_little - if (buffer.used < F_fss_simple_packet_block_header_size_d) return F_partial; + return F_okay; + } +#endif // _di_f_fss_simple_packet_extract_ - range->size.start = 1; - range->size.stop = F_fss_simple_packet_block_size_size_d; +#ifndef _di_f_fss_simple_packet_extract_range_ + f_status_t f_fss_simple_packet_extract_range(const f_string_static_t buffer, f_fss_simple_packet_range_t * const packet) { + #ifndef _di_f_fss_simple_packet_extract_range_ + if (!packet) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ - // The Payload Block can be NULL and if it is, then all values of the Size Block must be of size F_fss_simple_packet_block_header_size_d. - if (buffer.used == F_fss_simple_packet_block_size_size_d) { + if (buffer.used < F_fss_simple_packet_block_header_size_d) return F_packet_too_small; - // Big endian. - if (buffer.string[0] & F_fss_simple_packet_endian_d) { - if (buffer.string[2] || buffer.string[3] || !buffer.string[4]) return F_partial; - if (buffer.string[1] < F_fss_simple_packet_block_header_size_d) return F_status_set_error(F_valid_not); + packet->control = (uint8_t) buffer.string[0]; - return (buffer.string[1] == F_fss_simple_packet_block_header_size_d) ? F_okay : F_partial; + #ifdef _is_F_endian_little + // Big Endian. + if (packet->control & F_fss_simple_packet_endian_d) { + packet->size = ((uint8_t) buffer.string[1]); + packet->size += ((uint8_t) buffer.string[2]) << 8; + packet->size += ((uint8_t) buffer.string[3]) << 16; + packet->size += ((uint8_t) buffer.string[4]) << 24; } + // Little Endian. + else { + packet->size = ((uint8_t) buffer.string[1]) << 24; + packet->size += ((uint8_t) buffer.string[2]) << 16; + packet->size += ((uint8_t) buffer.string[3]) << 8; + packet->size += ((uint8_t) buffer.string[4]); + } + #else + // Big Endian. + if (packet->control & F_fss_simple_packet_endian_d) { + packet->size = ((uint8_t) buffer.string[1]) << 24; + packet->size += ((uint8_t) buffer.string[2]) << 16; + packet->size += ((uint8_t) buffer.string[3]) << 8; + packet->size += ((uint8_t) buffer.string[4]); + } + // Little Endian. + else { + packet->size = ((uint8_t) buffer.string[1]); + packet->size += ((uint8_t) buffer.string[2]) << 8; + packet->size += ((uint8_t) buffer.string[3]) << 16; + packet->size += ((uint8_t) buffer.string[4]) << 24; + } + #endif // _is_F_endian_little - // Little endian. - if (!buffer.string[1] || buffer.string[2] || buffer.string[3]) return F_partial; - if (buffer.string[4] < F_fss_simple_packet_block_header_size_d) return F_status_set_error(F_valid_not); - - return (buffer.string[4] == F_fss_simple_packet_block_header_size_d) ? F_okay : F_partial; - } - - range->payload.start = F_fss_simple_packet_block_header_size_d; - range->payload.stop = (buffer.used - F_fss_simple_packet_block_header_size_d < F_fss_simple_packet_block_payload_size_d) ? buffer.used - 1 : F_fss_simple_packet_block_payload_size_d - 1; + packet->payload.start = F_fss_simple_packet_block_header_size_d; + packet->payload.stop = (buffer.used - F_fss_simple_packet_block_header_size_d < F_fss_simple_packet_block_payload_size_d) ? buffer.used - 1 : F_fss_simple_packet_block_payload_size_d - 1; return F_okay; } -#endif // _di_f_fss_simple_packet_identify_ +#endif // _di_f_fss_simple_packet_extract_range_ #ifndef _di_f_fss_simple_packets_delete_callback_ f_status_t f_fss_simple_packets_delete_callback(const f_number_unsigned_t start, const f_number_unsigned_t stop, void * const void_array) { diff --git a/level_0/f_fss/c/fss/simple_packet.h b/level_0/f_fss/c/fss/simple_packet.h index 4ad7516..1ca285b 100644 --- a/level_0/f_fss/c/fss/simple_packet.h +++ b/level_0/f_fss/c/fss/simple_packet.h @@ -94,7 +94,7 @@ extern "C" { #endif // _di_f_fss_simple_packets_t_ /** - * This holds an array of f_fss_simple_packets_t. + * A packet header, where the payload is stored as a string. * * Properties: * - array: An array of f_fss_simple_packets_t. @@ -118,7 +118,7 @@ extern "C" { #endif // _di_f_fss_simple_packetss_t_ /** - * A set of string ranges intending to designate the different ranges for a Simple Packet representing each Block. + * A packet header, where the payload is represented by a range. * * Properties: * - control: The Control Block, which is 1 byte long. @@ -127,14 +127,14 @@ extern "C" { */ #ifndef _di_f_fss_simple_packet_range_t_ typedef struct { - f_string_range_t control; - f_string_range_t size; + uint8_t control; + uint32_t size; f_string_range_t payload; } f_fss_simple_packet_range_t; #define f_fss_simple_packet_range_t_initialize { \ - f_string_range_t_initialize, \ - f_string_range_t_initialize, \ + 0, \ + 0, \ f_string_range_t_initialize, \ } @@ -143,6 +143,12 @@ extern "C" { size, \ payload, \ } + + #define macro_f_fss_simple_packet_range_t_initialize_2(payload) { \ + 0, \ + 0, \ + payload, \ + } #endif // _di_f_fss_simple_packet_range_t_ /** @@ -236,26 +242,49 @@ extern "C" { #endif // _di_f_fss_simple_packet_destroy_ /** - * Identify the ranges representing the different parts of the FSS-000F (Simple Packet). + * Extract the different parts of the FSS-000F (Simple Packet) string into a packet structure. + * + * The buffer is processed as binary data, therefore, NULL and other control data are considered valid data and are not ignored. + * + * @param buffer + * The string buffer to identify the packet ranges of. + * This buffer is considered binary data and so any NULL found within is treated as a valid part of the buffer. + * @param packet + * The packet extracted from the given buffer, without doing anything to the payload. + * The caller can allocate the payload and extract it at any time by just selecting the string from F_fss_simple_packet_block_header_size_d until at most F_fss_simple_packet_block_payload_size_d. + * + * @return + * F_okay on success (The end of the Payload Block is assumed to be the remainder of the buffer or F_fss_simple_packet_block_payload_size_d, whichever is smaller). + * F_packet_too_small if the buffer.used is smaller than the minimum size of the packet. + * + * F_parameter (with error bit) if a parameter is invalid. + * F_valid_not (with error bit) if the data is invalid, which generally only happens when the value of the Size block is less than 5 (and when not returning F_partial). + */ +#ifndef _di_f_fss_simple_packet_extract_ + extern f_status_t f_fss_simple_packet_extract(const f_string_static_t buffer, f_fss_simple_packet_t * const packet); +#endif // _di_f_fss_simple_packet_extract_ + +/** + * Extract the different parts of the FSS-000F (Simple Packet) string into a packet range structure. + * + * The buffer is processed as binary data, therefore, NULL and other control data are considered valid data and are not ignored. * * @param buffer * The string buffer to identify the packet ranges of. * This buffer is considered binary data and so any NULL found within is treated as a valid part of the buffer. - * @param range - * The set of blocks, each representing a range within the buffer. - * If the buffer is too small (including when F_data_not is returned), then the ranges are all set to the out of range values as appropriate. + * @param packet + * The packet range extracted from the given buffer, with the payload being represented by a range. * * @return * F_okay on success (The end of the Payload Block is assumed to be the remainder of the buffer or F_fss_simple_packet_block_payload_size_d, whichever is smaller). - * F_partial on success but not all blocks are identified. - * F_data_not if buffer.used is 0. + * F_packet_too_small if the buffer.used is smaller than the minimum size of the packet. * * F_parameter (with error bit) if a parameter is invalid. * F_valid_not (with error bit) if the data is invalid, which generally only happens when the value of the Size block is less than 5 (and when not returning F_partial). */ -#ifndef _di_f_fss_simple_packet_identify_ - extern f_status_t f_fss_simple_packet_identify(const f_string_static_t buffer, f_fss_simple_packet_range_t * const range); -#endif // _di_f_fss_simple_packet_identify_ +#ifndef _di_f_fss_simple_packet_extract_range_ + extern f_status_t f_fss_simple_packet_extract_range(const f_string_static_t buffer, f_fss_simple_packet_range_t * const packet); +#endif // _di_f_fss_simple_packet_extract_range_ /** * A callback intended to be passed to f_memory_arrays_resize() for an f_fss_simple_packets_t structure. diff --git a/level_0/f_fss/data/build/settings-tests b/level_0/f_fss/data/build/settings-tests index 0ea8923..18ed23a 100644 --- a/level_0/f_fss/data/build/settings-tests +++ b/level_0/f_fss/data/build/settings-tests @@ -36,6 +36,7 @@ build_sources_program test-fss-set_delete.c test-fss-set_destroy.c build_sources_program test-fss-sets_delete_callback.c test-fss-sets_destroy_callback.c test-fss-setss_delete_callback.c test-fss-setss_destroy_callback.c build_sources_program test-fss-set_quote_delete.c test-fss-set_quote_destroy.c build_sources_program test-fss-set_quotes_delete_callback.c test-fss-set_quotes_destroy_callback.c test-fss-set_quotess_delete_callback.c test-fss-set_quotess_destroy_callback.c +build_sources_program test-fss-simple_packet_extract.c test-fss-simple_packet_extract_range.c build_sources_program test-fss-simple_packet_delete.c test-fss-simple_packet_destroy.c build_sources_program test-fss-simple_packets_delete_callback.c test-fss-simple_packets_destroy_callback.c test-fss-simple_packetss_delete_callback.c test-fss-simple_packetss_destroy_callback.c diff --git a/level_0/f_fss/tests/unit/c/test-fss-simple_packet_delete.h b/level_0/f_fss/tests/unit/c/test-fss-simple_packet_delete.h index 638a4b1..5a0271c 100644 --- a/level_0/f_fss/tests/unit/c/test-fss-simple_packet_delete.h +++ b/level_0/f_fss/tests/unit/c/test-fss-simple_packet_delete.h @@ -5,7 +5,7 @@ * API Version: 0.7 * Licenses: lgpl-2.1-or-later * - * Test the array types in the type project. + * Test the array types in the FSS project. */ #ifndef _TEST__F_fss__simple_packet_delete #define _TEST__F_fss__simple_packet_delete diff --git a/level_0/f_fss/tests/unit/c/test-fss-simple_packet_destroy.h b/level_0/f_fss/tests/unit/c/test-fss-simple_packet_destroy.h index 65cce64..4c15c93 100644 --- a/level_0/f_fss/tests/unit/c/test-fss-simple_packet_destroy.h +++ b/level_0/f_fss/tests/unit/c/test-fss-simple_packet_destroy.h @@ -5,7 +5,7 @@ * API Version: 0.7 * Licenses: lgpl-2.1-or-later * - * Test the array types in the type project. + * Test the array types in the FSS project. */ #ifndef _TEST__F_fss__simple_packet_destroy #define _TEST__F_fss__simple_packet_destroy diff --git a/level_0/f_fss/tests/unit/c/test-fss-simple_packet_extract.c b/level_0/f_fss/tests/unit/c/test-fss-simple_packet_extract.c new file mode 100644 index 0000000..b9cab6e --- /dev/null +++ b/level_0/f_fss/tests/unit/c/test-fss-simple_packet_extract.c @@ -0,0 +1,98 @@ +#include "test-fss.h" +#include "test-fss-simple_packet_extract.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_fss_simple_packet_extract__parameter_checking(void **state) { + + { + const f_status_t status = f_fss_simple_packet_extract(f_string_empty_s, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_fss_simple_packet_extract__returns_packet_too_small(void **state) { + + f_string_static_t test = macro_f_string_static_t_initialize_1("testing", 0, 0); + f_fss_simple_packet_t packet = f_fss_simple_packet_t_initialize; + + { + for (test.used = 0; test.used < F_fss_simple_packet_block_header_size_d; ++test.used) { + + const f_status_t status = f_fss_simple_packet_extract(f_string_empty_s, &packet); + + assert_int_equal(status, F_packet_too_small); + } // for + } +} + +void test__f_fss_simple_packet_extract__works_big_endian(void **state) { + + f_char_t string_1[] = { 0x80, 0x05, 0x00, 0x00, 0x00 }; + f_char_t string_2[] = { 0x80, 0x06, 0x00, 0x00, 0x00, 0x01 }; + f_char_t string_3[] = { 0x80, 0x07, 0x00, 0x00, 0x00, 0x01, 0x02 }; + + const f_string_static_t datas[] = { + macro_f_string_static_t_initialize_1(string_1, 0, 5 ), + macro_f_string_static_t_initialize_1(string_2, 0, 6 ), + macro_f_string_static_t_initialize_1(string_3, 0, 7 ), + }; + + const f_number_unsigned_t size[] = { + 5, + 6, + 7, + }; + + { + for (uint8_t i = 0; i < 3; ++i) { + + f_fss_simple_packet_t packet = f_fss_simple_packet_t_initialize; + + const f_status_t status = f_fss_simple_packet_extract(datas[i], &packet); + + assert_int_equal(status, F_okay); + assert_int_equal(packet.control & F_fss_simple_packet_endian_d, F_fss_simple_packet_endian_d); + assert_int_equal(packet.size, size[i]); + } // for + } +} + +void test__f_fss_simple_packet_extract__works_little_endian(void **state) { + + f_char_t string_1[] = { 0x00, 0x00, 0x00, 0x00, 0x05 }; + f_char_t string_2[] = { 0x00, 0x00, 0x00, 0x00, 0x06, 0x01 }; + f_char_t string_3[] = { 0x00, 0x00, 0x00, 0x00, 0x07, 0x01, 0x02 }; + + const f_string_static_t datas[] = { + macro_f_string_static_t_initialize_1(string_1, 0, 5 ), + macro_f_string_static_t_initialize_1(string_2, 0, 6 ), + macro_f_string_static_t_initialize_1(string_3, 0, 7 ), + }; + + const f_number_unsigned_t size[] = { + 5, + 6, + 7, + }; + + { + for (uint8_t i = 0; i < 3; ++i) { + + f_fss_simple_packet_t packet = f_fss_simple_packet_t_initialize; + + const f_status_t status = f_fss_simple_packet_extract(datas[i], &packet); + + assert_int_equal(status, F_okay); + assert_int_equal(packet.control & F_fss_simple_packet_endian_d, 0); + assert_int_equal(packet.size, size[i]); + } // for + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_fss/tests/unit/c/test-fss-simple_packet_extract.h b/level_0/f_fss/tests/unit/c/test-fss-simple_packet_extract.h new file mode 100644 index 0000000..6a2e014 --- /dev/null +++ b/level_0/f_fss/tests/unit/c/test-fss-simple_packet_extract.h @@ -0,0 +1,41 @@ +/** + * FLL - Level 0 + * + * Project: FSS + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Test the array types in the FSS project. + */ +#ifndef _TEST__F_fss__simple_packet_extract +#define _TEST__F_fss__simple_packet_extract + +/** + * Test that the function correctly fails on invalid parameter. + * + * @see f_fss_simple_packet_extract() + */ +extern void test__f_fss_simple_packet_extract__parameter_checking(void **state); + +/** + * Test that the function returns F_packet_too_small. + * + * @see f_fss_simple_packet_extract() + */ +extern void test__f_fss_simple_packet_extract__returns_packet_too_small(void **state); + +/** + * Test that the function works, with the control bit set to big endian. + * + * @see f_fss_simple_packet_extract() + */ +extern void test__f_fss_simple_packet_extract__works_big_endian(void **state); + +/** + * Test that the function works, with the control bit set to little endian. + * + * @see f_fss_simple_packet_extract() + */ +extern void test__f_fss_simple_packet_extract__works_little_endian(void **state); + +#endif // _TEST__F_fss__simple_packet_extract diff --git a/level_0/f_fss/tests/unit/c/test-fss-simple_packet_extract_range.c b/level_0/f_fss/tests/unit/c/test-fss-simple_packet_extract_range.c new file mode 100644 index 0000000..ebbda3a --- /dev/null +++ b/level_0/f_fss/tests/unit/c/test-fss-simple_packet_extract_range.c @@ -0,0 +1,98 @@ +#include "test-fss.h" +#include "test-fss-simple_packet_extract_range.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_fss_simple_packet_extract_range__parameter_checking(void **state) { + + { + const f_status_t status = f_fss_simple_packet_extract_range(f_string_empty_s, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + } +} + +void test__f_fss_simple_packet_extract_range__returns_packet_too_small(void **state) { + + f_string_static_t test = macro_f_string_static_t_initialize_1("testing", 0, 0); + f_fss_simple_packet_range_t packet = f_fss_simple_packet_range_t_initialize; + + { + for (test.used = 0; test.used < F_fss_simple_packet_block_header_size_d; ++test.used) { + + const f_status_t status = f_fss_simple_packet_extract_range(f_string_empty_s, &packet); + + assert_int_equal(status, F_packet_too_small); + } // for + } +} + +void test__f_fss_simple_packet_extract_range__works_big_endian(void **state) { + + f_char_t string_1[] = { 0x80, 0x05, 0x00, 0x00, 0x00 }; + f_char_t string_2[] = { 0x80, 0x06, 0x00, 0x00, 0x00, 0x01 }; + f_char_t string_3[] = { 0x80, 0x07, 0x00, 0x00, 0x00, 0x01, 0x02 }; + + const f_string_static_t datas[] = { + macro_f_string_static_t_initialize_1(string_1, 0, 5 ), + macro_f_string_static_t_initialize_1(string_2, 0, 6 ), + macro_f_string_static_t_initialize_1(string_3, 0, 7 ), + }; + + const f_number_unsigned_t size[] = { + 5, + 6, + 7, + }; + + { + for (uint8_t i = 0; i < 3; ++i) { + + f_fss_simple_packet_range_t packet = f_fss_simple_packet_range_t_initialize; + + const f_status_t status = f_fss_simple_packet_extract_range(datas[i], &packet); + + assert_int_equal(status, F_okay); + assert_int_equal(packet.control & F_fss_simple_packet_endian_d, F_fss_simple_packet_endian_d); + assert_int_equal(packet.size, size[i]); + } // for + } +} + +void test__f_fss_simple_packet_extract_range__works_little_endian(void **state) { + + f_char_t string_1[] = { 0x00, 0x00, 0x00, 0x00, 0x05 }; + f_char_t string_2[] = { 0x00, 0x00, 0x00, 0x00, 0x06, 0x01 }; + f_char_t string_3[] = { 0x00, 0x00, 0x00, 0x00, 0x07, 0x01, 0x02 }; + + const f_string_static_t datas[] = { + macro_f_string_static_t_initialize_1(string_1, 0, 5 ), + macro_f_string_static_t_initialize_1(string_2, 0, 6 ), + macro_f_string_static_t_initialize_1(string_3, 0, 7 ), + }; + + const f_number_unsigned_t size[] = { + 5, + 6, + 7, + }; + + { + for (uint8_t i = 0; i < 3; ++i) { + + f_fss_simple_packet_range_t packet = f_fss_simple_packet_range_t_initialize; + + const f_status_t status = f_fss_simple_packet_extract_range(datas[i], &packet); + + assert_int_equal(status, F_okay); + assert_int_equal(packet.control & F_fss_simple_packet_endian_d, 0); + assert_int_equal(packet.size, size[i]); + } // for + } +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_fss/tests/unit/c/test-fss-simple_packet_extract_range.h b/level_0/f_fss/tests/unit/c/test-fss-simple_packet_extract_range.h new file mode 100644 index 0000000..25b1a16 --- /dev/null +++ b/level_0/f_fss/tests/unit/c/test-fss-simple_packet_extract_range.h @@ -0,0 +1,41 @@ +/** + * FLL - Level 0 + * + * Project: FSS + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Test the array types in the FSS project. + */ +#ifndef _TEST__F_fss__simple_packet_extract_range +#define _TEST__F_fss__simple_packet_extract_range + +/** + * Test that the function correctly fails on invalid parameter. + * + * @see f_fss_simple_packet_extract_range() + */ +extern void test__f_fss_simple_packet_extract_range__parameter_checking(void **state); + +/** + * Test that the function returns F_packet_too_small. + * + * @see f_fss_simple_packet_extract_range() + */ +extern void test__f_fss_simple_packet_extract_range__returns_packet_too_small(void **state); + +/** + * Test that the function works, with the control bit set to big endian. + * + * @see f_fss_simple_packet_extract_range() + */ +extern void test__f_fss_simple_packet_extract_range__works_big_endian(void **state); + +/** + * Test that the function works, with the control bit set to little endian. + * + * @see f_fss_simple_packet_extract_range() + */ +extern void test__f_fss_simple_packet_extract_range__works_little_endian(void **state); + +#endif // _TEST__F_fss__simple_packet_extract_range diff --git a/level_0/f_fss/tests/unit/c/test-fss-simple_packets_delete_callback.h b/level_0/f_fss/tests/unit/c/test-fss-simple_packets_delete_callback.h index a6668fe..7cbd47b 100644 --- a/level_0/f_fss/tests/unit/c/test-fss-simple_packets_delete_callback.h +++ b/level_0/f_fss/tests/unit/c/test-fss-simple_packets_delete_callback.h @@ -5,7 +5,7 @@ * API Version: 0.7 * Licenses: lgpl-2.1-or-later * - * Test the array types in the type project. + * Test the array types in the FSS project. */ #ifndef _TEST__F_fss__simple_packets_delete_callback #define _TEST__F_fss__simple_packets_delete_callback diff --git a/level_0/f_fss/tests/unit/c/test-fss-simple_packets_destroy_callback.h b/level_0/f_fss/tests/unit/c/test-fss-simple_packets_destroy_callback.h index 7bfb870..f04f427 100644 --- a/level_0/f_fss/tests/unit/c/test-fss-simple_packets_destroy_callback.h +++ b/level_0/f_fss/tests/unit/c/test-fss-simple_packets_destroy_callback.h @@ -5,7 +5,7 @@ * API Version: 0.7 * Licenses: lgpl-2.1-or-later * - * Test the array types in the type project. + * Test the array types in the FSS project. */ #ifndef _TEST__F_fss__simple_packets_destroy_callback #define _TEST__F_fss__simple_packets_destroy_callback diff --git a/level_0/f_fss/tests/unit/c/test-fss-simple_packetss_delete_callback.h b/level_0/f_fss/tests/unit/c/test-fss-simple_packetss_delete_callback.h index 446e4d7..972cd6d 100644 --- a/level_0/f_fss/tests/unit/c/test-fss-simple_packetss_delete_callback.h +++ b/level_0/f_fss/tests/unit/c/test-fss-simple_packetss_delete_callback.h @@ -5,7 +5,7 @@ * API Version: 0.7 * Licenses: lgpl-2.1-or-later * - * Test the array types in the type project. + * Test the array types in the FSS project. */ #ifndef _TEST__F_fss__simple_packetss_delete_callback #define _TEST__F_fss__simple_packetss_delete_callback diff --git a/level_0/f_fss/tests/unit/c/test-fss-simple_packetss_destroy_callback.h b/level_0/f_fss/tests/unit/c/test-fss-simple_packetss_destroy_callback.h index a43cf37..b856812 100644 --- a/level_0/f_fss/tests/unit/c/test-fss-simple_packetss_destroy_callback.h +++ b/level_0/f_fss/tests/unit/c/test-fss-simple_packetss_destroy_callback.h @@ -5,7 +5,7 @@ * API Version: 0.7 * Licenses: lgpl-2.1-or-later * - * Test the array types in the type project. + * Test the array types in the FSS project. */ #ifndef _TEST__F_fss__simple_packetss_destroy_callback #define _TEST__F_fss__simple_packetss_destroy_callback diff --git a/level_0/f_fss/tests/unit/c/test-fss.c b/level_0/f_fss/tests/unit/c/test-fss.c index 8f2de39..cebf91d 100644 --- a/level_0/f_fss/tests/unit/c/test-fss.c +++ b/level_0/f_fss/tests/unit/c/test-fss.c @@ -129,6 +129,15 @@ int main(void) { cmocka_unit_test(test__f_fss_simple_packetss_delete_callback__works), cmocka_unit_test(test__f_fss_simple_packetss_destroy_callback__works), + cmocka_unit_test(test__f_fss_simple_packet_extract__works_little_endian), + cmocka_unit_test(test__f_fss_simple_packet_extract_range__works_little_endian), + + cmocka_unit_test(test__f_fss_simple_packet_extract__works_big_endian), + cmocka_unit_test(test__f_fss_simple_packet_extract_range__works_big_endian), + + cmocka_unit_test(test__f_fss_simple_packet_extract__returns_packet_too_small), + cmocka_unit_test(test__f_fss_simple_packet_extract_range__returns_packet_too_small), + #ifndef _di_level_0_parameter_checking_ cmocka_unit_test(test__f_fss_apply_delimit__parameter_checking), cmocka_unit_test(test__f_fss_apply_delimit_range__parameter_checking), @@ -161,6 +170,8 @@ int main(void) { cmocka_unit_test(test__f_fss_simple_packet_delete__parameter_checking), cmocka_unit_test(test__f_fss_simple_packet_destroy__parameter_checking), + cmocka_unit_test(test__f_fss_simple_packet_extract__parameter_checking), + cmocka_unit_test(test__f_fss_simple_packet_extract_range__parameter_checking), // f_fss_items_delete_callback() doesn't use parameter checking. // f_fss_items_destroy_callback() doesn't use parameter checking. diff --git a/level_0/f_fss/tests/unit/c/test-fss.h b/level_0/f_fss/tests/unit/c/test-fss.h index 304183c..8c0c0bd 100644 --- a/level_0/f_fss/tests/unit/c/test-fss.h +++ b/level_0/f_fss/tests/unit/c/test-fss.h @@ -67,6 +67,8 @@ #include "test-fss-set_quotes_destroy_callback.h" #include "test-fss-set_quotess_delete_callback.h" #include "test-fss-set_quotess_destroy_callback.h" +#include "test-fss-simple_packet_extract.h" +#include "test-fss-simple_packet_extract_range.h" #include "test-fss-simple_packet_delete.h" #include "test-fss-simple_packet_destroy.h" #include "test-fss-simple_packets_delete_callback.h" -- 1.8.3.1