Commit e60289f2 authored by Daniel Kamil Kozar's avatar Daniel Kamil Kozar Committed by Jean-Paul Saman

add facilities for testing arrays of structs

Signed-off-by: Jean-Paul Saman's avatarJean-Paul Saman <jpsaman@videolan.org>
parent f321f9d2
......@@ -169,5 +169,9 @@
<array name="i_service_name" len_name="i_service_name_length" min_size="0" max_size="126" />
<array name="i_service_provider_name" len_name="i_service_provider_name_length" min_size="0" max_size="126" />
</descriptor>
<descriptor name="service list" sname="service_list" fname="ServiceList">
<array name="i_service" len_name="i_service_count" min_size="1" type="dvbpsi_service_list_service_s" />
</descriptor>
</dr>
......@@ -131,7 +131,14 @@ static int main_<xsl:value-of select="@sname" />_<xsl:value-of select="@msuffix"
BOZO_begin_array(<xsl:value-of select="@name" />, <xsl:value-of select="@len_name" />, <xsl:value-of select="@min_size" />)
BOZO_DOJOB(<xsl:value-of select="../@fname" />);
BOZO_check_array_begin(<xsl:value-of select="@name" />, <xsl:value-of select="@len_name" />)
<xsl:choose>
<xsl:when test="@type">
BOZO_check_array_cmp(<xsl:value-of select="@name" />, <xsl:value-of select="@len_name" />, <xsl:value-of select="@type" />)
</xsl:when>
<xsl:otherwise>
BOZO_check_array_gen(<xsl:value-of select="@name" />, <xsl:value-of select="@len_name" />)
</xsl:otherwise>
</xsl:choose>
BOZO_CLEAN();
<xsl:choose>
<xsl:when test="@max_size">
......
......@@ -472,7 +472,9 @@ static int main_ca_(void)
BOZO_begin_array(i_private_data, i_private_length, 0)
BOZO_DOJOB(CA);
BOZO_check_array_begin(i_private_data, i_private_length)
BOZO_check_array_gen(i_private_data, i_private_length)
BOZO_CLEAN();
BOZO_end_array(i_private_data, ARRAY_SIZE(s_decoded.i_private_data))
......@@ -494,7 +496,9 @@ static int main_iso639_(void)
BOZO_begin_array(code, i_code_count, 1)
BOZO_DOJOB(ISO639);
BOZO_check_array_begin(code, i_code_count)
BOZO_check_array_gen(code, i_code_count)
BOZO_CLEAN();
BOZO_end_array(code, ARRAY_SIZE(s_decoded.code))
......@@ -613,7 +617,9 @@ static int main_copyright_(void)
BOZO_begin_array(i_additional_info, i_additional_length, 0)
BOZO_DOJOB(Copyright);
BOZO_check_array_begin(i_additional_info, i_additional_length)
BOZO_check_array_gen(i_additional_info, i_additional_length)
BOZO_CLEAN();
BOZO_end_array(i_additional_info, ARRAY_SIZE(s_decoded.i_additional_info))
......@@ -829,7 +835,9 @@ static int main_network_name_(void)
BOZO_begin_array(i_name_byte, i_name_length, 0)
BOZO_DOJOB(NetworkName);
BOZO_check_array_begin(i_name_byte, i_name_length)
BOZO_check_array_gen(i_name_byte, i_name_length)
BOZO_CLEAN();
BOZO_end_array(i_name_byte, ARRAY_SIZE(s_decoded.i_name_byte))
......@@ -851,7 +859,9 @@ static int main_stuffing_(void)
BOZO_begin_array(i_stuffing_byte, i_stuffing_length, 0)
BOZO_DOJOB(Stuffing);
BOZO_check_array_begin(i_stuffing_byte, i_stuffing_length)
BOZO_check_array_gen(i_stuffing_byte, i_stuffing_length)
BOZO_CLEAN();
BOZO_end_array(i_stuffing_byte, ARRAY_SIZE(s_decoded.i_stuffing_byte))
......@@ -873,7 +883,9 @@ static int main_bouquet_name_(void)
BOZO_begin_array(i_char, i_name_length, 0)
BOZO_DOJOB(BouquetName);
BOZO_check_array_begin(i_char, i_name_length)
BOZO_check_array_gen(i_char, i_name_length)
BOZO_CLEAN();
BOZO_end_array(i_char, ARRAY_SIZE(s_decoded.i_char))
......@@ -906,7 +918,9 @@ static int main_service_1(void)
BOZO_begin_array(i_service_provider_name, i_service_provider_name_length, 0)
BOZO_DOJOB(Service);
BOZO_check_array_begin(i_service_provider_name, i_service_provider_name_length)
BOZO_check_array_gen(i_service_provider_name, i_service_provider_name_length)
BOZO_CLEAN();
BOZO_end_array(i_service_provider_name, ARRAY_SIZE(s_decoded.i_service_provider_name))
......@@ -939,7 +953,9 @@ static int main_service_2(void)
BOZO_begin_array(i_service_name, i_service_name_length, 0)
BOZO_DOJOB(Service);
BOZO_check_array_begin(i_service_name, i_service_name_length)
BOZO_check_array_gen(i_service_name, i_service_name_length)
BOZO_CLEAN();
BOZO_end_array(i_service_name, ARRAY_SIZE(s_decoded.i_service_name))
......@@ -972,7 +988,9 @@ static int main_service_3(void)
BOZO_begin_array(i_service_name, i_service_name_length, 0)
BOZO_DOJOB(Service);
BOZO_check_array_begin(i_service_name, i_service_name_length)
BOZO_check_array_gen(i_service_name, i_service_name_length)
BOZO_CLEAN();
BOZO_end_array(i_service_name, 126)
......@@ -983,7 +1001,9 @@ static int main_service_3(void)
BOZO_begin_array(i_service_provider_name, i_service_provider_name_length, 0)
BOZO_DOJOB(Service);
BOZO_check_array_begin(i_service_provider_name, i_service_provider_name_length)
BOZO_check_array_gen(i_service_provider_name, i_service_provider_name_length)
BOZO_CLEAN();
BOZO_end_array(i_service_provider_name, 126)
......@@ -994,6 +1014,29 @@ static int main_service_3(void)
return i_err;
}
/* service list */
static int main_service_list_(void)
{
BOZO_VARS(service_list);
BOZO_START(service list);
/* check i_service */
BOZO_begin_array(i_service, i_service_count, 1)
BOZO_DOJOB(ServiceList);
BOZO_check_array_begin(i_service, i_service_count)
BOZO_check_array_cmp(i_service, i_service_count, dvbpsi_service_list_service_s)
BOZO_CLEAN();
BOZO_end_array(i_service, ARRAY_SIZE(s_decoded.i_service))
BOZO_END(service list);
return i_err;
}
/* main function */
int main(void)
......@@ -1027,6 +1070,7 @@ int main(void)
i_err |= main_service_1();
i_err |= main_service_2();
i_err |= main_service_3();
i_err |= main_service_list_();
if(i_err)
fprintf(stderr, "At least one test has FAILED !!!\n");
......
......@@ -26,6 +26,8 @@
# define PRI64d "llu"
#endif
#include "test_dr_cmp.h"
#define BOZO_VARS(sname) \
int i_err = 0; \
long long unsigned int i_loop_count; \
......@@ -163,8 +165,8 @@
#define BOZO_check_array_cmp(name, len_name, type) \
else if( !i_err \
&& (compare_##type##(s_decoded.name, p_new_decoded->name, \
s_decoded.len_name) != 0)) \
&& (my_memcmp(s_decoded.name, p_new_decoded->name, \
s_decoded.len_name, compare_##type) != 0)) \
{ \
fprintf(stderr, "\nError: array %s not equal\n", #name); \
i_err = 1; \
......
static int my_memcmp(const void *s1, const void *s2, size_t n,
int (*compar)(const void *, const void *))
{
for(size_t i = 0 ; i < n ; ++i)
{
int cmp = compar(s1, s2);
if(cmp != 0) return cmp;
}
return 0;
}
static int compare_dvbpsi_service_list_service_s(const void *s1, const void *s2)
{
const struct dvbpsi_service_list_service_s *a = s1, *b = s2;
if(a->i_service_id < b->i_service_id ||
a->i_service_type < b->i_service_type) return -1;
else if(a->i_service_id > b->i_service_id ||
a->i_service_type > b->i_service_type) return 1;
else return 0;
}
......@@ -56,7 +56,7 @@ typedef struct dvbpsi_dvb_service_list_dr_s
{
uint8_t i_service_count; /*!< length of the i_service_list
array */
struct {
struct dvbpsi_service_list_service_s {
uint16_t i_service_id; /*!< service id */
uint8_t i_service_type; /*!< service type */
} i_service[64]; /*!< array of services */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment