diff --git a/cmp_tool.c b/cmp_tool.c index 0cf72eff5c1f540802f653cf902f56d6c5d3ef88..86302b38c2db4fdf0915a2b0c916a490930d1ba7 100644 --- a/cmp_tool.c +++ b/cmp_tool.c @@ -655,7 +655,7 @@ static int cmp_gernate_rdcu_info(const struct cmp_cfg *cfg, int cmp_size_bit, st info->rdcu_new_model_adr_used = cfg->rdcu_new_model_adr; info->rdcu_cmp_adr_used = cfg->rdcu_buffer_adr; - if (cmp_size_bit == CMP_ERROR_SAMLL_BUF) + if (cmp_size_bit == CMP_ERROR_SMALL_BUF) /* the icu_output_buf is to small to store the whole bitstream */ info->cmp_err |= 1UL << SMALL_BUFFER_ERR_BIT; /* set small buffer error */ if (cmp_size_bit < 0) diff --git a/include/cmp_data_types.h b/include/cmp_data_types.h index 8878557c3c2ce6a9dc81dd13c9b6805540a98600..41a39f7b7464a0704223408429fcec1b8eef0c78 100644 --- a/include/cmp_data_types.h +++ b/include/cmp_data_types.h @@ -108,8 +108,8 @@ struct cmp_max_used_bits { unsigned int nc_background_mean; unsigned int nc_background_variance; unsigned int nc_background_outlier_pixels; - unsigned int smeating_mean; - unsigned int smeating_variance_mean; + unsigned int smearing_mean; + unsigned int smearing_variance_mean; unsigned int smearing_outlier_pixels; unsigned int fc_imagette; unsigned int fc_offset_mean; diff --git a/include/cmp_support.h b/include/cmp_support.h index aa455a5e667d509b74b99a3dc7326f63e8c5b275..b69eb5c8a09c0772ee4f11c0dcd40fd98850aa74 100644 --- a/include/cmp_support.h +++ b/include/cmp_support.h @@ -24,7 +24,7 @@ /* return code if the bitstream buffer is too small to store the whole bitstream */ -#define CMP_ERROR_SAMLL_BUF -2 +#define CMP_ERROR_SMALL_BUF -2 /* return code if the value or the model is bigger than the max_used_bits * parameter allows diff --git a/lib/cmp_data_types.c b/lib/cmp_data_types.c index 6ce5f4bb3b06c672b4c34c7860be19369df67801..3064e6c8ab518b8631a3972c8b70589b081245da 100644 --- a/lib/cmp_data_types.c +++ b/lib/cmp_data_types.c @@ -50,8 +50,8 @@ struct cmp_max_used_bits max_used_bits = { MAX_USED_NC_BACKGROUND_MEAN_BITS, /* nc_background_mean */ MAX_USED_NC_BACKGROUND_VARIANCE_BITS, /* nc_background_variance */ MAX_USED_NC_BACKGROUND_OUTLIER_PIXELS_BITS, /* nc_background_outlier_pixels */ - MAX_USED_SMEARING_MEAN_BITS, /* smeating_mean */ - MAX_USED_SMEARING_VARIANCE_MEAN_BITS, /* smeating_variance_mean */ + MAX_USED_SMEARING_MEAN_BITS, /* smearing_mean */ + MAX_USED_SMEARING_VARIANCE_MEAN_BITS, /* smearing_variance_mean */ MAX_USED_SMEARING_OUTLIER_PIXELS_BITS, /* smearing_outlier_pixels */ MAX_USED_FC_IMAGETTE_BITS, /* fc_imagette */ MAX_USED_FC_OFFSET_MEAN_BITS, /* fc_offset_mean */ diff --git a/lib/cmp_icu.c b/lib/cmp_icu.c index 2d04120716064dec9c444e63803117f64d810c1c..107b85dbec6416d23a0900319207afc385134eff 100644 --- a/lib/cmp_icu.c +++ b/lib/cmp_icu.c @@ -306,7 +306,7 @@ static uint32_t map_to_pos(uint32_t value_to_map, unsigned int max_data_bits) * ignored if bitstream_adr is NULL * * @returns length in bits of the generated bitstream on success; returns - * negative in case of erroneous input; returns CMP_ERROR_SAMLL_BUF if + * negative in case of erroneous input; returns CMP_ERROR_SMALL_BUF if * the bitstream buffer is too small to put the value in the bitstream */ @@ -335,7 +335,7 @@ static int put_n_bits32(uint32_t value, unsigned int n_bits, int bit_offset, /* Check if bitstream buffer is large enough */ if ((unsigned int)stream_len > max_stream_len) { debug_print("Error: The buffer for the compressed data is too small to hold the compressed data. Try a larger buffer_length parameter.\n"); - return CMP_ERROR_SAMLL_BUF; + return CMP_ERROR_SMALL_BUF; } /* (M) is the n_bits parameter large enough to cover all value bits; the @@ -510,7 +510,7 @@ static uint32_t golomb_encoder(uint32_t value, uint32_t m, uint32_t log2_m, * @param setup pointer to the encoder setup * * @returns the bit length of the bitstream with the added encoded value on - * success; negative on error, CMP_ERROR_SAMLL_BUF if the bitstream buffer + * success; negative on error, CMP_ERROR_SMALL_BUF if the bitstream buffer * is too small to put the value in the bitstream */ @@ -537,7 +537,7 @@ static int encode_normal(uint32_t value, int stream_len, * @param setup pointer to the encoder setup * * @returns the bit length of the bitstream with the added encoded value on - * success; negative on error, CMP_ERROR_SAMLL_BUF if the bitstream buffer + * success; negative on error, CMP_ERROR_SMALL_BUF if the bitstream buffer * is too small to put the value in the bitstream * * @note no check if the data or model are in the allowed range @@ -587,7 +587,7 @@ static int encode_value_zero(uint32_t data, uint32_t model, int stream_len, * @param setup pointer to the encoder setup * * @returns the bit length of the bitstream with the added encoded value on - * success; negative on error, CMP_ERROR_SAMLL_BUF if the bitstream buffer + * success; negative on error, CMP_ERROR_SMALL_BUF if the bitstream buffer * is too small to put the value in the bitstream * * @note no check if the data or model are in the allowed range @@ -653,7 +653,7 @@ static int encode_value_multi(uint32_t data, uint32_t model, int stream_len, * @param setup pointer to the encoder setup * * @returns the bit length of the bitstream with the added unencoded value on - * success; negative on error, CMP_ERROR_SAMLL_BUF if the bitstream buffer + * success; negative on error, CMP_ERROR_SMALL_BUF if the bitstream buffer * is too small to put the value in the bitstream * */ @@ -678,7 +678,7 @@ static int encode_value_none(uint32_t value, uint32_t unused, int stream_len, * @param setup pointer to the encoder setup * * @returns the bit length of the bitstream with the added encoded value on - * success; negative on error, CMP_ERROR_SAMLL_BUF if the bitstream buffer + * success; negative on error, CMP_ERROR_SMALL_BUF if the bitstream buffer * is too small to put the value in the bitstream, CMP_ERROR_HIGH_VALUE if * the value or the model is bigger than the max_used_bits parameter allows */ @@ -798,7 +798,7 @@ static int configure_encoder_setup(struct encoder_setupt *setup, * @param cfg pointer to the compression configuration structure * * @returns the bit length of the bitstream on success; negative on error, - * CMP_ERROR_SAMLL_BUF if the bitstream buffer is too small to put the + * CMP_ERROR_SMALL_BUF if the bitstream buffer is too small to put the * value in the bitstream, CMP_ERROR_HIGH_VALUE if the value or the model is * bigger than the max_used_bits parameter allows */ @@ -887,7 +887,7 @@ static int compress_multi_entry_hdr(void **data, void **model, void **up_model, * @param cfg pointer to the compression configuration structure * * @returns the bit length of the bitstream on success; negative on error, - * CMP_ERROR_SAMLL_BUF if the bitstream buffer is too small to put the + * CMP_ERROR_SMALL_BUF if the bitstream buffer is too small to put the * value in the bitstream */ @@ -959,7 +959,7 @@ static int compress_s_fx(const struct cmp_cfg *cfg) * @param cfg pointer to the compression configuration structure * * @returns the bit length of the bitstream on success; negative on error, - * CMP_ERROR_SAMLL_BUF if the bitstream buffer is too small to put the + * CMP_ERROR_SMALL_BUF if the bitstream buffer is too small to put the * value in the bitstream */ @@ -1041,7 +1041,7 @@ static int compress_s_fx_efx(const struct cmp_cfg *cfg) * @param cfg pointer to the compression configuration structure * * @returns the bit length of the bitstream on success; negative on error, - * CMP_ERROR_SAMLL_BUF if the bitstream buffer is too small to put the + * CMP_ERROR_SMALL_BUF if the bitstream buffer is too small to put the * value in the bitstream */ @@ -1129,7 +1129,7 @@ static int compress_s_fx_ncob(const struct cmp_cfg *cfg) * @param cfg pointer to the compression configuration structure * * @returns the bit length of the bitstream on success; negative on error, - * CMP_ERROR_SAMLL_BUF if the bitstream buffer is too small to put the + * CMP_ERROR_SMALL_BUF if the bitstream buffer is too small to put the * value in the bitstream */ @@ -1244,7 +1244,7 @@ static int compress_s_fx_efx_ncob_ecob(const struct cmp_cfg *cfg) * @param cfg pointer to the compression configuration structure * * @returns the bit length of the bitstream on success; negative on error, - * CMP_ERROR_SAMLL_BUF if the bitstream buffer is too small to put the + * CMP_ERROR_SMALL_BUF if the bitstream buffer is too small to put the * value in the bitstream */ @@ -1306,7 +1306,7 @@ static int compress_f_fx(const struct cmp_cfg *cfg) * @param cfg pointer to the compression configuration structure * * @returns the bit length of the bitstream on success; negative on error, - * CMP_ERROR_SAMLL_BUF if the bitstream buffer is too small to put the + * CMP_ERROR_SMALL_BUF if the bitstream buffer is too small to put the * value in the bitstream */ @@ -1378,7 +1378,7 @@ static int compress_f_fx_efx(const struct cmp_cfg *cfg) * @param cfg pointer to the compression configuration structure * * @returns the bit length of the bitstream on success; negative on error, - * CMP_ERROR_SAMLL_BUF if the bitstream buffer is too small to put the + * CMP_ERROR_SMALL_BUF if the bitstream buffer is too small to put the * value in the bitstream */ @@ -1456,7 +1456,7 @@ static int compress_f_fx_ncob(const struct cmp_cfg *cfg) * @param cfg pointer to the compression configuration structure * * @returns the bit length of the bitstream on success; negative on error, - * CMP_ERROR_SAMLL_BUF if the bitstream buffer is too small to put the + * CMP_ERROR_SMALL_BUF if the bitstream buffer is too small to put the * value in the bitstream */ @@ -1560,7 +1560,7 @@ static int compress_f_fx_efx_ncob_ecob(const struct cmp_cfg *cfg) * @param cfg pointer to the compression configuration structure * * @returns the bit length of the bitstream on success; negative on error, - * CMP_ERROR_SAMLL_BUF if the bitstream buffer is too small to put the + * CMP_ERROR_SMALL_BUF if the bitstream buffer is too small to put the * value in the bitstream */ @@ -1642,7 +1642,7 @@ static int compress_l_fx(const struct cmp_cfg *cfg) * @param cfg pointer to the compression configuration structure * * @returns the bit length of the bitstream on success; negative on error, - * CMP_ERROR_SAMLL_BUF if the bitstream buffer is too small to put the + * CMP_ERROR_SMALL_BUF if the bitstream buffer is too small to put the * value in the bitstream */ @@ -1734,7 +1734,7 @@ static int compress_l_fx_efx(const struct cmp_cfg *cfg) * @param cfg pointer to the compression configuration structure * * @returns the bit length of the bitstream on success; negative on error, - * CMP_ERROR_SAMLL_BUF if the bitstream buffer is too small to put the + * CMP_ERROR_SMALL_BUF if the bitstream buffer is too small to put the * value in the bitstream */ @@ -1850,7 +1850,7 @@ static int compress_l_fx_ncob(const struct cmp_cfg *cfg) * @param cfg pointer to the compression configuration structure * * @returns the bit length of the bitstream on success; negative on error, - * CMP_ERROR_SAMLL_BUF if the bitstream buffer is too small to put the + * CMP_ERROR_SMALL_BUF if the bitstream buffer is too small to put the * value in the bitstream */ @@ -1991,7 +1991,7 @@ static int compress_l_fx_efx_ncob_ecob(const struct cmp_cfg *cfg) * * @param cfg pointer to the compression configuration structure * @returns the bit length of the bitstream on success; negative on error, - * CMP_ERROR_SAMLL_BUF if the bitstream buffer is too small to put the + * CMP_ERROR_SMALL_BUF if the bitstream buffer is too small to put the * value in the bitstream */ @@ -2062,7 +2062,7 @@ static int compress_nc_offset(const struct cmp_cfg *cfg) * * @param cfg pointer to the compression configuration structure * @returns the bit length of the bitstream on success; negative on error, - * CMP_ERROR_SAMLL_BUF if the bitstream buffer is too small to put the + * CMP_ERROR_SMALL_BUF if the bitstream buffer is too small to put the * value in the bitstream */ @@ -2144,7 +2144,7 @@ static int compress_nc_background(const struct cmp_cfg *cfg) * @param cfg pointer to the compression configuration structure * * @returns the bit length of the bitstream on success; negative on error, - * CMP_ERROR_SAMLL_BUF if the bitstream buffer is too small to put the + * CMP_ERROR_SMALL_BUF if the bitstream buffer is too small to put the * value in the bitstream */ @@ -2176,11 +2176,11 @@ static int compress_smearing(const struct cmp_cfg *cfg) } err = configure_encoder_setup(&setup_mean, cfg->cmp_par_mean, cfg->spill_mean, - cfg->round, max_used_bits.smeating_mean, cfg); + cfg->round, max_used_bits.smearing_mean, cfg); if (err) return -1; err = configure_encoder_setup(&setup_var_mean, cfg->cmp_par_variance, cfg->spill_variance, - cfg->round, max_used_bits.smeating_variance_mean, cfg); + cfg->round, max_used_bits.smearing_variance_mean, cfg); if (err) return -1; err = configure_encoder_setup(&setup_pix, cfg->cmp_par_pixels_error, cfg->spill_pixels_error, @@ -2227,7 +2227,7 @@ static int compress_smearing(const struct cmp_cfg *cfg) * @param cmp_size length of the bitstream in bits * * @returns the bit length of the bitstream on success; negative on error, - * CMP_ERROR_SAMLL_BUF if the bitstream buffer is too small to put the + * CMP_ERROR_SMALL_BUF if the bitstream buffer is too small to put the * value in the bitstream */ @@ -2277,6 +2277,8 @@ static int cmp_data_to_big_endian(const struct cmp_cfg *cfg, int cmp_size) return cmp_size; if (cfg->cmp_mode == CMP_MODE_RAW) { + if (s & 0x7) /* size must be a multiple of 8 in RAW mode */ + return -1; if (cmp_input_big_to_cpu_endianness(cfg->icu_output_buf, s/CHAR_BIT, cfg->data_type)) cmp_size = -1; @@ -2309,7 +2311,7 @@ static int cmp_data_to_big_endian(const struct cmp_cfg *cfg, int cmp_size) * started * * @returns the bit length of the bitstream on success; negative on error, - * CMP_ERROR_SAMLL_BUF (-2) if the compressed data buffer is too small to + * CMP_ERROR_SMALL_BUF (-2) if the compressed data buffer is too small to * hold the whole compressed data, CMP_ERROR_HIGH_VALUE (-3) if a data or * model value is bigger than the max_used_bits parameter allows (set with * the cmp_set_max_used_bits() function) @@ -2327,7 +2329,7 @@ int icu_compress_data(const struct cmp_cfg *cfg) if (raw_mode_is_used(cfg->cmp_mode)) if (cfg->samples > cfg->buffer_length) - return CMP_ERROR_SAMLL_BUF; + return CMP_ERROR_SMALL_BUF; if (!cmp_cfg_is_valid(cfg)) return -1; @@ -2402,11 +2404,13 @@ int icu_compress_data(const struct cmp_cfg *cfg) case DATA_TYPE_F_CAM_OFFSET: case DATA_TYPE_F_CAM_BACKGROUND: + /* LCOV_EXCL_START */ case DATA_TYPE_UNKNOWN: default: debug_print("Error: Data type not supported.\n"); cmp_size = -1; } + /* LCOV_EXCL_STOP */ } if (cfg->icu_output_buf) { diff --git a/lib/cmp_support.c b/lib/cmp_support.c index ae7941b6bb9bfed857762c0c06d980eca89488a2..f157a6ea7b774ce13ded9c9252f975f23b56cd1e 100644 --- a/lib/cmp_support.c +++ b/lib/cmp_support.c @@ -671,7 +671,7 @@ int cmp_cfg_imagette_is_valid(const struct cmp_cfg *cfg) return 0; if (!cmp_imagette_data_type_is_used(cfg->data_type)) { - debug_print("Error: The compression data type is not an imagette compression data type!\n"); + debug_print("Error: The compression data type is not an imagette compression data type.\n"); cfg_invalid++; } @@ -712,7 +712,7 @@ int cmp_cfg_fx_cob_is_valid(const struct cmp_cfg *cfg) return 0; if (!cmp_fx_cob_data_type_is_used(cfg->data_type)) { - debug_print("Error: The compression data type is not a flux/center of brightness compression data type.!\n"); + debug_print("Error: The compression data type is not a flux/center of brightness compression data type.\n"); cfg_invalid++; } /* flux parameter is needed for every fx_cob data_type */ @@ -816,7 +816,7 @@ int cmp_cfg_aux_is_valid(const struct cmp_cfg *cfg) return 0; if (!cmp_aux_data_type_is_used(cfg->data_type)) { - debug_print("Error: The compression data type is not an auxiliary science compression data type.!\n"); + debug_print("Error: The compression data type is not an auxiliary science compression data type.\n"); cfg_invalid++; } diff --git a/lib/decmp.c b/lib/decmp.c index 534fc466596161d75e7743abb74b28b47b288f09..f15c943078051dfd19fc59de35792efd51ef92e5 100644 --- a/lib/decmp.c +++ b/lib/decmp.c @@ -218,7 +218,7 @@ static decoder_ptr select_decoder(unsigned int golomb_par) * ignored if bitstream_adr is NULL * * @returns bit position of the last read bit in the bitstream on success; - * returns negative in case of erroneous input; returns CMP_ERROR_SAMLL_BUF + * returns negative in case of erroneous input; returns CMP_ERROR_SMALL_BUF * if the bitstream buffer is too small to read the value from the * bitstream */ @@ -248,7 +248,7 @@ static int get_n_bits32(uint32_t *p_value, unsigned int n_bits, int bit_offset, /* Check if bitstream buffer is large enough */ if ((unsigned int)stream_len > max_stream_len) { debug_print("Error: Buffer overflow detected.\n"); - return CMP_ERROR_SAMLL_BUF; + return CMP_ERROR_SMALL_BUF; } @@ -297,7 +297,7 @@ static int get_n_bits32(uint32_t *p_value, unsigned int n_bits, int bit_offset, * @param setup pointer to the decoder setup * * @returns bit index of the next code word in the bitstream on success; returns - * negative in case of erroneous input; returns CMP_ERROR_SAMLL_BUF if the + * negative in case of erroneous input; returns CMP_ERROR_SMALL_BUF if the * bitstream buffer is too small to read the value from the bitstream */ @@ -344,7 +344,7 @@ static int decode_normal(uint32_t *decoded_value, int stream_pos, * @param setup pointer to the decoder setup * * @returns bit index of the next code word in the bitstream on success; returns - * negative in case of erroneous input; returns CMP_ERROR_SAMLL_BUF if the + * negative in case of erroneous input; returns CMP_ERROR_SMALL_BUF if the * bitstream buffer is too small to read the value from the bitstream */ @@ -392,7 +392,7 @@ static int decode_zero(uint32_t *decoded_value, int stream_pos, * @param setup pointer to the decoder setup * * @returns bit index of the next code word in the bitstream on success; returns - * negative in case of erroneous input; returns CMP_ERROR_SAMLL_BUF if the + * negative in case of erroneous input; returns CMP_ERROR_SMALL_BUF if the * bitstream buffer is too small to read the value from the bitstream */ @@ -448,7 +448,7 @@ static uint32_t re_map_to_pos(uint32_t value_to_unmap) * @param setup pointer to the decoder setup * * @returns bit index of the next code word in the bitstream on success; returns - * negative in case of erroneous input; returns CMP_ERROR_SAMLL_BUF if the + * negative in case of erroneous input; returns CMP_ERROR_SMALL_BUF if the * bitstream buffer is too small to read the value from the bitstream */ @@ -597,7 +597,7 @@ static int decompress_multi_entry_hdr(void **data, void **model, void **up_model * @param cfg pointer to the compression configuration structure * * @returns the bit length of the bitstream on success; negative on error, - * CMP_ERROR_SAMLL_BUF if the bitstream buffer is too small to put the + * CMP_ERROR_SMALL_BUF if the bitstream buffer is too small to put the * value in the bitstream */ @@ -669,7 +669,7 @@ static int decompress_s_fx(const struct cmp_cfg *cfg) * @param cfg pointer to the compression configuration structure * * @returns the bit length of the bitstream on success; negative on error, - * CMP_ERROR_SAMLL_BUF if the bitstream buffer is too small to put the + * CMP_ERROR_SMALL_BUF if the bitstream buffer is too small to put the * value in the bitstream */ @@ -752,7 +752,7 @@ static int decompress_s_fx_efx(const struct cmp_cfg *cfg) * @param cfg pointer to the compression configuration structure * * @returns the bit length of the bitstream on success; negative on error, - * CMP_ERROR_SAMLL_BUF if the bitstream buffer is too small to put the + * CMP_ERROR_SMALL_BUF if the bitstream buffer is too small to put the * value in the bitstream */ @@ -843,7 +843,7 @@ static int decompress_s_fx_ncob(const struct cmp_cfg *cfg) * @param cfg pointer to the compression configuration structure * * @returns the bit length of the bitstream on success; negative on error, - * CMP_ERROR_SAMLL_BUF if the bitstream buffer is too small to put the + * CMP_ERROR_SMALL_BUF if the bitstream buffer is too small to put the * value in the bitstream */ @@ -964,7 +964,7 @@ static int decompress_s_fx_efx_ncob_ecob(const struct cmp_cfg *cfg) * @param cfg pointer to the compression configuration structure * * @returns the bit length of the bitstream on success; negative on error, - * CMP_ERROR_SAMLL_BUF if the bitstream buffer is too small to put the + * CMP_ERROR_SMALL_BUF if the bitstream buffer is too small to put the * value in the bitstream */ @@ -1024,7 +1024,7 @@ static int decompress_f_fx(const struct cmp_cfg *cfg) * @param cfg pointer to the compression configuration structure * * @returns the bit length of the bitstream on success; negative on error, - * CMP_ERROR_SAMLL_BUF if the bitstream buffer is too small to put the + * CMP_ERROR_SMALL_BUF if the bitstream buffer is too small to put the * value in the bitstream */ @@ -1096,7 +1096,7 @@ static int decompress_f_fx_efx(const struct cmp_cfg *cfg) * @param cfg pointer to the compression configuration structure * * @returns the bit length of the bitstream on success; negative on error, - * CMP_ERROR_SAMLL_BUF if the bitstream buffer is too small to put the + * CMP_ERROR_SMALL_BUF if the bitstream buffer is too small to put the * value in the bitstream */ @@ -1176,7 +1176,7 @@ static int decompress_f_fx_ncob(const struct cmp_cfg *cfg) * @param cfg pointer to the compression configuration structure * * @returns the bit length of the bitstream on success; negative on error, - * CMP_ERROR_SAMLL_BUF if the bitstream buffer is too small to put the + * CMP_ERROR_SMALL_BUF if the bitstream buffer is too small to put the * value in the bitstream */ @@ -1286,7 +1286,7 @@ static int decompress_f_fx_efx_ncob_ecob(const struct cmp_cfg *cfg) * @param cfg pointer to the compression configuration structure * * @returns the bit length of the bitstream on success; negative on error, - * CMP_ERROR_SAMLL_BUF if the bitstream buffer is too small to put the + * CMP_ERROR_SMALL_BUF if the bitstream buffer is too small to put the * value in the bitstream */ @@ -1369,7 +1369,7 @@ static int decompress_l_fx(const struct cmp_cfg *cfg) * @param cfg pointer to the compression configuration structure * * @returns the bit length of the bitstream on success; negative on error, - * CMP_ERROR_SAMLL_BUF if the bitstream buffer is too small to put the + * CMP_ERROR_SMALL_BUF if the bitstream buffer is too small to put the * value in the bitstream */ @@ -1463,7 +1463,7 @@ static int decompress_l_fx_efx(const struct cmp_cfg *cfg) * @param cfg pointer to the compression configuration structure * * @returns the bit length of the bitstream on success; negative on error, - * CMP_ERROR_SAMLL_BUF if the bitstream buffer is too small to put the + * CMP_ERROR_SMALL_BUF if the bitstream buffer is too small to put the * value in the bitstream */ @@ -1585,7 +1585,7 @@ static int decompress_l_fx_ncob(const struct cmp_cfg *cfg) * @param cfg pointer to the compression configuration structure * * @returns the bit length of the bitstream on success; negative on error, - * CMP_ERROR_SAMLL_BUF if the bitstream buffer is too small to put the + * CMP_ERROR_SMALL_BUF if the bitstream buffer is too small to put the * value in the bitstream */ @@ -1731,7 +1731,7 @@ static int decompress_l_fx_efx_ncob_ecob(const struct cmp_cfg *cfg) * @param cfg pointer to the compression configuration structure * * @returns the bit length of the bitstream on success; negative on error, - * CMP_ERROR_SAMLL_BUF if the bitstream buffer is too small to put the + * CMP_ERROR_SMALL_BUF if the bitstream buffer is too small to put the * value in the bitstream */ @@ -1803,7 +1803,7 @@ static int decompress_nc_offset(const struct cmp_cfg *cfg) * @param cfg pointer to the compression configuration structure * * @returns the bit length of the bitstream on success; negative on error, - * CMP_ERROR_SAMLL_BUF if the bitstream buffer is too small to put the + * CMP_ERROR_SMALL_BUF if the bitstream buffer is too small to put the * value in the bitstream */ @@ -1886,7 +1886,7 @@ static int decompress_nc_background(const struct cmp_cfg *cfg) * @param cfg pointer to the compression configuration structure * * @returns the bit length of the bitstream on success; negative on error, - * CMP_ERROR_SAMLL_BUF if the bitstream buffer is too small to put the + * CMP_ERROR_SMALL_BUF if the bitstream buffer is too small to put the * value in the bitstream */ @@ -1917,10 +1917,10 @@ static int decompress_smearing(const struct cmp_cfg *cfg) } if (configure_decoder_setup(&setup_mean, cfg->cmp_par_mean, cfg->spill_mean, - cfg->round, max_used_bits.smeating_mean, cfg)) + cfg->round, max_used_bits.smearing_mean, cfg)) return -1; if (configure_decoder_setup(&setup_var, cfg->cmp_par_variance, cfg->spill_variance, - cfg->round, max_used_bits.smeating_variance_mean, cfg)) + cfg->round, max_used_bits.smearing_variance_mean, cfg)) return -1; if (configure_decoder_setup(&setup_pix, cfg->cmp_par_pixels_error, cfg->spill_pixels_error, cfg->round, max_used_bits.smearing_outlier_pixels, cfg)) diff --git a/test/cmp_icu/test_cmp_icu.c b/test/cmp_icu/test_cmp_icu.c index 9038a39713c450049ffe78a341a5e2231928273d..3eae4bebc100f5bd5e01d4132ecf08fee70c4557 100644 --- a/test/cmp_icu/test_cmp_icu.c +++ b/test/cmp_icu/test_cmp_icu.c @@ -31,7 +31,7 @@ void setUp(void) #endif if (!n) { - n++; + n = 1; srand(seed); printf("seed: %u\n", seed); } @@ -41,20 +41,18 @@ void setUp(void) /** * @brief generate a random number * - * @param min minimum value - * @param max maximum value + * @param min minimum value (inclusive) + * @param max maximum value (inclusive) * * @returns "random" numbers in the range [M, N] * * @see https://c-faq.com/lib/randrange.html */ -int random_range(unsigned int min, unsigned int max) +int random_between(unsigned int min, unsigned int max) { - if (min > max) - TEST_ASSERT(0); - if (max-min > RAND_MAX) - TEST_ASSERT(0); + TEST_ASSERT(min < max); + TEST_ASSERT(max-min <= RAND_MAX); return min + rand() / (RAND_MAX / (max - min + 1) + 1); } @@ -170,10 +168,10 @@ void test_cmp_cfg_icu_create(void) TEST_ASSERT_EQUAL_INT(3, cfg.round); /* random test */ - data_type = random_range(DATA_TYPE_IMAGETTE, biggest_data_type); - cmp_mode = random_range(CMP_MODE_RAW, CMP_MODE_STUFF); - model_value = random_range(0, MAX_MODEL_VALUE); - lossy_par = random_range(CMP_LOSSLESS, MAX_ICU_ROUND); + data_type = random_between(DATA_TYPE_IMAGETTE, biggest_data_type); + cmp_mode = random_between(CMP_MODE_RAW, CMP_MODE_STUFF); + model_value = random_between(0, MAX_MODEL_VALUE); + lossy_par = random_between(CMP_LOSSLESS, MAX_ICU_ROUND); cfg = cmp_cfg_icu_create(data_type, cmp_mode, model_value, lossy_par); TEST_ASSERT_EQUAL_INT(data_type, cfg.data_type); TEST_ASSERT_EQUAL_INT(cmp_mode, cfg.cmp_mode); @@ -1610,7 +1608,7 @@ void test_put_n_bits32(void) /* try to put too much in the bitstream */ v = 0x1; n = 1; o = 96; rval = put_n_bits32(v, n, o, testarray0, l); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_SAMLL_BUF, rval); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_SMALL_BUF, rval); TEST_ASSERT(testarray0[0] == 0); TEST_ASSERT(testarray0[1] == 0); TEST_ASSERT(testarray0[2] == 0); @@ -1622,7 +1620,7 @@ void test_put_n_bits32(void) /* offset lager than max_stream_len(l) */ v = 0x0; n = 32; o = INT32_MAX; rval = put_n_bits32(v, n, o, testarray1, l); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_SAMLL_BUF, rval); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_SMALL_BUF, rval); TEST_ASSERT(testarray1[0] == 0xffffffff); TEST_ASSERT(testarray1[1] == 0xffffffff); TEST_ASSERT(testarray1[2] == 0xffffffff); @@ -1887,7 +1885,7 @@ void test_encode_value_zero(void) /* small buffer error */ data = 23; model = 26; stream_len = encode_value_zero(data, model, stream_len, &setup); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_SAMLL_BUF, stream_len); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_SMALL_BUF, stream_len); /* reset bitstream to all bits set */ bitstream[0] = ~0U; @@ -1938,7 +1936,7 @@ void test_encode_value_zero(void) setup.max_stream_len = 32; data = 31; model = 0; stream_len = encode_value_zero(data, model, stream_len, &setup); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_SAMLL_BUF, stream_len); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_SMALL_BUF, stream_len); TEST_ASSERT_EQUAL_HEX(0, bitstream[0]); TEST_ASSERT_EQUAL_HEX(0, bitstream[1]); TEST_ASSERT_EQUAL_HEX(0, bitstream[2]); @@ -2021,7 +2019,7 @@ void test_encode_value_multi(void) /* small buffer error */ data = 0; model = 38; stream_len = encode_value_multi(data, model, stream_len, &setup); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_SAMLL_BUF, stream_len); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_SMALL_BUF, stream_len); /* small buffer error when creating the multi escape symbol*/ bitstream[0] = 0; @@ -2031,7 +2029,7 @@ void test_encode_value_multi(void) stream_len = 32; data = 31; model = 0; stream_len = encode_value_multi(data, model, stream_len, &setup); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_SAMLL_BUF, stream_len); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_SMALL_BUF, stream_len); TEST_ASSERT_EQUAL_HEX(0, bitstream[0]); TEST_ASSERT_EQUAL_HEX(0, bitstream[1]); } @@ -2095,7 +2093,7 @@ void test_encode_value(void) /* small buffer error bitstream can not hold more data*/ cmp_size = encode_value(data, model, cmp_size, &setup); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_SAMLL_BUF, cmp_size); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_SMALL_BUF, cmp_size); /* reset bitstream */ bitstream[0] = 0; @@ -2187,8 +2185,8 @@ void test_cmp_get_max_used_bits(void) TEST_ASSERT_EQUAL_INT(max_used_bits.nc_background_variance, MAX_USED_NC_BACKGROUND_VARIANCE_BITS); TEST_ASSERT_EQUAL_INT(max_used_bits.nc_background_outlier_pixels, MAX_USED_NC_BACKGROUND_OUTLIER_PIXELS_BITS); - TEST_ASSERT_EQUAL_INT(max_used_bits.smeating_mean, MAX_USED_SMEARING_MEAN_BITS); - TEST_ASSERT_EQUAL_INT(max_used_bits.smeating_variance_mean, MAX_USED_SMEARING_VARIANCE_MEAN_BITS); + TEST_ASSERT_EQUAL_INT(max_used_bits.smearing_mean, MAX_USED_SMEARING_MEAN_BITS); + TEST_ASSERT_EQUAL_INT(max_used_bits.smearing_variance_mean, MAX_USED_SMEARING_VARIANCE_MEAN_BITS); TEST_ASSERT_EQUAL_INT(max_used_bits.smearing_outlier_pixels, MAX_USED_SMEARING_OUTLIER_PIXELS_BITS); TEST_ASSERT_EQUAL_INT(max_used_bits.fc_offset_mean, MAX_USED_FC_OFFSET_MEAN_BITS); @@ -2553,7 +2551,7 @@ void test_compress_imagette_raw(void) cfg.buffer_length = 6; /* the buffer is to small */ cmp_size = icu_compress_data(&cfg); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_SAMLL_BUF, cmp_size); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_SMALL_BUF, cmp_size); } @@ -2592,7 +2590,7 @@ void test_compress_imagette_error_cases(void) cfg.buffer_length = 4; cmp_size = icu_compress_data(&cfg); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_SAMLL_BUF, cmp_size); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_SMALL_BUF, cmp_size); /* error in setup */ @@ -2902,7 +2900,8 @@ void test_compress_s_fx_model_multi(void) } -void test_compress_s_fx_efx_model_multi(void) +#if 0 +void todo_est_compress_s_fx_efx_model_multi(void) { uint32_t i; struct s_fx_efx data[6], model[6]; @@ -3014,6 +3013,1347 @@ void test_compress_s_fx_efx_model_multi(void) free(cfg.icu_new_model_buf); free(cfg.icu_output_buf); } +#endif + + +/** + * @test compress_s_fx + */ + +void test_compress_s_fx_error_cases(void) +{ + int error, cmp_bits, compressed_data_size; + struct cmp_cfg cfg = {0}; + uint32_t cmp_par_exp_flags = MAX_ICU_GOLOMB_PAR; + uint32_t spillover_exp_flags = 6; + uint32_t cmp_par_fx = 2; + uint32_t spillover_fx = 8; + uint8_t data_to_compress[MULTI_ENTRY_HDR_SIZE+3*sizeof(struct s_fx)] = {0}; + uint8_t compressed_data[MULTI_ENTRY_HDR_SIZE+1*sizeof(struct s_fx)] = {0}; + struct cmp_max_used_bits max_used_bits = {0}; + struct s_fx *data_p = (struct s_fx *)&data_to_compress[MULTI_ENTRY_HDR_SIZE]; + + max_used_bits.s_exp_flags = 2; + max_used_bits.s_fx = 21; + cmp_set_max_used_bits(&max_used_bits); + + cfg = cmp_cfg_icu_create(DATA_TYPE_S_FX, CMP_MODE_DIFF_ZERO, 0, CMP_LOSSLESS); + TEST_ASSERT(cfg.data_type != DATA_TYPE_UNKNOWN); + + error = cmp_cfg_fx_cob(&cfg, cmp_par_exp_flags, spillover_exp_flags, + cmp_par_fx, spillover_fx, CMP_PAR_UNUSED, + CMP_PAR_UNUSED, CMP_PAR_UNUSED, CMP_PAR_UNUSED, + CMP_PAR_UNUSED, CMP_PAR_UNUSED, CMP_PAR_UNUSED, + CMP_PAR_UNUSED); + TEST_ASSERT_FALSE(error); + + compressed_data_size = cmp_cfg_icu_buffers(&cfg, data_to_compress, 3, NULL, + NULL, (uint32_t *)compressed_data, 1); + TEST_ASSERT_EQUAL_INT(sizeof(compressed_data), compressed_data_size); + + /* test if data are higher than max used bits value */ + data_p[0].fx = 0x200000; /* has more than 21 bits (max_used_bits.s_fx) */ + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + + /* compressed data are to small for the compressed_data buffer */ + max_used_bits.s_exp_flags = 8; + max_used_bits.s_fx= 32; + cmp_set_max_used_bits(&max_used_bits); + memset(data_to_compress, 0xff, sizeof(data_to_compress)); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_SMALL_BUF, cmp_bits); + + max_used_bits.s_exp_flags = 33; /* more than 32 bits are not allowed */ + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(-1, cmp_bits); + + max_used_bits.s_exp_flags = 32; + max_used_bits.s_fx= 33; /* more than 32 bits are not allowed */ + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(-1, cmp_bits); +} + + +/** + * @test compress_s_fx_efx + */ + +void test_compress_s_fx_efx_error_cases(void) +{ + int error, cmp_bits, compressed_data_size; + struct cmp_cfg cfg = {0}; + uint32_t cmp_par_exp_flags = 2; + uint32_t spillover_exp_flags = 6; + uint32_t cmp_par_fx = 1; + uint32_t spillover_fx = 8; + uint32_t cmp_par_efx = MAX_ICU_GOLOMB_PAR; + uint32_t spillover_efx = cmp_icu_max_spill(MAX_ICU_GOLOMB_PAR); + uint8_t data_to_compress[MULTI_ENTRY_HDR_SIZE+2*sizeof(struct s_fx_efx)] = {0}; + uint8_t compressed_data[MULTI_ENTRY_HDR_SIZE+1*sizeof(struct s_fx_efx)] = {0}; + struct cmp_max_used_bits max_used_bits = {0}; + struct s_fx_efx *data_p= (struct s_fx_efx *)&data_to_compress[MULTI_ENTRY_HDR_SIZE]; + + max_used_bits.s_exp_flags = 2; + max_used_bits.s_fx = 21; + max_used_bits.s_efx = 16; + cmp_set_max_used_bits(&max_used_bits); + + cfg = cmp_cfg_icu_create(DATA_TYPE_S_FX_EFX, CMP_MODE_DIFF_MULTI, 0, CMP_LOSSLESS); + TEST_ASSERT(cfg.data_type != DATA_TYPE_UNKNOWN); + + error = cmp_cfg_fx_cob(&cfg, cmp_par_exp_flags, spillover_exp_flags, + cmp_par_fx, spillover_fx, CMP_PAR_UNUSED, + CMP_PAR_UNUSED, cmp_par_efx, spillover_efx, + CMP_PAR_UNUSED, CMP_PAR_UNUSED, CMP_PAR_UNUSED, + CMP_PAR_UNUSED); + TEST_ASSERT_FALSE(error); + + compressed_data_size = cmp_cfg_icu_buffers(&cfg, data_to_compress, 2, NULL, + NULL, (uint32_t *)compressed_data, 1); + TEST_ASSERT_EQUAL_INT(sizeof(compressed_data), compressed_data_size); + + /* test if data are higher than max used bits value */ + data_p[0].exp_flags = 0x4; /* has more than 2 bits (max_used_bits.s_exp_flags) */ + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + + data_p[0].exp_flags = 0x3; + data_p[1].fx = 0x200000; /* has more than 21 bits (max_used_bits.fx) */ + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + + data_p[1].fx = 0x1FFFFF; + data_p[1].efx = 0x100000; /* has more than 16 bits (max_used_bits.efx) */ + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + + /* error case exp_flag setup */ + max_used_bits.s_exp_flags = 33; + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(-1, cmp_bits); + + /* error case fx setup */ + max_used_bits.s_exp_flags = 2; + max_used_bits.s_fx = 33; + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(-1, cmp_bits); + + /* error case efx setup */ + max_used_bits.s_fx = 21; + max_used_bits.s_efx = 33; + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(-1, cmp_bits); +} + + +/** + * @test compress_s_fx_ncob + */ + +void test_compress_s_fx_ncob_error_cases(void) +{ + int error, cmp_bits, compressed_data_size; + struct cmp_cfg cfg = {0}; + uint32_t cmp_par_exp_flags = 3; + uint32_t spillover_exp_flags = 6; + uint32_t cmp_par_fx = 1; + uint32_t spillover_fx = 8; + uint32_t cmp_par_ncob = MAX_ICU_GOLOMB_PAR; + uint32_t spillover_ncob = cmp_icu_max_spill(MAX_ICU_GOLOMB_PAR); + uint8_t data_to_compress[MULTI_ENTRY_HDR_SIZE+3*sizeof(struct s_fx_ncob)] = {0}; + uint8_t model_data[MULTI_ENTRY_HDR_SIZE+3*sizeof(struct s_fx_ncob)] = {0}; + uint8_t compressed_data[MULTI_ENTRY_HDR_SIZE+1*sizeof(struct s_fx_ncob)] = {0}; + struct cmp_max_used_bits max_used_bits = {0}; + struct s_fx_ncob *data_p = (struct s_fx_ncob *)&data_to_compress[MULTI_ENTRY_HDR_SIZE]; + + + max_used_bits.s_exp_flags = 2; + max_used_bits.s_fx = 21; + max_used_bits.s_ncob = 31; + cmp_set_max_used_bits(&max_used_bits); + + cfg = cmp_cfg_icu_create(DATA_TYPE_S_FX_NCOB, CMP_MODE_MODEL_ZERO, 0, CMP_LOSSLESS); + TEST_ASSERT(cfg.data_type != DATA_TYPE_UNKNOWN); + + error = cmp_cfg_fx_cob(&cfg, cmp_par_exp_flags, spillover_exp_flags, + cmp_par_fx, spillover_fx, cmp_par_ncob, spillover_ncob, + CMP_PAR_UNUSED, CMP_PAR_UNUSED, CMP_PAR_UNUSED, + CMP_PAR_UNUSED, CMP_PAR_UNUSED, CMP_PAR_UNUSED); + TEST_ASSERT_FALSE(error); + + compressed_data_size = cmp_cfg_icu_buffers(&cfg, data_to_compress, 3, model_data, + NULL, (uint32_t *)compressed_data, 1); + TEST_ASSERT_EQUAL_INT(sizeof(compressed_data), compressed_data_size); + + /* the compressed_data buffer is to small */ + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_SMALL_BUF, cmp_bits); + + /* test if data are higher than max used bits value */ + data_p[2].exp_flags = 0x4; /* has more than 2 bits (max_used_bits.s_exp_flags) */ + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + + data_p[2].exp_flags = 0x3; + data_p[1].fx = 0x200000; /* value to high */ + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + + data_p[1].fx = 0x1FFFFF; /* value to high */ + data_p[0].ncob_y = 0x80000000; /* value to high */ + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + data_p[0].ncob_y = 0x7FFFFFFF; /* value to high */ + + /* error case exp_flag setup */ + max_used_bits.s_exp_flags = 33; + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(-1, cmp_bits); + + /* error case fx setup */ + max_used_bits.s_exp_flags = 2; + max_used_bits.s_fx = 33; + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(-1, cmp_bits); + + /* error case efx setup */ + max_used_bits.s_fx = 21; + max_used_bits.s_ncob = 33; + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(-1, cmp_bits); +} + + +/** + * @test compress_s_fx_efx_ncob_ecob + */ + +void test_compress_s_fx_efx_ncob_ecob_error_cases(void) +{ + int error, cmp_bits, compressed_data_size; + struct cmp_cfg cfg = {0}; + uint32_t cmp_par_exp_flags = 3; + uint32_t spillover_exp_flags = 6; + uint32_t cmp_par_fx = 1; + uint32_t spillover_fx = 8; + uint32_t cmp_par_ncob = MAX_ICU_GOLOMB_PAR; + uint32_t spillover_ncob = cmp_icu_max_spill(MAX_ICU_GOLOMB_PAR); + uint32_t cmp_par_efx = MAX_ICU_GOLOMB_PAR; + uint32_t spillover_efx = cmp_icu_max_spill(MAX_ICU_GOLOMB_PAR); + uint32_t cmp_par_ecob = 23; + uint32_t spillover_ecob = cmp_icu_max_spill(23); + uint8_t data_to_compress[MULTI_ENTRY_HDR_SIZE+3*sizeof(struct s_fx_efx_ncob_ecob)] = {0}; + uint8_t model_data[MULTI_ENTRY_HDR_SIZE+3*sizeof(struct s_fx_efx_ncob_ecob)] = {0}; + uint8_t compressed_data[MULTI_ENTRY_HDR_SIZE+1*sizeof(struct s_fx_efx_ncob_ecob)] = {0}; + struct cmp_max_used_bits max_used_bits = {0}; + struct s_fx_efx_ncob_ecob *data_p = (struct s_fx_efx_ncob_ecob *)&data_to_compress[MULTI_ENTRY_HDR_SIZE]; + + + max_used_bits.s_exp_flags = 2; + max_used_bits.s_fx = 21; + max_used_bits.s_ncob = 31; + max_used_bits.s_efx = 23; + max_used_bits.s_ecob = 7; + cmp_set_max_used_bits(&max_used_bits); + + cfg = cmp_cfg_icu_create(DATA_TYPE_S_FX_EFX_NCOB_ECOB, CMP_MODE_MODEL_ZERO, 0, CMP_LOSSLESS); + TEST_ASSERT(cfg.data_type != DATA_TYPE_UNKNOWN); + + error = cmp_cfg_fx_cob(&cfg, cmp_par_exp_flags, spillover_exp_flags, + cmp_par_fx, spillover_fx, cmp_par_ncob, + spillover_ncob, cmp_par_efx, spillover_efx, + cmp_par_ecob, spillover_ecob, CMP_PAR_UNUSED, CMP_PAR_UNUSED); + + TEST_ASSERT_FALSE(error); + + compressed_data_size = cmp_cfg_icu_buffers(&cfg, data_to_compress, 3, model_data, + NULL, (uint32_t *)compressed_data, 1); + TEST_ASSERT_EQUAL_INT(sizeof(compressed_data), compressed_data_size); + + /* the compressed_data buffer is to small */ + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_SMALL_BUF, cmp_bits); + + /* test if data are higher than max used bits value */ + data_p[2].exp_flags = 0x4; + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + + data_p[2].exp_flags = 0x3; + data_p[2].fx = 0x200000; + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + + data_p[2].fx = 0x1FFFFF; + data_p[1].ncob_x = 0x80000000; + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + + data_p[1].ncob_x = 0x7FFFFFFF; + data_p[1].ncob_y = 0x80000000; + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + + data_p[1].ncob_y = 0x7FFFFFFF; + data_p[1].efx = 0x800000; + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + + data_p[1].efx = 0x7FFFFF; + data_p[1].ecob_y = 0x80; + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + data_p[1].ecob_y = 0x7F; + + /* error case exp_flag setup */ + max_used_bits.s_exp_flags = 33; + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(-1, cmp_bits); + + /* error case fx setup */ + max_used_bits.s_exp_flags = 32; + max_used_bits.s_fx = 33; + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(-1, cmp_bits); + + /* error case efx setup */ + max_used_bits.s_fx = 32; + max_used_bits.s_ncob = 33; + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(-1, cmp_bits); + + max_used_bits.s_ncob = 32; + max_used_bits.s_efx = 33; + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(-1, cmp_bits); + + max_used_bits.s_efx = 32; + max_used_bits.s_ecob = 33; + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(-1, cmp_bits); + max_used_bits.s_ecob = 32; +} + + +/** + * @test compress_f_fx + */ + +void test_compress_f_fx_error_cases(void) +{ + int error, cmp_bits, compressed_data_size; + struct cmp_cfg cfg = {0}; + uint32_t cmp_par_fx = MAX_ICU_GOLOMB_PAR; + uint32_t spillover_fx = 8; + uint8_t data_to_compress[MULTI_ENTRY_HDR_SIZE+3*sizeof(struct f_fx)] = {0}; + uint8_t compressed_data[MULTI_ENTRY_HDR_SIZE+1*sizeof(struct f_fx)] = {0}; + struct cmp_max_used_bits max_used_bits = {0}; + + max_used_bits.f_fx = 23; + cmp_set_max_used_bits(&max_used_bits); + + cfg = cmp_cfg_icu_create(DATA_TYPE_F_FX, CMP_MODE_DIFF_ZERO, 0, CMP_LOSSLESS); + TEST_ASSERT(cfg.data_type != DATA_TYPE_UNKNOWN); + + error = cmp_cfg_fx_cob(&cfg, CMP_PAR_UNUSED, CMP_PAR_UNUSED, + cmp_par_fx, spillover_fx, CMP_PAR_UNUSED, + CMP_PAR_UNUSED, CMP_PAR_UNUSED, CMP_PAR_UNUSED, + CMP_PAR_UNUSED, CMP_PAR_UNUSED, CMP_PAR_UNUSED, + CMP_PAR_UNUSED); + TEST_ASSERT_FALSE(error); + + compressed_data_size = cmp_cfg_icu_buffers(&cfg, data_to_compress, 3, NULL, NULL, (uint32_t *)compressed_data, 1); + TEST_ASSERT_EQUAL_INT(sizeof(compressed_data), compressed_data_size); + + /* compressed data are to small for the compressed_data buffer */ + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_SMALL_BUF, cmp_bits); + + max_used_bits.f_fx= 33; /* more than 32 bits are not allowed */ + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(-1, cmp_bits); +} + + +/** + * @test compress_f_fx_efx + */ + +void test_compress_f_fx_efx_error_cases(void) +{ + int error, cmp_bits, compressed_data_size; + struct cmp_cfg cfg = {0}; + uint32_t cmp_par_fx = 1; + uint32_t spillover_fx = 8; + uint32_t cmp_par_efx = 1; + uint32_t spillover_efx = 8; + uint8_t data_to_compress[MULTI_ENTRY_HDR_SIZE+2*sizeof(struct f_fx_efx)] = {0}; + uint8_t compressed_data[MULTI_ENTRY_HDR_SIZE+1*sizeof(struct f_fx_efx)] = {0}; + struct cmp_max_used_bits max_used_bits = {0}; + struct f_fx_efx *data_p = (struct f_fx_efx *)&data_to_compress[MULTI_ENTRY_HDR_SIZE]; + + max_used_bits.f_fx = 23; + max_used_bits.f_efx = 31; + cmp_set_max_used_bits(&max_used_bits); + + cfg = cmp_cfg_icu_create(DATA_TYPE_F_FX_EFX, CMP_MODE_DIFF_ZERO, 0, CMP_LOSSLESS); + TEST_ASSERT(cfg.data_type != DATA_TYPE_UNKNOWN); + + error = cmp_cfg_fx_cob(&cfg, CMP_PAR_UNUSED, CMP_PAR_UNUSED, + cmp_par_fx, spillover_fx, CMP_PAR_UNUSED, + CMP_PAR_UNUSED, cmp_par_efx, spillover_efx, + CMP_PAR_UNUSED, CMP_PAR_UNUSED, CMP_PAR_UNUSED, + CMP_PAR_UNUSED); + TEST_ASSERT_FALSE(error); + + compressed_data_size = cmp_cfg_icu_buffers(&cfg, data_to_compress, 2, NULL, NULL, + (uint32_t *)compressed_data, 1); + TEST_ASSERT_EQUAL_INT(sizeof(compressed_data), compressed_data_size); + + /* compressed data are to small for the compressed_data buffer */ + data_p[0].fx = 42; + data_p[0].efx = 42; + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_SMALL_BUF, cmp_bits); + + /* efx value is to big for the max used bits values */ + data_p[0].efx = 0x80000000; + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + data_p[0].efx = 0x7FFFFFFF; + + max_used_bits.f_fx= 33; /* more than 32 bits are not allowed */ + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(-1, cmp_bits); + + max_used_bits.f_fx= 32; + max_used_bits.f_efx= 33; /* more than 32 bits are not allowed */ + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(-1, cmp_bits); +} + + +/** + * @test compress_f_fx_ncob + */ + +void test_compress_f_fx_ncob_error_cases(void) +{ + int error, cmp_bits, compressed_data_size; + struct cmp_cfg cfg = {0}; + uint32_t cmp_par_fx = MAX_ICU_GOLOMB_PAR; + uint32_t spillover_fx = 8; + uint32_t cmp_par_ncob = 1; + uint32_t spillover_ncob = 8; + uint8_t data_to_compress[MULTI_ENTRY_HDR_SIZE+2*sizeof(struct f_fx_ncob)] = {0}; + uint8_t compressed_data[MULTI_ENTRY_HDR_SIZE+1*sizeof(struct f_fx_ncob)] = {0}; + struct cmp_max_used_bits max_used_bits = {0}; + struct f_fx_ncob *data_p = (struct f_fx_ncob *)&data_to_compress[MULTI_ENTRY_HDR_SIZE]; + + max_used_bits.f_fx = 31; + max_used_bits.f_ncob = 23; + cmp_set_max_used_bits(&max_used_bits); + + cfg = cmp_cfg_icu_create(DATA_TYPE_F_FX_NCOB, CMP_MODE_DIFF_ZERO, 0, CMP_LOSSLESS); + TEST_ASSERT(cfg.data_type != DATA_TYPE_UNKNOWN); + + error = cmp_cfg_fx_cob(&cfg, CMP_PAR_UNUSED, CMP_PAR_UNUSED, + cmp_par_fx, spillover_fx, cmp_par_ncob, spillover_ncob, + CMP_PAR_UNUSED, CMP_PAR_UNUSED, CMP_PAR_UNUSED, + CMP_PAR_UNUSED, CMP_PAR_UNUSED, CMP_PAR_UNUSED); + TEST_ASSERT_FALSE(error); + + compressed_data_size = cmp_cfg_icu_buffers(&cfg, data_to_compress, 2, NULL, NULL, + (uint32_t *)compressed_data, 1); + TEST_ASSERT_EQUAL_INT(sizeof(compressed_data), compressed_data_size); + + /* compressed data are to small for the compressed_data buffer */ + data_p[0].fx = 42; + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_SMALL_BUF, cmp_bits); + + /* value is to big for the max used bits values */ + data_p[0].ncob_x = 0x800000; + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + data_p[0].ncob_x = 0x7FFFFF; + data_p[0].ncob_y = 0x800000; + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + data_p[0].ncob_y = 0x7FFFFF; + + max_used_bits.f_fx= 33; /* more than 32 bits are not allowed */ + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(-1, cmp_bits); + + max_used_bits.f_fx= 32; + max_used_bits.f_ncob= 33; /* more than 32 bits are not allowed */ + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(-1, cmp_bits); +} + + +/** + * @test compress_f_fx_efx_ncob_ecob + */ + +void test_compress_f_fx_efx_ncob_ecob(void) +{ + int error, cmp_bits, compressed_data_size; + struct cmp_cfg cfg = {0}; + uint32_t cmp_par_fx = 1; + uint32_t spillover_fx = 8; + uint32_t cmp_par_ncob = 2; + uint32_t spillover_ncob = 10; + uint32_t cmp_par_efx = 3; + uint32_t spillover_efx = 44; + uint32_t cmp_par_ecob = 5; + uint32_t spillover_ecob = 55; + uint8_t data_to_compress[MULTI_ENTRY_HDR_SIZE+4*sizeof(struct f_fx_efx_ncob_ecob)] = {0}; + uint8_t compressed_data[MULTI_ENTRY_HDR_SIZE+1*sizeof(struct f_fx_efx_ncob_ecob)] = {0}; + struct cmp_max_used_bits max_used_bits = {0}; + struct f_fx_efx_ncob_ecob *data_p = (struct f_fx_efx_ncob_ecob *)&data_to_compress[MULTI_ENTRY_HDR_SIZE]; + + max_used_bits.f_fx = 31; + max_used_bits.f_ncob = 3; + max_used_bits.f_efx = 16; + max_used_bits.f_ecob = 8; + cmp_set_max_used_bits(&max_used_bits); + + cfg = cmp_cfg_icu_create(DATA_TYPE_F_FX_EFX_NCOB_ECOB, CMP_MODE_DIFF_ZERO, 0, CMP_LOSSLESS); + TEST_ASSERT(cfg.data_type != DATA_TYPE_UNKNOWN); + + error = cmp_cfg_fx_cob(&cfg, CMP_PAR_UNUSED, CMP_PAR_UNUSED, + cmp_par_fx, spillover_fx, cmp_par_ncob, spillover_ncob, + cmp_par_efx, spillover_efx, cmp_par_ecob, spillover_ecob, + CMP_PAR_UNUSED, CMP_PAR_UNUSED); + TEST_ASSERT_FALSE(error); + + compressed_data_size = cmp_cfg_icu_buffers(&cfg, data_to_compress, 4, NULL, NULL, + (uint32_t *)compressed_data, 1); + TEST_ASSERT_EQUAL_INT(sizeof(compressed_data), compressed_data_size); + + /* value is to big for the max used bits values */ + data_p[3].fx = 0x80000000; + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + + data_p[3].fx = 0x80000000-1; + data_p[2].ncob_x = 0x8; + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + + data_p[2].ncob_x = 0x7; + data_p[1].ncob_y = 0x8; + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + + data_p[1].ncob_y = 0x7; + data_p[0].efx = 0x10000; + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + + data_p[0].efx = 0x10000-1; + data_p[2].ecob_x = 0x100; + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + + data_p[2].ecob_x = 0x100-1; + data_p[3].ecob_y = 0x100; + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + data_p[3].ecob_y = 0x100-1; + + max_used_bits.f_fx = 33; /* more than 32 bits are not allowed */ + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(-1, cmp_bits); + + max_used_bits.f_fx = 32; + max_used_bits.f_ncob = 33; /* more than 32 bits are not allowed */ + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(-1, cmp_bits); + + max_used_bits.f_ncob = 32; + max_used_bits.f_efx = 33; /* more than 32 bits are not allowed */ + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(-1, cmp_bits); + + max_used_bits.f_efx = 32; + max_used_bits.f_ecob = 33; /* more than 32 bits are not allowed */ + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(-1, cmp_bits); +} + + +/** + * @test compress_l_fx + */ + +void test_compress_l_fx_error_cases(void) +{ + int error, cmp_bits, compressed_data_size; + struct cmp_cfg cfg = {0}; + uint32_t cmp_par_exp_flags = 3; + uint32_t spillover_exp_flags = 10; + uint32_t cmp_par_fx = 1; + uint32_t spillover_fx = 8; + uint32_t cmp_par_fx_cob_variance = 30; + uint32_t spillover_fx_cob_variance = 8; + uint8_t data_to_compress[MULTI_ENTRY_HDR_SIZE+3*sizeof(struct l_fx)] = {0}; + uint8_t compressed_data[MULTI_ENTRY_HDR_SIZE+1*sizeof(struct l_fx)] = {0}; + struct cmp_max_used_bits max_used_bits = {0}; + struct l_fx *data_p = (struct l_fx *)&data_to_compress[MULTI_ENTRY_HDR_SIZE]; + + max_used_bits.l_exp_flags = 23; + max_used_bits.l_fx = 31; + max_used_bits.l_efx = 1; + max_used_bits.l_fx_variance = 23; + cmp_set_max_used_bits(&max_used_bits); + + cfg = cmp_cfg_icu_create(DATA_TYPE_L_FX, CMP_MODE_DIFF_ZERO, 0, CMP_LOSSLESS); + TEST_ASSERT(cfg.data_type != DATA_TYPE_UNKNOWN); + + error = cmp_cfg_fx_cob(&cfg, cmp_par_exp_flags, spillover_exp_flags, + cmp_par_fx, spillover_fx, CMP_PAR_UNUSED, CMP_PAR_UNUSED, + CMP_PAR_UNUSED, CMP_PAR_UNUSED, CMP_PAR_UNUSED, CMP_PAR_UNUSED, + cmp_par_fx_cob_variance, spillover_fx_cob_variance); + TEST_ASSERT_FALSE(error); + + compressed_data_size = cmp_cfg_icu_buffers(&cfg, data_to_compress, 3, NULL, NULL, + (uint32_t *)compressed_data, 1); + TEST_ASSERT_EQUAL_INT(sizeof(compressed_data), compressed_data_size); + + /* value is to big for the max used bits values */ + data_p[2].exp_flags = 0x800000; + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + + data_p[2].exp_flags = 0x800000-1; + data_p[2].fx = 0x80000000; + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + + data_p[2].fx = 0x80000000-1; + data_p[0].fx_variance = 0x800000; + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + + data_p[0].fx_variance = 0x800000-1; + + max_used_bits.l_exp_flags = 33; /* more than 32 bits are not allowed */ + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(-1, cmp_bits); + + max_used_bits.l_exp_flags = 32; + max_used_bits.l_fx = 33; /* more than 32 bits are not allowed */ + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(-1, cmp_bits); + + max_used_bits.l_fx = 32; + max_used_bits.l_fx_variance = 33; /* more than 32 bits are not allowed */ + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(-1, cmp_bits); +} + + +/** + * @test compress_l_fx_efx + */ + +void test_compress_l_fx_efx_error_cases(void) +{ + int error, cmp_bits, compressed_data_size; + struct cmp_cfg cfg = {0}; + uint32_t cmp_par_exp_flags = MAX_ICU_GOLOMB_PAR; + uint32_t spillover_exp_flags = cmp_icu_max_spill(cmp_par_exp_flags); + uint32_t cmp_par_fx = 1; + uint32_t spillover_fx = 8; + uint32_t cmp_par_efx = 3; + uint32_t spillover_efx = 44; + uint32_t cmp_par_fx_cob_variance = 30; + uint32_t spillover_fx_cob_variance = 8; + uint8_t data_to_compress[MULTI_ENTRY_HDR_SIZE+3*sizeof(struct l_fx_efx)] = {0}; + uint8_t compressed_data[MULTI_ENTRY_HDR_SIZE+1*sizeof(struct l_fx_efx)] = {0}; + struct cmp_max_used_bits max_used_bits = {0}; + struct l_fx_efx *data_p = (struct l_fx_efx *)&data_to_compress[MULTI_ENTRY_HDR_SIZE]; + + max_used_bits.l_exp_flags = 23; + max_used_bits.l_fx = 31; + max_used_bits.l_efx = 1; + max_used_bits.l_fx_variance = 23; + cmp_set_max_used_bits(&max_used_bits); + + cfg = cmp_cfg_icu_create(DATA_TYPE_L_FX_EFX, CMP_MODE_DIFF_ZERO, 0, CMP_LOSSLESS); + TEST_ASSERT(cfg.data_type != DATA_TYPE_UNKNOWN); + + error = cmp_cfg_fx_cob(&cfg, cmp_par_exp_flags, spillover_exp_flags, + cmp_par_fx, spillover_fx, CMP_PAR_UNUSED, CMP_PAR_UNUSED, + cmp_par_efx, spillover_efx, CMP_PAR_UNUSED, CMP_PAR_UNUSED, + cmp_par_fx_cob_variance, spillover_fx_cob_variance); + TEST_ASSERT_FALSE(error); + + compressed_data_size = cmp_cfg_icu_buffers(&cfg, data_to_compress, 3, NULL, NULL, + (uint32_t *)compressed_data, 1); + TEST_ASSERT_EQUAL_INT(sizeof(compressed_data), compressed_data_size); + + /* value is to big for the max used bits values */ + data_p[2].exp_flags = 0x800000; + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + + data_p[2].exp_flags = 0x800000-1; + data_p[2].fx = 0x80000000; + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + + data_p[2].fx = 0x80000000-1; + data_p[1].efx = 0x2; + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + + data_p[1].efx = 0x1; + data_p[0].fx_variance = 0x800000; + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + + data_p[0].fx_variance = 0x800000-1; + + max_used_bits.l_exp_flags = 33; /* more than 32 bits are not allowed */ + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(-1, cmp_bits); + + max_used_bits.l_exp_flags = 32; + max_used_bits.l_fx = 33; /* more than 32 bits are not allowed */ + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(-1, cmp_bits); + + max_used_bits.l_fx = 32; + max_used_bits.l_efx = 33; /* more than 32 bits are not allowed */ + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(-1, cmp_bits); + + max_used_bits.l_efx = 32; + max_used_bits.l_fx_variance = 33; /* more than 32 bits are not allowed */ + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(-1, cmp_bits); +} + + +/** + * @test compress_l_fx_ncob + */ + +void test_compress_l_fx_ncob_error_cases(void) +{ + int error, cmp_bits, compressed_data_size; + struct cmp_cfg cfg = {0}; + uint32_t cmp_par_exp_flags = MAX_ICU_GOLOMB_PAR; + uint32_t spillover_exp_flags = cmp_icu_max_spill(cmp_par_exp_flags); + uint32_t cmp_par_fx = 1; + uint32_t spillover_fx = 8; + uint32_t cmp_par_ncob = 2; + uint32_t spillover_ncob = 10; + uint32_t cmp_par_fx_cob_variance = 30; + uint32_t spillover_fx_cob_variance = 8; + uint8_t data_to_compress[MULTI_ENTRY_HDR_SIZE+3*sizeof(struct l_fx_ncob)] = {0}; + uint8_t compressed_data[MULTI_ENTRY_HDR_SIZE+1*sizeof(struct l_fx_ncob)] = {0}; + struct cmp_max_used_bits max_used_bits = {0}; + struct l_fx_ncob *data_p = (struct l_fx_ncob *)&data_to_compress[MULTI_ENTRY_HDR_SIZE]; + + max_used_bits.l_exp_flags = 23; + max_used_bits.l_fx = 31; + max_used_bits.l_ncob = 2; + max_used_bits.l_fx_variance = 23; + max_used_bits.l_cob_variance = 11; + cmp_set_max_used_bits(&max_used_bits); + + cfg = cmp_cfg_icu_create(DATA_TYPE_L_FX_NCOB, CMP_MODE_DIFF_ZERO, 0, CMP_LOSSLESS); + TEST_ASSERT(cfg.data_type != DATA_TYPE_UNKNOWN); + + error = cmp_cfg_fx_cob(&cfg, cmp_par_exp_flags, spillover_exp_flags, + cmp_par_fx, spillover_fx, cmp_par_ncob, spillover_ncob, + CMP_PAR_UNUSED, CMP_PAR_UNUSED, CMP_PAR_UNUSED, CMP_PAR_UNUSED, + cmp_par_fx_cob_variance, spillover_fx_cob_variance); + TEST_ASSERT_FALSE(error); + + compressed_data_size = cmp_cfg_icu_buffers(&cfg, data_to_compress, 3, NULL, NULL, + (uint32_t *)compressed_data, 1); + TEST_ASSERT_EQUAL_INT(sizeof(compressed_data), compressed_data_size); + + /* value is to big for the max used bits values */ + data_p[2].exp_flags = 0x800000; + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + + data_p[2].exp_flags = 0x800000-1; + data_p[2].fx = 0x80000000; + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + + data_p[2].fx = 0x80000000-1; + data_p[2].ncob_x = 0x4; + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + + data_p[2].ncob_x = 0x3; + data_p[2].ncob_y = 0x4; + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + + data_p[2].ncob_y = 0x3; + data_p[0].fx_variance = 0x800000; + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + + data_p[0].fx_variance = 0x800000-1; + data_p[2].cob_x_variance = 0x800; + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + + data_p[2].cob_x_variance = 0x800-1; + data_p[2].cob_y_variance = 0x800; + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + + data_p[2].cob_y_variance = 0x800-1; + + max_used_bits.l_exp_flags = 33; /* more than 32 bits are not allowed */ + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(-1, cmp_bits); + + max_used_bits.l_exp_flags = 32; + max_used_bits.l_fx = 33; /* more than 32 bits are not allowed */ + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(-1, cmp_bits); + + max_used_bits.l_fx = 32; + max_used_bits.l_ncob = 33; /* more than 32 bits are not allowed */ + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(-1, cmp_bits); + + max_used_bits.l_ncob = 32; + max_used_bits.l_fx_variance = 33; /* more than 32 bits are not allowed */ + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(-1, cmp_bits); + + max_used_bits.l_fx_variance = 32; + max_used_bits.l_cob_variance = 33; /* more than 32 bits are not allowed */ + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(-1, cmp_bits); +} + + +/** + * @test compress_l_fx_efx_ncob_ecob + */ + +void test_compress_l_fx_efx_ncob_ecob_error_cases(void) +{ + int error, cmp_bits, compressed_data_size; + struct cmp_cfg cfg = {0}; + uint32_t cmp_par_exp_flags = MAX_ICU_GOLOMB_PAR; + uint32_t spillover_exp_flags = cmp_icu_max_spill(cmp_par_exp_flags); + uint32_t cmp_par_fx = 1; + uint32_t spillover_fx = 8; + uint32_t cmp_par_ncob = 2; + uint32_t spillover_ncob = 10; + uint32_t cmp_par_efx = 3; + uint32_t spillover_efx = 44; + uint32_t cmp_par_ecob = 5; + uint32_t spillover_ecob = 55; + uint32_t cmp_par_fx_cob_variance = 30; + uint32_t spillover_fx_cob_variance = 8; + uint8_t data_to_compress[MULTI_ENTRY_HDR_SIZE+3*sizeof(struct l_fx_efx_ncob_ecob)] = {0}; + uint8_t compressed_data[MULTI_ENTRY_HDR_SIZE+1*sizeof(struct l_fx_efx_ncob_ecob)] = {0}; + struct cmp_max_used_bits max_used_bits = {0}; + struct l_fx_efx_ncob_ecob *data_p = (struct l_fx_efx_ncob_ecob *)&data_to_compress[MULTI_ENTRY_HDR_SIZE]; + + max_used_bits.l_exp_flags = 23; + max_used_bits.l_fx = 31; + max_used_bits.l_ncob = 2; + max_used_bits.l_efx = 1; + max_used_bits.l_ecob = 3; + max_used_bits.l_fx_variance = 23; + max_used_bits.l_cob_variance = 11; + cmp_set_max_used_bits(&max_used_bits); + + cfg = cmp_cfg_icu_create(DATA_TYPE_L_FX_EFX_NCOB_ECOB, CMP_MODE_DIFF_ZERO, 0, CMP_LOSSLESS); + TEST_ASSERT(cfg.data_type != DATA_TYPE_UNKNOWN); + + error = cmp_cfg_fx_cob(&cfg, cmp_par_exp_flags, spillover_exp_flags, + cmp_par_fx, spillover_fx, cmp_par_ncob, spillover_ncob, + cmp_par_efx, spillover_efx, cmp_par_ecob, spillover_ecob, + cmp_par_fx_cob_variance, spillover_fx_cob_variance); + TEST_ASSERT_FALSE(error); + + compressed_data_size = cmp_cfg_icu_buffers(&cfg, data_to_compress, 3, NULL, NULL, + (uint32_t *)compressed_data, 1); + TEST_ASSERT_EQUAL_INT(sizeof(compressed_data), compressed_data_size); + + /* value is to big for the max used bits values */ + data_p[2].exp_flags = 0x800000; + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + + data_p[2].exp_flags = 0x800000-1; + data_p[2].fx = 0x80000000; + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + + data_p[2].fx = 0x80000000-1; + data_p[2].ncob_x = 0x4; + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + + data_p[2].ncob_x = 0x3; + data_p[2].ncob_y = 0x4; + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + + data_p[2].ncob_y = 0x3; + data_p[1].efx = 0x2; + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + + data_p[1].efx = 0x1; + data_p[1].ecob_x = 0x8; + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + + data_p[1].ecob_x = 0x7; + data_p[1].ecob_y = 0x8; + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + + data_p[1].ecob_y = 0x7; + data_p[0].fx_variance = 0x800000; + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + + data_p[0].fx_variance = 0x800000-1; + data_p[2].cob_x_variance = 0x800; + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + + data_p[2].cob_x_variance = 0x800-1; + data_p[2].cob_y_variance = 0x800; + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + + data_p[2].cob_y_variance = 0x800-1; + + max_used_bits.l_exp_flags = 33; /* more than 32 bits are not allowed */ + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(-1, cmp_bits); + + max_used_bits.l_exp_flags = 32; + max_used_bits.l_fx = 33; /* more than 32 bits are not allowed */ + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(-1, cmp_bits); + + max_used_bits.l_fx = 32; + max_used_bits.l_ncob = 33; /* more than 32 bits are not allowed */ + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(-1, cmp_bits); + + max_used_bits.l_ncob = 32; + max_used_bits.l_efx = 33; /* more than 32 bits are not allowed */ + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(-1, cmp_bits); + + max_used_bits.l_efx = 32; + max_used_bits.l_ecob = 33; /* more than 32 bits are not allowed */ + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(-1, cmp_bits); + + max_used_bits.l_ecob = 32; + max_used_bits.l_fx_variance = 33; /* more than 32 bits are not allowed */ + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(-1, cmp_bits); + + max_used_bits.l_fx_variance = 32; + max_used_bits.l_cob_variance = 33; /* more than 32 bits are not allowed */ + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(-1, cmp_bits); +} + + +/** + * @test compress_nc_offset + */ + +void test_compress_nc_offset_error_cases(void) +{ + int error, cmp_bits, compressed_data_size; + struct cmp_cfg cfg = {0}; + uint32_t cmp_par_mean = 1; + uint32_t spillover_mean = 2; + uint32_t cmp_par_variance = MAX_ICU_GOLOMB_PAR; + uint32_t spillover_variance = cmp_icu_max_spill(MAX_ICU_GOLOMB_PAR); + uint8_t data_to_compress[MULTI_ENTRY_HDR_SIZE+3*sizeof(struct nc_offset)] = {0}; + uint8_t compressed_data[MULTI_ENTRY_HDR_SIZE+1*sizeof(struct nc_offset)] = {0}; + struct cmp_max_used_bits max_used_bits = {0}; + struct nc_offset *data_p = (struct nc_offset *)&data_to_compress[MULTI_ENTRY_HDR_SIZE]; + + max_used_bits.nc_offset_mean = 1; + max_used_bits.nc_offset_variance = 31; + cmp_set_max_used_bits(&max_used_bits); + + cfg = cmp_cfg_icu_create(DATA_TYPE_OFFSET, CMP_MODE_DIFF_MULTI, 0, CMP_LOSSLESS); + TEST_ASSERT(cfg.data_type != DATA_TYPE_UNKNOWN); + + error = cmp_cfg_aux(&cfg, cmp_par_mean, spillover_mean, + cmp_par_variance, spillover_variance, + CMP_PAR_UNUSED, CMP_PAR_UNUSED); + TEST_ASSERT_FALSE(error); + + compressed_data_size = cmp_cfg_icu_buffers(&cfg, data_to_compress, 3, NULL, NULL, + (uint32_t *)compressed_data, 1); + TEST_ASSERT_EQUAL_INT(sizeof(compressed_data), compressed_data_size); + + /* value is to big for the max used bits values */ + data_p[0].mean = 0x2; + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + + data_p[0].mean = 0x1; + data_p[1].variance = 0x80000000; + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + + data_p[1].variance = 0x80000000-1; + + max_used_bits.nc_offset_mean = 33; /* more than 32 bits are not allowed */ + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(-1, cmp_bits); + + max_used_bits.nc_offset_mean = 32; + max_used_bits.nc_offset_variance = 33; /* more than 32 bits are not allowed */ + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(-1, cmp_bits); +} + + +/** + * @test compress_nc_background + */ + +void test_compress_nc_background_error_cases(void) +{ + int error, cmp_bits, compressed_data_size; + struct cmp_cfg cfg = {0}; + uint32_t cmp_par_mean = 1; + uint32_t spillover_mean = 2; + uint32_t cmp_par_variance = MAX_ICU_GOLOMB_PAR; + uint32_t spillover_variance = cmp_icu_max_spill(MAX_ICU_GOLOMB_PAR); + uint32_t cmp_par_pixels_error = 23; + uint32_t spillover_pixels_error = 42; + uint8_t data_to_compress[MULTI_ENTRY_HDR_SIZE+3*sizeof(struct nc_background)] = {0}; + uint8_t compressed_data[MULTI_ENTRY_HDR_SIZE+1*sizeof(struct nc_background)] = {0}; + struct cmp_max_used_bits max_used_bits = {0}; + struct nc_background *data_p = (struct nc_background *)&data_to_compress[MULTI_ENTRY_HDR_SIZE]; + + max_used_bits.nc_background_mean = 1; + max_used_bits.nc_background_variance = 31; + max_used_bits.nc_background_outlier_pixels = 2; + cmp_set_max_used_bits(&max_used_bits); + + cfg = cmp_cfg_icu_create(DATA_TYPE_BACKGROUND, CMP_MODE_DIFF_MULTI, 0, CMP_LOSSLESS); + TEST_ASSERT(cfg.data_type != DATA_TYPE_UNKNOWN); + + error = cmp_cfg_aux(&cfg, cmp_par_mean, spillover_mean, + cmp_par_variance, spillover_variance, + cmp_par_pixels_error, spillover_pixels_error); + TEST_ASSERT_FALSE(error); + + compressed_data_size = cmp_cfg_icu_buffers(&cfg, data_to_compress, 3, NULL, NULL, + (uint32_t *)compressed_data, 1); + TEST_ASSERT_EQUAL_INT(sizeof(compressed_data), compressed_data_size); + + /* value is to big for the max used bits values */ + data_p[0].mean = 0x2; + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + + data_p[0].mean = 0x1; + data_p[1].variance = 0x80000000; + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + + data_p[1].variance = 0x80000000-1; + data_p[1].outlier_pixels = 0x4; + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + + data_p[1].outlier_pixels = 0x3; + + max_used_bits.nc_background_mean = 33; /* more than 32 bits are not allowed */ + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(-1, cmp_bits); + + max_used_bits.nc_background_mean = 32; + max_used_bits.nc_background_variance = 33; /* more than 32 bits are not allowed */ + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(-1, cmp_bits); + + max_used_bits.nc_background_variance = 32; + max_used_bits.nc_background_outlier_pixels = 33; /* more than 32 bits are not allowed */ + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(-1, cmp_bits); +} + + +/** + * @test compress_smearing + */ + +void test_compress_smearing_error_cases(void) +{ + int error, cmp_bits, compressed_data_size; + struct cmp_cfg cfg = {0}; + uint32_t cmp_par_mean = 1; + uint32_t spillover_mean = 2; + uint32_t cmp_par_variance = MAX_ICU_GOLOMB_PAR; + uint32_t spillover_variance = cmp_icu_max_spill(MAX_ICU_GOLOMB_PAR); + uint32_t cmp_par_pixels_error = 23; + uint32_t spillover_pixels_error = 42; + uint8_t data_to_compress[MULTI_ENTRY_HDR_SIZE+3*sizeof(struct smearing)] = {0}; + uint8_t compressed_data[MULTI_ENTRY_HDR_SIZE+1*sizeof(struct smearing)] = {0}; + struct cmp_max_used_bits max_used_bits = {0}; + struct smearing *data_p = (struct smearing *)&data_to_compress[MULTI_ENTRY_HDR_SIZE]; + + max_used_bits.smearing_mean = 1; + max_used_bits.smearing_variance_mean = 15; + max_used_bits.smearing_outlier_pixels = 2; + cmp_set_max_used_bits(&max_used_bits); + + cfg = cmp_cfg_icu_create(DATA_TYPE_SMEARING, CMP_MODE_DIFF_MULTI, 0, CMP_LOSSLESS); + TEST_ASSERT(cfg.data_type != DATA_TYPE_UNKNOWN); + + error = cmp_cfg_aux(&cfg, cmp_par_mean, spillover_mean, + cmp_par_variance, spillover_variance, + cmp_par_pixels_error, spillover_pixels_error); + TEST_ASSERT_FALSE(error); + + compressed_data_size = cmp_cfg_icu_buffers(&cfg, data_to_compress, 3, NULL, NULL, + (uint32_t *)compressed_data, 1); + TEST_ASSERT_EQUAL_INT(sizeof(compressed_data), compressed_data_size); + + /* value is to big for the max used bits values */ + data_p[0].mean = 0x2; + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + + data_p[0].mean = 0x1; + data_p[1].variance_mean = 0x8000; + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + + data_p[1].variance_mean = 0x8000-1; + data_p[1].outlier_pixels = 0x4; + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); + + data_p[1].outlier_pixels = 0x3; + + max_used_bits.smearing_mean = 33; /* more than 32 bits are not allowed */ + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(-1, cmp_bits); + + max_used_bits.smearing_mean = 32; + max_used_bits.smearing_variance_mean = 33; /* more than 32 bits are not allowed */ + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(-1, cmp_bits); + + max_used_bits.smearing_variance_mean = 32; + max_used_bits.smearing_outlier_pixels = 33; /* more than 32 bits are not allowed */ + cmp_set_max_used_bits(&max_used_bits); + cmp_bits = icu_compress_data(&cfg); + TEST_ASSERT_EQUAL_INT(-1, cmp_bits); +} + + +/** + * @test pad_bitstream + */ + +void test_pad_bitstream(void) +{ + struct cmp_cfg cfg = {0}; + int cmp_size; + int cmp_size_return; + uint32_t cmp_data[3]; + const int MAX_BIT_LEN = 96; + + memset(cmp_data, 0xFF, sizeof(cmp_data)); + cfg.icu_output_buf = cmp_data; + cfg.data_type = DATA_TYPE_IMAGETTE; /* 16 bit samples */ + cfg.buffer_length = 6; /* 6 * 16 bit samples -> 3 * 32 bit */ + + /* test negative cmp_size */ + cmp_size = -1; + cmp_size_return = pad_bitstream(&cfg, cmp_size); + TEST_ASSERT_EQUAL_INT(-1, cmp_size_return); + cmp_size = -3; + cmp_size_return = pad_bitstream(&cfg, cmp_size); + TEST_ASSERT_EQUAL_INT(-3, cmp_size_return); + + /* test RAW_MODE */ + cfg.cmp_mode = CMP_MODE_RAW; + cmp_size = MAX_BIT_LEN; + cmp_size_return = pad_bitstream(&cfg, cmp_size); + TEST_ASSERT_EQUAL_INT(MAX_BIT_LEN, cmp_size_return); + TEST_ASSERT_EQUAL_INT(cmp_data[0], 0xFFFFFFFF); + TEST_ASSERT_EQUAL_INT(cmp_data[1], 0xFFFFFFFF); + TEST_ASSERT_EQUAL_INT(cmp_data[2], 0xFFFFFFFF); + + /* test Normal operation */ + cfg.cmp_mode = CMP_MODE_MODEL_MULTI; + cmp_size = 0; + /* set the first 32 bits zero no change should occur */ + cmp_size = put_n_bits32(0, 32, cmp_size, cfg.icu_output_buf, MAX_BIT_LEN); + cmp_size_return = pad_bitstream(&cfg, cmp_size); + TEST_ASSERT_EQUAL_INT(cmp_size, cmp_size_return); + TEST_ASSERT_EQUAL_INT(cmp_data[0], 0); + TEST_ASSERT_EQUAL_INT(cmp_data[1], 0xFFFFFFFF); + TEST_ASSERT_EQUAL_INT(cmp_data[2], 0xFFFFFFFF); + + /* set the first 33 bits zero; and checks the padding */ + cmp_size = put_n_bits32(0, 1, cmp_size, cfg.icu_output_buf, MAX_BIT_LEN); + cmp_size_return = pad_bitstream(&cfg, cmp_size); + TEST_ASSERT_EQUAL_INT(cmp_size, cmp_size_return); + TEST_ASSERT_EQUAL_INT(cmp_data[0], 0); + TEST_ASSERT_EQUAL_INT(cmp_data[1], 0); + TEST_ASSERT_EQUAL_INT(cmp_data[2], 0xFFFFFFFF); + + /* set the first 63 bits zero; and checks the padding */ + cmp_data[1] = 0xFFFFFFFF; + cmp_size = 32; + cmp_size = put_n_bits32(0, 31, cmp_size, cfg.icu_output_buf, MAX_BIT_LEN); + cmp_size_return = pad_bitstream(&cfg, cmp_size); + TEST_ASSERT_EQUAL_INT(cmp_size, cmp_size_return); + TEST_ASSERT_EQUAL_INT(cmp_data[0], 0); + TEST_ASSERT_EQUAL_INT(cmp_data[1], 0); + TEST_ASSERT_EQUAL_INT(cmp_data[2], 0xFFFFFFFF); + + /* error case the rest of the compressed data are to small dor a 32 bit + * access */ + cfg.buffer_length = 5; + cmp_size = 64; + cmp_size = put_n_bits32(0, 1, cmp_size, cfg.icu_output_buf, MAX_BIT_LEN); + cmp_size_return = pad_bitstream(&cfg, cmp_size); + TEST_ASSERT_EQUAL_INT(CMP_ERROR_SMALL_BUF, cmp_size_return); +} + + +/** + * @test cmp_data_to_big_endian + */ + +void test_cmp_data_to_big_endian_error_cases(void) +{ + struct cmp_cfg cfg = {0}; + int cmp_size; + int cmp_size_return; + uint16_t cmp_data[3] = {0x0123, 0x4567, 0x89AB}; + uint8_t *p; + + cfg.icu_output_buf = (uint32_t *)cmp_data; + + /* this should work */ + cfg.data_type = DATA_TYPE_IMAGETTE; + cfg.cmp_mode = CMP_MODE_RAW; + cmp_size = 48; + cmp_size_return = cmp_data_to_big_endian(&cfg, cmp_size); + TEST_ASSERT_EQUAL_INT(cmp_size_return, 48); + p = (uint8_t *)cfg.icu_output_buf; + TEST_ASSERT_EQUAL(p[0], 0x01); + TEST_ASSERT_EQUAL(p[1], 0x23); + TEST_ASSERT_EQUAL(p[2], 0x45); + TEST_ASSERT_EQUAL(p[3], 0x67); + TEST_ASSERT_EQUAL(p[4], 0x89); + TEST_ASSERT_EQUAL(p[5], 0xAB); + + /* error cases */ + cmp_data[0] = 0x0123; + cmp_data[1] = 0x4567; + cmp_data[2] = 0x89AB; + cfg.data_type = DATA_TYPE_IMAGETTE; + cfg.cmp_mode = CMP_MODE_RAW; + cmp_size = 47; /* wrong size */ + cmp_size_return = cmp_data_to_big_endian(&cfg, cmp_size); + TEST_ASSERT_EQUAL_INT(cmp_size_return, -1); + + cmp_data[0] = 0x0123; + cmp_data[1] = 0x4567; + cmp_data[2] = 0x89AB; + cfg.data_type = DATA_TYPE_IMAGETTE; + cfg.cmp_mode = CMP_MODE_RAW; + cmp_size = 49; /* wrong size */ + cmp_size_return = cmp_data_to_big_endian(&cfg, cmp_size); + TEST_ASSERT_EQUAL_INT(cmp_size_return, -1); + + cmp_data[0] = 0x0123; + cmp_data[1] = 0x4567; + cmp_data[2] = 0x89AB; + cfg.data_type = DATA_TYPE_UNKNOWN; /* wrong data_type */ + cfg.cmp_mode = CMP_MODE_RAW; + cmp_size = 48; + cmp_size_return = cmp_data_to_big_endian(&cfg, cmp_size); + TEST_ASSERT_EQUAL_INT(cmp_size_return, -1); +} /** @@ -3024,8 +4364,6 @@ void test_icu_compress_data_error_cases(void) { int cmp_size; struct cmp_cfg cfg = {0}; - uint16_t data[4] = {0, 0xFFFF, 23, 42}; - uint32_t cmp_data_buf[4] = {0}; /* cfg = NULL test */ cmp_size = icu_compress_data(NULL); @@ -3035,6 +4373,5 @@ void test_icu_compress_data_error_cases(void) cfg.samples = 0; cmp_size = icu_compress_data(&cfg); TEST_ASSERT_EQUAL(0, cmp_size); - }