From 6456189e1f611519e7180f7b8a9eaf569ec8847b Mon Sep 17 00:00:00 2001 From: Dominik Loidolt <dominik.loidolt@univie.ac.at> Date: Fri, 9 Aug 2024 15:51:11 +0200 Subject: [PATCH] Refactor: Remove deprecated ICU compression interface Removed the following obsolete functions: - icu_compress - cmp_cfg_icu_create - cmp_cfg_icu_buffers - cmp_cfg_icu_imagette - cmp_cfg_fx_cob - cmp_cfg_aux These have been replaced with the chunk compression functions (compress_chunk() and friends). --- lib/cmp_icu.h | 36 - lib/icu_compress/cmp_icu.c | 325 ---- test/cmp_decmp/test_cmp_decmp.c | 135 +- test/cmp_icu/test_cmp_icu.c | 3040 ++----------------------------- 4 files changed, 174 insertions(+), 3362 deletions(-) diff --git a/lib/cmp_icu.h b/lib/cmp_icu.h index 2c431e7..966caf3 100644 --- a/lib/cmp_icu.h +++ b/lib/cmp_icu.h @@ -22,42 +22,6 @@ #include "common/cmp_support.h" -#define CMP_PAR_UNUSED 0 int32_t compress_like_rdcu(const struct rdcu_cfg *rcfg, struct cmp_info *info); -/* create and setup a compression configuration */ -struct cmp_cfg cmp_cfg_icu_create(enum cmp_data_type data_type, enum cmp_mode cmp_mode, - uint32_t model_value, uint32_t lossy_par); - -/* set up the different data buffers for an ICU compression */ -uint32_t cmp_cfg_icu_buffers(struct cmp_cfg *cfg, void *data_to_compress, - uint32_t data_samples, void *model_of_data, - void *updated_model, uint32_t *compressed_data, - uint32_t compressed_data_len_samples); - - /* set up the configuration parameters for an ICU imagette compression */ -int cmp_cfg_icu_imagette(struct cmp_cfg *cfg, uint32_t cmp_par, - uint32_t spillover_par); - -/* set up the configuration parameters for a flux/COB compression */ -int cmp_cfg_fx_cob(struct cmp_cfg *cfg, - uint32_t cmp_par_exp_flags, uint32_t spillover_exp_flags, - uint32_t cmp_par_fx, uint32_t spillover_fx, - uint32_t cmp_par_ncob, uint32_t spillover_ncob, - uint32_t cmp_par_efx, uint32_t spillover_efx, - uint32_t cmp_par_ecob, uint32_t spillover_ecob, - uint32_t cmp_par_fx_cob_variance, uint32_t spillover_fx_cob_variance); - -/* set up the configuration parameters for an auxiliary science data compression */ -int cmp_cfg_aux(struct cmp_cfg *cfg, - uint32_t cmp_par_mean, uint32_t spillover_mean, - uint32_t cmp_par_variance, uint32_t spillover_variance, - uint32_t cmp_par_pixels_error, uint32_t spillover_pixels_error); - -/* set up the max_used_bits used for the compression */ -int cmp_cfg_icu_max_used_bits(struct cmp_cfg *cfg, const struct cmp_max_used_bits *max_used_bits); - -/* start the compression */ -int icu_compress_data(const struct cmp_cfg *cfg); - #endif /* CMP_ICU_H */ diff --git a/lib/icu_compress/cmp_icu.c b/lib/icu_compress/cmp_icu.c index 7b437d7..ec5787b 100644 --- a/lib/icu_compress/cmp_icu.c +++ b/lib/icu_compress/cmp_icu.c @@ -88,282 +88,6 @@ struct encoder_setup { }; -/** - * @brief create an ICU compression configuration - * - * @param data_type compression data product type - * @param cmp_mode compression mode - * @param model_value model weighting parameter (only needed for model compression mode) - * @param lossy_par lossy rounding parameter (use CMP_LOSSLESS for lossless compression) - * - * @returns a compression configuration containing the chosen parameters; - * on error the data_type record is set to DATA_TYPE_UNKNOWN - */ - -struct cmp_cfg cmp_cfg_icu_create(enum cmp_data_type data_type, enum cmp_mode cmp_mode, - uint32_t model_value, uint32_t lossy_par) -{ - struct cmp_cfg cfg; - - memset(&cfg, 0, sizeof(cfg)); - - cfg.data_type = data_type; - cfg.cmp_mode = cmp_mode; - cfg.model_value = model_value; - cfg.round = lossy_par; - cfg.max_used_bits = &MAX_USED_BITS_SAFE; - - if (cmp_cfg_gen_par_is_invalid(&cfg, ICU_CHECK) || data_type == DATA_TYPE_CHUNK) - cfg.data_type = DATA_TYPE_UNKNOWN; - - return cfg; -} - - -/** - * @brief set up the different data buffers for an ICU compression - * - * @param cfg pointer to a compression configuration (created - * with the cmp_cfg_icu_create() function) - * @param data_to_compress pointer to the data to be compressed - * @param data_samples length of the data to be compressed measured in - * data samples/entities (collection header not - * included by imagette data) - * @param model_of_data pointer to model data buffer (can be NULL if no - * model compression mode is used) - * @param updated_model pointer to store the updated model for the next - * model mode compression (can be the same as the model_of_data - * buffer for in-place update or NULL if updated model is not needed) - * @param compressed_data pointer to the compressed data buffer (can be NULL) - * @param compressed_data_len_samples length of the compressed_data buffer in - * measured in the same units as the data_samples - * - * @returns the size of the compressed_data buffer on success; 0 if the - * parameters are invalid - * - * @note There is a difference in the data_samples parameter when compressing - * imagette data compared to compressing non-imagette data! - * When compressing non-imagette data, the compressor expects that the - * collection header will always prefix the non-imagette data. Therefore, the - * data_samples parameter is simply the number of entries in the collection. It - * is not intended to join multiple non-imagette collections and compress them - * together. - * When compressing imagette data, the length of the entire data to be - * compressed, including the collection header, is measured in 16-bit samples. - * The compressor makes in this case no distinction between header and imagette - * data. Therefore, the data_samples parameter is the number of 16-bit imagette - * pixels plus the length of the collection header, measured in 16-bit units. - * The compression of multiple joined collections is possible. - */ - -uint32_t cmp_cfg_icu_buffers(struct cmp_cfg *cfg, void *data_to_compress, - uint32_t data_samples, void *model_of_data, - void *updated_model, uint32_t *compressed_data, - uint32_t compressed_data_len_samples) -{ - uint32_t cmp_data_size, hdr_size; - - if (!cfg) { - debug_print("Error: pointer to the compression configuration structure is NULL."); - return 0; - } - - cfg->input_buf = data_to_compress; - cfg->model_buf = model_of_data; - cfg->samples = data_samples; - cfg->icu_new_model_buf = updated_model; - cfg->icu_output_buf = compressed_data; - /* cfg->buffer_length = cmp_data_size; */ - cfg->buffer_length = compressed_data_len_samples; - - if (cmp_cfg_icu_buffers_is_invalid(cfg)) - return 0; - - cmp_data_size = cmp_cal_size_of_data(compressed_data_len_samples, cfg->data_type); - hdr_size = cmp_ent_cal_hdr_size(cfg->data_type, cfg->cmp_mode == CMP_MODE_RAW); - - if ((cmp_data_size + hdr_size) > CMP_ENTITY_MAX_SIZE || cmp_data_size > CMP_ENTITY_MAX_SIZE) { - debug_print("Error: The buffer for the compressed data is too large to fit in a compression entity."); - return 0; - } - - return cmp_data_size; -} - - -/** - * @brief set up the maximum length of the different data product types for - * an ICU compression - * - * @param cfg pointer to a compression configuration (created with the - * cmp_cfg_icu_create() function) - * @param max_used_bits pointer to a max_used_bits struct containing the maximum - * length of the different data product types - * - * @returns 0 if all max_used_bits parameters are valid, non-zero if parameters are invalid - * - * @note the cmp_cfg_icu_create() function set the max_used_bits configuration to - * MAX_USED_BITS_SAFE - */ - -int cmp_cfg_icu_max_used_bits(struct cmp_cfg *cfg, const struct cmp_max_used_bits *max_used_bits) -{ - if (!cfg) - return -1; - - cfg->max_used_bits = max_used_bits; - - if (cmp_cfg_icu_max_used_bits_out_of_limit(max_used_bits)) - return -1; - - return 0; -} - - -/** - * @brief set up the configuration parameters for an ICU imagette compression - * - * @param cfg pointer to a compression configuration (created - * by the cmp_cfg_icu_create() function) - * @param cmp_par imagette compression parameter (Golomb parameter) - * @param spillover_par imagette spillover threshold parameter - * - * @returns 0 if parameters are valid, non-zero if parameters are invalid - */ - -int cmp_cfg_icu_imagette(struct cmp_cfg *cfg, uint32_t cmp_par, - uint32_t spillover_par) -{ - if (!cfg) - return -1; - - cfg->golomb_par = cmp_par; - cfg->spill = spillover_par; - - if (cmp_cfg_imagette_is_invalid(cfg, ICU_CHECK)) - return -1; - - return 0; -} - - -/** - * @brief set up the configuration parameters for a flux/COB compression - * @note not all parameters are needed for every flux/COB compression data type - * - * @param cfg pointer to a compression configuration (created - * by the cmp_cfg_icu_create() function) - * @param cmp_par_exp_flags exposure flags compression parameter - * @param spillover_exp_flags exposure flags spillover threshold parameter - * @param cmp_par_fx normal flux compression parameter - * @param spillover_fx normal flux spillover threshold parameter - * @param cmp_par_ncob normal center of brightness compression parameter - * @param spillover_ncob normal center of brightness spillover threshold parameter - * @param cmp_par_efx extended flux compression parameter - * @param spillover_efx extended flux spillover threshold parameter - * @param cmp_par_ecob extended center of brightness compression parameter - * @param spillover_ecob extended center of brightness spillover threshold parameter - * @param cmp_par_fx_cob_variance flux/COB variance compression parameter - * @param spillover_fx_cob_variance flux/COB variance spillover threshold parameter - * - * @returns 0 if parameters are valid, non-zero if parameters are invalid - */ - -int cmp_cfg_fx_cob(struct cmp_cfg *cfg, - uint32_t cmp_par_exp_flags, uint32_t spillover_exp_flags, - uint32_t cmp_par_fx, uint32_t spillover_fx, - uint32_t cmp_par_ncob, uint32_t spillover_ncob, - uint32_t cmp_par_efx, uint32_t spillover_efx, - uint32_t cmp_par_ecob, uint32_t spillover_ecob, - uint32_t cmp_par_fx_cob_variance, uint32_t spillover_fx_cob_variance) -{ - if (!cfg) - return -1; - - cfg->cmp_par_exp_flags = cmp_par_exp_flags; - cfg->cmp_par_fx = cmp_par_fx; - cfg->cmp_par_ncob = cmp_par_ncob; - cfg->cmp_par_efx = cmp_par_efx; - cfg->cmp_par_ecob = cmp_par_ecob; - cfg->cmp_par_fx_cob_variance = cmp_par_fx_cob_variance; - - cfg->spill_exp_flags = spillover_exp_flags; - cfg->spill_fx = spillover_fx; - cfg->spill_ncob = spillover_ncob; - cfg->spill_efx = spillover_efx; - cfg->spill_ecob = spillover_ecob; - cfg->spill_fx_cob_variance = spillover_fx_cob_variance; - - if (cmp_cfg_fx_cob_is_invalid(cfg)) - return -1; - - return 0; -} - - -/** - * @brief set up the configuration parameters for an auxiliary science data compression - * @note auxiliary compression data types are: DATA_TYPE_OFFSET, DATA_TYPE_BACKGROUND, - DATA_TYPE_SMEARING, DATA_TYPE_F_CAM_OFFSET, DATA_TYPE_F_CAM_BACKGROUND - * @note not all parameters are needed for every auxiliary compression data type - * - * @param cfg pointer to a compression configuration (created - * with the cmp_cfg_icu_create() function) - * @param cmp_par_mean mean compression parameter - * @param spillover_mean mean spillover threshold parameter - * @param cmp_par_variance variance compression parameter - * @param spillover_variance variance spillover threshold parameter - * @param cmp_par_pixels_error outlier pixels number compression parameter - * @param spillover_pixels_error outlier pixels number spillover threshold parameter - * - * @returns 0 if parameters are valid, non-zero if parameters are invalid - */ - -int cmp_cfg_aux(struct cmp_cfg *cfg, - uint32_t cmp_par_mean, uint32_t spillover_mean, - uint32_t cmp_par_variance, uint32_t spillover_variance, - uint32_t cmp_par_pixels_error, uint32_t spillover_pixels_error) -{ - if (!cfg) - return -1; - - switch (cfg->data_type) { - case DATA_TYPE_OFFSET: - case DATA_TYPE_F_CAM_OFFSET: - cfg->cmp_par_offset_mean = cmp_par_mean; - cfg->spill_offset_mean = spillover_mean; - cfg->cmp_par_offset_variance = cmp_par_variance; - cfg->spill_offset_variance = spillover_variance; - break; - case DATA_TYPE_BACKGROUND: - case DATA_TYPE_F_CAM_BACKGROUND: - cfg->cmp_par_background_mean = cmp_par_mean; - cfg->spill_background_mean = spillover_mean; - cfg->cmp_par_background_variance = cmp_par_variance; - cfg->spill_background_variance = spillover_variance; - cfg->cmp_par_background_pixels_error = cmp_par_pixels_error; - cfg->spill_background_pixels_error = spillover_pixels_error; - break; - case DATA_TYPE_SMEARING: - cfg->cmp_par_smearing_mean = cmp_par_mean; - cfg->spill_smearing_mean = spillover_mean; - cfg->cmp_par_smearing_variance = cmp_par_variance; - cfg->spill_smearing_variance = spillover_variance; - cfg->cmp_par_smearing_pixels_error = cmp_par_pixels_error; - cfg->spill_smearing_pixels_error = spillover_pixels_error; - break; - default: - debug_print("Error: The compression data type is not an auxiliary science compression data type."); - return -1; - } - - if (cmp_cfg_aux_is_invalid(cfg)) - return -1; - - return 0; -} - - /** * @brief map a signed value into a positive value range * @@ -2206,55 +1930,6 @@ static uint32_t compress_data_internal(const struct cmp_cfg *cfg, uint32_t strea } -/** - * @brief compress data on the ICU in software - * - * @param cfg pointer to a compression configuration (created with the - * cmp_cfg_icu_create() function, setup with the cmp_cfg_xxx() functions) - * - * @note the validity of the cfg structure is checked before the compression is - * started - * - * @returns the bit length of the bitstream on success; negative on error, - * 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) - */ - -int icu_compress_data(const struct cmp_cfg *cfg) -{ - struct cmp_cfg cfg_cpy; - uint32_t dst_capacity_used = 0; - - if (cfg) { - if (cfg->samples == 0) - return 0; - cfg_cpy = *cfg; - cfg_cpy.buffer_length = cmp_cal_size_of_data(cfg->buffer_length, cfg->data_type); - if (cfg_cpy.icu_output_buf && !cfg_cpy.buffer_length) - return -1; - - if (!rdcu_supported_data_type_is_used(cfg->data_type) && !cmp_data_type_is_invalid(cfg->data_type)) { - if (cfg->icu_new_model_buf) { - if (cfg->input_buf) - memcpy(cfg->icu_new_model_buf, cfg->input_buf, COLLECTION_HDR_SIZE); - cfg_cpy.icu_new_model_buf = (uint8_t *)cfg_cpy.icu_new_model_buf + COLLECTION_HDR_SIZE; - } - if (cfg->icu_output_buf && cfg->input_buf && cfg->buffer_length) - memcpy(cfg->icu_output_buf, cfg->input_buf, COLLECTION_HDR_SIZE); - if (cfg->input_buf) - cfg_cpy.input_buf = (uint8_t *)cfg->input_buf + COLLECTION_HDR_SIZE; - if (cfg->model_buf) - cfg_cpy.model_buf = (uint8_t *)cfg->model_buf + COLLECTION_HDR_SIZE; - dst_capacity_used = COLLECTION_HDR_SIZE*8; - } - return (int)compress_data_internal(&cfg_cpy, dst_capacity_used); - } - return (int)compress_data_internal(NULL, dst_capacity_used); -} - - /** * @brief estimate a "good" spillover threshold parameter * diff --git a/test/cmp_decmp/test_cmp_decmp.c b/test/cmp_decmp/test_cmp_decmp.c index 6520556..be5da6e 100644 --- a/test/cmp_decmp/test_cmp_decmp.c +++ b/test/cmp_decmp/test_cmp_decmp.c @@ -561,32 +561,17 @@ static uint32_t generate_random_chunk(void *chunk, struct chunk_def col_array[], /** * @brief generate random compression configuration * - * @param cfg pointer to a compression configuration + * @param rcfg pointer to a RDCU compression configuration */ -void generate_random_cmp_cfg(struct cmp_cfg *cfg) +void generate_random_rdcu_cfg(struct rdcu_cfg *rcfg) { - if (cmp_imagette_data_type_is_used(cfg->data_type)) { - cfg->cmp_par_imagette = cmp_rand_between(MIN_IMA_GOLOMB_PAR, MAX_IMA_GOLOMB_PAR); - cfg->ap1_golomb_par = cmp_rand_between(MIN_IMA_GOLOMB_PAR, MAX_IMA_GOLOMB_PAR); - cfg->ap2_golomb_par = cmp_rand_between(MIN_IMA_GOLOMB_PAR, MAX_IMA_GOLOMB_PAR); - cfg->spill_imagette = cmp_rand_between(MIN_IMA_SPILL, cmp_ima_max_spill(cfg->golomb_par)); - cfg->ap1_spill = cmp_rand_between(MIN_IMA_SPILL, cmp_ima_max_spill(cfg->ap1_golomb_par)); - cfg->ap2_spill = cmp_rand_between(MIN_IMA_SPILL, cmp_ima_max_spill(cfg->ap2_golomb_par)); - } else { - cfg->cmp_par_1 = cmp_rand_between(MIN_NON_IMA_GOLOMB_PAR, MAX_NON_IMA_GOLOMB_PAR); - cfg->cmp_par_2 = cmp_rand_between(MIN_NON_IMA_GOLOMB_PAR, MAX_NON_IMA_GOLOMB_PAR); - cfg->cmp_par_3 = cmp_rand_between(MIN_NON_IMA_GOLOMB_PAR, MAX_NON_IMA_GOLOMB_PAR); - cfg->cmp_par_4 = cmp_rand_between(MIN_NON_IMA_GOLOMB_PAR, MAX_NON_IMA_GOLOMB_PAR); - cfg->cmp_par_5 = cmp_rand_between(MIN_NON_IMA_GOLOMB_PAR, MAX_NON_IMA_GOLOMB_PAR); - cfg->cmp_par_6 = cmp_rand_between(MIN_NON_IMA_GOLOMB_PAR, MAX_NON_IMA_GOLOMB_PAR); - cfg->spill_par_1 = cmp_rand_between(MIN_NON_IMA_SPILL, cmp_icu_max_spill(cfg->cmp_par_exp_flags)); - cfg->spill_par_2 = cmp_rand_between(MIN_NON_IMA_SPILL, cmp_icu_max_spill(cfg->cmp_par_fx)); - cfg->spill_par_3 = cmp_rand_between(MIN_NON_IMA_SPILL, cmp_icu_max_spill(cfg->cmp_par_ncob)); - cfg->spill_par_4 = cmp_rand_between(MIN_NON_IMA_SPILL, cmp_icu_max_spill(cfg->cmp_par_efx)); - cfg->spill_par_5 = cmp_rand_between(MIN_NON_IMA_SPILL, cmp_icu_max_spill(cfg->cmp_par_ecob)); - cfg->spill_par_6 = cmp_rand_between(MIN_NON_IMA_SPILL, cmp_icu_max_spill(cfg->cmp_par_fx_cob_variance)); - } + rcfg->golomb_par = cmp_rand_between(MIN_IMA_GOLOMB_PAR, MAX_IMA_GOLOMB_PAR); + rcfg->ap1_golomb_par = cmp_rand_between(MIN_IMA_GOLOMB_PAR, MAX_IMA_GOLOMB_PAR); + rcfg->ap2_golomb_par = cmp_rand_between(MIN_IMA_GOLOMB_PAR, MAX_IMA_GOLOMB_PAR); + rcfg->spill = cmp_rand_between(MIN_IMA_SPILL, cmp_ima_max_spill(rcfg->golomb_par)); + rcfg->ap1_spill = cmp_rand_between(MIN_IMA_SPILL, cmp_ima_max_spill(rcfg->ap1_golomb_par)); + rcfg->ap2_spill = cmp_rand_between(MIN_IMA_SPILL, cmp_ima_max_spill(rcfg->ap2_golomb_par)); } @@ -644,10 +629,10 @@ void generate_random_cmp_par(struct cmp_par *par) * @brief compress the given configuration and decompress it afterwards; finally * compare the results * - * @param cfg pointer to a compression configuration + * @param rcfg pointer to a RDCU compression configuration */ -void compression_decompression(struct cmp_cfg *cfg) +void compression_decompression_like_rdcu(struct rdcu_cfg *rcfg) { int cmp_size_bits, s, error; uint32_t data_size, cmp_data_size, cmp_ent_size; @@ -655,61 +640,51 @@ void compression_decompression(struct cmp_cfg *cfg) void *decompressed_data; static void *model_of_data; void *updated_model = NULL; + struct cmp_info info; - if (!cfg) { + if (!rcfg) { free(model_of_data); return; } - TEST_ASSERT_NOT_NULL(cfg); + TEST_ASSERT_NOT_NULL(rcfg); - TEST_ASSERT_NULL(cfg->icu_output_buf); + TEST_ASSERT_NULL(rcfg->icu_output_buf); - data_size = cmp_cal_size_of_data(cfg->samples, cfg->data_type); + data_size = rcfg->samples * sizeof(uint16_t); + TEST_ASSERT_NOT_EQUAL_UINT(0, data_size); /* create a compression entity */ - cmp_data_size = cmp_cal_size_of_data(cfg->buffer_length, cfg->data_type); - /* cmp_data_size &= ~0x3U; /1* the size of the compressed data should be a multiple of 4 *1/ */ - TEST_ASSERT_NOT_EQUAL_INT(0, cmp_data_size); + cmp_data_size = rcfg->buffer_length * sizeof(uint16_t); + TEST_ASSERT_NOT_EQUAL_UINT(0, cmp_data_size); - cmp_ent_size = cmp_ent_create(NULL, cfg->data_type, cfg->cmp_mode == CMP_MODE_RAW, cmp_data_size); + cmp_ent_size = cmp_ent_create(NULL, DATA_TYPE_IMAGETTE, rcfg->cmp_mode == CMP_MODE_RAW, cmp_data_size); TEST_ASSERT_NOT_EQUAL_UINT(0, cmp_ent_size); ent = malloc(cmp_ent_size); TEST_ASSERT_TRUE(ent); - cmp_ent_size = cmp_ent_create(ent, cfg->data_type, cfg->cmp_mode == CMP_MODE_RAW, cmp_data_size); + cmp_ent_size = cmp_ent_create(ent, DATA_TYPE_IMAGETTE, rcfg->cmp_mode == CMP_MODE_RAW, cmp_data_size); TEST_ASSERT_NOT_EQUAL_UINT(0, cmp_ent_size); /* we put the compressed data direct into the compression entity */ - cfg->icu_output_buf = cmp_ent_get_data_buf(ent); - TEST_ASSERT_NOT_NULL(cfg->icu_output_buf); + rcfg->icu_output_buf = cmp_ent_get_data_buf(ent); + TEST_ASSERT_NOT_NULL(rcfg->icu_output_buf); /* now compress the data */ - cmp_size_bits = icu_compress_data(cfg); - + cmp_size_bits = compress_like_rdcu(rcfg, &info); TEST_ASSERT(cmp_size_bits > 0); /* put the compression parameters in the entity header */ - { - /* mock values */ - uint32_t version_id = ~0U; - uint64_t start_time = 32; - uint64_t end_time = 42; - uint16_t model_id = 0xCAFE; - uint8_t model_counter = 0; - uint32_t ent_size; - - ent_size = cmp_ent_build(ent, version_id, start_time, end_time, - model_id, model_counter, cfg, cmp_size_bits); - TEST_ASSERT_NOT_EQUAL_UINT(0, ent_size); - error = cmp_ent_set_size(ent, ent_size); - TEST_ASSERT_FALSE(error); - } + cmp_ent_size = cmp_ent_create(ent, DATA_TYPE_IMAGETTE, rcfg->cmp_mode == CMP_MODE_RAW, + cmp_bit_to_byte((unsigned int)cmp_size_bits)); + TEST_ASSERT_NOT_EQUAL_UINT(0, cmp_ent_size); + error = cmp_ent_write_rdcu_cmp_pars(ent, &info, rcfg); + TEST_ASSERT_FALSE(error); /* allocate the buffers for decompression */ TEST_ASSERT_NOT_EQUAL_INT(0, data_size); s = decompress_cmp_entiy(ent, model_of_data, NULL, NULL); decompressed_data = malloc((size_t)s); TEST_ASSERT_NOT_NULL(decompressed_data); - if (model_mode_is_used(cfg->cmp_mode)) { + if (model_mode_is_used(rcfg->cmp_mode)) { updated_model = malloc(data_size); TEST_ASSERT_NOT_NULL(updated_model); } @@ -717,12 +692,12 @@ void compression_decompression(struct cmp_cfg *cfg) /* now we try to decompress the data */ s = decompress_cmp_entiy(ent, model_of_data, updated_model, decompressed_data); TEST_ASSERT_EQUAL_INT(data_size, s); - TEST_ASSERT_FALSE(memcmp(decompressed_data, cfg->input_buf, data_size)); + TEST_ASSERT_FALSE(memcmp(decompressed_data, rcfg->input_buf, data_size)); - if (model_mode_is_used(cfg->cmp_mode)) { + if (model_mode_is_used(rcfg->cmp_mode)) { TEST_ASSERT_NOT_NULL(updated_model); TEST_ASSERT_NOT_NULL(model_of_data); - TEST_ASSERT_FALSE(memcmp(updated_model, cfg->icu_new_model_buf, data_size)); + TEST_ASSERT_FALSE(memcmp(updated_model, rcfg->icu_new_model_buf, data_size)); memcpy(model_of_data, updated_model, data_size); } else { /* non-model mode */ /* reset model */ @@ -731,7 +706,7 @@ void compression_decompression(struct cmp_cfg *cfg) memcpy(model_of_data, decompressed_data, data_size); } - cfg->icu_output_buf = NULL; + rcfg->icu_output_buf = NULL; free(ent); free(decompressed_data); free(updated_model); @@ -753,8 +728,7 @@ void test_random_round_trip_like_rdcu_compression(void) { enum cmp_data_type data_type; enum cmp_mode cmp_mode; - struct cmp_cfg cfg; - uint32_t cmp_buffer_size; + struct rdcu_cfg rcfg; enum { MAX_DATA_TO_COMPRESS_SIZE = 0x1000B, CMP_BUFFER_FAKTOR = 3 /* compression data buffer size / data to compress buffer size */ @@ -782,25 +756,32 @@ void test_random_round_trip_like_rdcu_compression(void) /* for (cmp_mode = CMP_MODE_RAW; cmp_mode <= CMP_MODE_STUFF; cmp_mode++) { */ for (cmp_mode = CMP_MODE_RAW; cmp_mode <= CMP_MODE_DIFF_MULTI; cmp_mode++) { /* printf("cmp_mode: %i\n", cmp_mode); */ - cfg = cmp_cfg_icu_create(data_type, cmp_mode, model_value, - CMP_LOSSLESS); - TEST_ASSERT_NOT_EQUAL_INT(cfg.data_type, DATA_TYPE_UNKNOWN); - - generate_random_cmp_cfg(&cfg); - - if (!model_mode_is_used(cmp_mode)) - cmp_buffer_size = cmp_cfg_icu_buffers(&cfg, data_to_compress1, - samples, NULL, NULL, NULL, samples*CMP_BUFFER_FAKTOR); - else - cmp_buffer_size = cmp_cfg_icu_buffers(&cfg, data_to_compress2, - samples, data_to_compress1, updated_model, NULL, samples*CMP_BUFFER_FAKTOR); - - TEST_ASSERT_EQUAL_UINT(cmp_buffer_size, cmp_cal_size_of_data(CMP_BUFFER_FAKTOR*samples, data_type)); - - compression_decompression(&cfg); + int error = rdcu_cfg_create(&rcfg, cmp_mode, + model_value, CMP_LOSSLESS); + TEST_ASSERT_FALSE(error); + + generate_random_rdcu_cfg(&rcfg); + + if (!model_mode_is_used(cmp_mode)) { + rcfg.input_buf = data_to_compress1; + rcfg.samples = samples; + rcfg.model_buf = NULL; + rcfg.icu_new_model_buf = NULL; + rcfg.icu_output_buf = NULL; + rcfg.buffer_length = samples*CMP_BUFFER_FAKTOR; + } else { + rcfg.input_buf = data_to_compress2; + rcfg.samples = samples; + rcfg.model_buf = data_to_compress1; + rcfg.icu_new_model_buf = updated_model; + rcfg.icu_output_buf = NULL; + rcfg.buffer_length = samples*CMP_BUFFER_FAKTOR; + } + + compression_decompression_like_rdcu(&rcfg); } } - compression_decompression(NULL); + compression_decompression_like_rdcu(NULL); free(data_to_compress1); free(data_to_compress2); free(updated_model); diff --git a/test/cmp_icu/test_cmp_icu.c b/test/cmp_icu/test_cmp_icu.c index d0f8fbb..4f8c15f 100644 --- a/test/cmp_icu/test_cmp_icu.c +++ b/test/cmp_icu/test_cmp_icu.c @@ -66,1206 +66,6 @@ void setUp(void) } -/** - * @test cmp_cfg_icu_create - */ - -void test_cmp_cfg_icu_create(void) -{ - struct cmp_cfg cfg; - enum cmp_data_type data_type; - enum cmp_mode cmp_mode; - uint32_t model_value, lossy_par; - const enum cmp_data_type biggest_data_type = DATA_TYPE_F_CAM_BACKGROUND; - - /* wrong data type tests */ - data_type = DATA_TYPE_UNKNOWN; /* not valid data type */ - cmp_mode = CMP_MODE_RAW; - model_value = 0; - lossy_par = CMP_LOSSLESS; - cfg = cmp_cfg_icu_create(data_type, cmp_mode, model_value, lossy_par); - TEST_ASSERT_EQUAL_INT(DATA_TYPE_UNKNOWN, cfg.data_type); - memset(&cfg, 0, sizeof(cfg)); - - data_type = biggest_data_type + 1; /* not valid data type */ - cfg = cmp_cfg_icu_create(data_type, cmp_mode, model_value, lossy_par); - TEST_ASSERT_EQUAL_INT(DATA_TYPE_UNKNOWN, cfg.data_type); - memset(&cfg, 0, sizeof(cfg)); - - data_type = biggest_data_type; - cfg = cmp_cfg_icu_create(data_type, cmp_mode, model_value, lossy_par); - TEST_ASSERT_EQUAL_INT(biggest_data_type, cfg.data_type); - TEST_ASSERT_EQUAL_INT(CMP_MODE_RAW, cfg.cmp_mode); - TEST_ASSERT_EQUAL_INT(0, cfg.model_value); - TEST_ASSERT_EQUAL_INT(0, cfg.round); - TEST_ASSERT_EQUAL(&MAX_USED_BITS_SAFE, cfg.max_used_bits); - memset(&cfg, 0, sizeof(cfg)); - - /* this should work */ - data_type = DATA_TYPE_IMAGETTE; - cfg = cmp_cfg_icu_create(data_type, cmp_mode, model_value, lossy_par); - TEST_ASSERT_EQUAL_INT(DATA_TYPE_IMAGETTE, cfg.data_type); - TEST_ASSERT_EQUAL_INT(CMP_MODE_RAW, cfg.cmp_mode); - TEST_ASSERT_EQUAL_INT(0, cfg.model_value); - TEST_ASSERT_EQUAL_INT(0, cfg.round); - TEST_ASSERT_EQUAL(&MAX_USED_BITS_SAFE, cfg.max_used_bits); - memset(&cfg, 0, sizeof(cfg)); - - /* wrong compression mode tests */ - cmp_mode = (enum cmp_mode)(MAX_CMP_MODE + 1); - cfg = cmp_cfg_icu_create(data_type, cmp_mode, model_value, lossy_par); - TEST_ASSERT_EQUAL_INT(DATA_TYPE_UNKNOWN, cfg.data_type); - memset(&cfg, 0, sizeof(cfg)); - - cmp_mode = (enum cmp_mode)-1; - cfg = cmp_cfg_icu_create(data_type, cmp_mode, model_value, lossy_par); - TEST_ASSERT_EQUAL_INT(DATA_TYPE_UNKNOWN, cfg.data_type); - memset(&cfg, 0, sizeof(cfg)); - - /* this should work */ - cmp_mode = MAX_CMP_MODE; - cfg = cmp_cfg_icu_create(data_type, cmp_mode, model_value, lossy_par); - TEST_ASSERT_EQUAL_INT(DATA_TYPE_IMAGETTE, cfg.data_type); - TEST_ASSERT_EQUAL_INT(MAX_CMP_MODE, cfg.cmp_mode); - TEST_ASSERT_EQUAL_INT(0, cfg.model_value); - TEST_ASSERT_EQUAL_INT(0, cfg.round); - TEST_ASSERT_EQUAL(&MAX_USED_BITS_SAFE, cfg.max_used_bits); - memset(&cfg, 0, sizeof(cfg)); - - /* wrong model_value tests */ - cmp_mode = CMP_MODE_MODEL_MULTI; /* model value checks only active on model mode */ - model_value = MAX_MODEL_VALUE + 1; - cfg = cmp_cfg_icu_create(data_type, cmp_mode, model_value, lossy_par); - TEST_ASSERT_EQUAL_INT(DATA_TYPE_UNKNOWN, cfg.data_type); - - model_value = -1U; - cfg = cmp_cfg_icu_create(data_type, cmp_mode, model_value, lossy_par); - TEST_ASSERT_EQUAL_INT(DATA_TYPE_UNKNOWN, cfg.data_type); - - /* this should work */ - model_value = MAX_MODEL_VALUE; - cfg = cmp_cfg_icu_create(data_type, cmp_mode, model_value, lossy_par); - TEST_ASSERT_EQUAL_INT(DATA_TYPE_IMAGETTE, cfg.data_type); - TEST_ASSERT_EQUAL_INT(CMP_MODE_MODEL_MULTI, cfg.cmp_mode); - TEST_ASSERT_EQUAL_INT(16, cfg.model_value); - TEST_ASSERT_EQUAL_INT(0, cfg.round); - TEST_ASSERT_EQUAL(&MAX_USED_BITS_SAFE, cfg.max_used_bits); - - /* no checks for model mode -> no model cmp_mode */ - cmp_mode = CMP_MODE_RAW; - model_value = MAX_MODEL_VALUE + 1; - cfg = cmp_cfg_icu_create(data_type, cmp_mode, model_value, lossy_par); - TEST_ASSERT_EQUAL_INT(DATA_TYPE_IMAGETTE, cfg.data_type); - TEST_ASSERT_EQUAL_INT(CMP_MODE_RAW, cfg.cmp_mode); - TEST_ASSERT_EQUAL_INT(MAX_MODEL_VALUE + 1, cfg.model_value); - TEST_ASSERT_EQUAL_INT(0, cfg.round); - TEST_ASSERT_EQUAL(&MAX_USED_BITS_SAFE, cfg.max_used_bits); - model_value = MAX_MODEL_VALUE; - - /* wrong lossy_par tests */ - lossy_par = MAX_ICU_ROUND + 1; - cfg = cmp_cfg_icu_create(data_type, cmp_mode, model_value, lossy_par); - TEST_ASSERT_EQUAL_INT(DATA_TYPE_UNKNOWN, cfg.data_type); - - lossy_par = -1U; - cfg = cmp_cfg_icu_create(data_type, cmp_mode, model_value, lossy_par); - TEST_ASSERT_EQUAL_INT(DATA_TYPE_UNKNOWN, cfg.data_type); - - /* this should work */ - lossy_par = MAX_ICU_ROUND; - cfg = cmp_cfg_icu_create(data_type, cmp_mode, model_value, lossy_par); - TEST_ASSERT_EQUAL_INT(DATA_TYPE_IMAGETTE, cfg.data_type); - TEST_ASSERT_EQUAL_INT(CMP_MODE_RAW, cfg.cmp_mode); - TEST_ASSERT_EQUAL_INT(16, cfg.model_value); - TEST_ASSERT_EQUAL_INT(3, cfg.round); - TEST_ASSERT_EQUAL(&MAX_USED_BITS_SAFE, cfg.max_used_bits); - - /* random test */ - data_type = cmp_rand_between(DATA_TYPE_IMAGETTE, biggest_data_type); - cmp_mode = cmp_rand_between(CMP_MODE_RAW, MAX_CMP_MODE); - model_value = cmp_rand_between(0, MAX_MODEL_VALUE); - lossy_par = cmp_rand_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); - TEST_ASSERT_EQUAL_INT(model_value, cfg.model_value); - TEST_ASSERT_EQUAL_INT(lossy_par, cfg.round); - TEST_ASSERT_EQUAL(&MAX_USED_BITS_SAFE, cfg.max_used_bits); -} - - -/** - * @test cmp_cfg_icu_buffers - */ - -void test_cmp_cfg_icu_buffers(void) -{ - struct cmp_cfg cfg; - void *data_to_compress; - uint32_t data_samples; - void *model_of_data; - void *updated_model; - uint32_t *compressed_data; - uint32_t compressed_data_len_samples; - size_t s; - uint16_t ima_data[4] = {42, 23, 0, 0xFFFF}; - uint16_t ima_model[4] = {0xC, 0xA, 0xFF, 0xE}; - uint16_t ima_up_model[4] = {0}; - uint32_t cmp_data[2] = {0}; - - /* error case: unknown data_type */ - cfg = cmp_cfg_icu_create(DATA_TYPE_UNKNOWN, CMP_MODE_DIFF_ZERO, 16, CMP_LOSSLESS); - data_to_compress = ima_data; - data_samples = 4; - model_of_data = NULL; - updated_model = NULL; - compressed_data = cmp_data; - compressed_data_len_samples = 4; - s = cmp_cfg_icu_buffers(&cfg, data_to_compress, data_samples, - model_of_data, updated_model, compressed_data, - compressed_data_len_samples); - TEST_ASSERT_EQUAL_size_t(0, s); - - /* error case: no data test */ - cfg = cmp_cfg_icu_create(DATA_TYPE_IMAGETTE, CMP_MODE_DIFF_ZERO, 16, CMP_LOSSLESS); - data_to_compress = NULL; /* no data set */ - data_samples = 4; - model_of_data = NULL; - updated_model = NULL; - compressed_data = cmp_data; - compressed_data_len_samples = 4; - s = cmp_cfg_icu_buffers(&cfg, data_to_compress, data_samples, - model_of_data, updated_model, compressed_data, - compressed_data_len_samples); - TEST_ASSERT_EQUAL_size_t(0, s); - - /* now its should work */ - cfg = cmp_cfg_icu_create(DATA_TYPE_IMAGETTE, CMP_MODE_DIFF_ZERO, 16, CMP_LOSSLESS); - data_to_compress = ima_data; - s = cmp_cfg_icu_buffers(&cfg, data_to_compress, data_samples, - model_of_data, updated_model, compressed_data, - compressed_data_len_samples); - TEST_ASSERT_EQUAL_size_t(8, s); - TEST_ASSERT_EQUAL(ima_data, cfg.input_buf); - TEST_ASSERT_EQUAL_INT(NULL, cfg.model_buf); - TEST_ASSERT_EQUAL_INT(4, cfg.samples); - TEST_ASSERT_EQUAL(NULL, cfg.icu_new_model_buf); - TEST_ASSERT_EQUAL(cmp_data, cfg.icu_output_buf); - TEST_ASSERT_EQUAL_INT(4, cfg.buffer_length); - - /* error case: model mode and no model */ - cfg = cmp_cfg_icu_create(DATA_TYPE_IMAGETTE, CMP_MODE_MODEL_ZERO, 16, CMP_LOSSLESS); - model_of_data = NULL; - s = cmp_cfg_icu_buffers(&cfg, data_to_compress, data_samples, - model_of_data, updated_model, compressed_data, - compressed_data_len_samples); - TEST_ASSERT_EQUAL_size_t(0, s); - - /* now its should work */ - cfg = cmp_cfg_icu_create(DATA_TYPE_IMAGETTE, CMP_MODE_MODEL_ZERO, 16, CMP_LOSSLESS); - model_of_data = ima_model; - updated_model = ima_model; - s = cmp_cfg_icu_buffers(&cfg, data_to_compress, data_samples, - model_of_data, updated_model, compressed_data, - compressed_data_len_samples); - TEST_ASSERT_EQUAL_size_t(8, s); - TEST_ASSERT_EQUAL(ima_data, cfg.input_buf); - TEST_ASSERT_EQUAL_INT(ima_model, cfg.model_buf); - TEST_ASSERT_EQUAL_INT(4, cfg.samples); - TEST_ASSERT_EQUAL(ima_model, cfg.icu_new_model_buf); - TEST_ASSERT_EQUAL(cmp_data, cfg.icu_output_buf); - TEST_ASSERT_EQUAL_INT(4, cfg.buffer_length); - - /* error case: data == model */ - cfg = cmp_cfg_icu_create(DATA_TYPE_IMAGETTE, CMP_MODE_MODEL_ZERO, 16, CMP_LOSSLESS); - data_to_compress = ima_data; - model_of_data = ima_data; - s = cmp_cfg_icu_buffers(&cfg, data_to_compress, data_samples, - model_of_data, updated_model, compressed_data, - compressed_data_len_samples); - TEST_ASSERT_EQUAL_size_t(0, s); - - /* error case: data == compressed_data */ - cfg = cmp_cfg_icu_create(DATA_TYPE_IMAGETTE, CMP_MODE_MODEL_ZERO, 16, CMP_LOSSLESS); - data_to_compress = ima_data; - model_of_data = ima_model; - compressed_data = (void *)ima_data; - s = cmp_cfg_icu_buffers(&cfg, data_to_compress, data_samples, - model_of_data, updated_model, compressed_data, - compressed_data_len_samples); - TEST_ASSERT_EQUAL_size_t(0, s); - - /* error case: data == updated_model */ - cfg = cmp_cfg_icu_create(DATA_TYPE_IMAGETTE, CMP_MODE_MODEL_ZERO, 16, CMP_LOSSLESS); - data_to_compress = ima_data; - model_of_data = ima_model; - updated_model = ima_data; - compressed_data = (void *)ima_data; - s = cmp_cfg_icu_buffers(&cfg, data_to_compress, data_samples, - model_of_data, updated_model, compressed_data, - compressed_data_len_samples); - TEST_ASSERT_EQUAL_size_t(0, s); - - /* error case: model == compressed_data */ - cfg = cmp_cfg_icu_create(DATA_TYPE_IMAGETTE, CMP_MODE_MODEL_ZERO, 16, CMP_LOSSLESS); - data_to_compress = ima_data; - model_of_data = ima_model; - compressed_data = (void *)ima_model; - s = cmp_cfg_icu_buffers(&cfg, data_to_compress, data_samples, - model_of_data, updated_model, compressed_data, - compressed_data_len_samples); - TEST_ASSERT_EQUAL_size_t(0, s); - - /* error case: updated_model == compressed_data */ - cfg = cmp_cfg_icu_create(DATA_TYPE_IMAGETTE, CMP_MODE_MODEL_ZERO, 16, CMP_LOSSLESS); - data_to_compress = ima_data; - model_of_data = ima_model; - updated_model = ima_up_model; - compressed_data = (void *)ima_up_model; - s = cmp_cfg_icu_buffers(&cfg, data_to_compress, data_samples, - model_of_data, updated_model, compressed_data, - compressed_data_len_samples); - TEST_ASSERT_EQUAL_size_t(0, s); - - /* warning case: samples = 0 */ - cfg = cmp_cfg_icu_create(DATA_TYPE_IMAGETTE, CMP_MODE_MODEL_ZERO, 16, CMP_LOSSLESS); - data_to_compress = ima_data; - data_samples = 0; - model_of_data = ima_model; - updated_model = ima_up_model; - compressed_data = cmp_data; - compressed_data_len_samples = 4; - s = cmp_cfg_icu_buffers(&cfg, data_to_compress, data_samples, - model_of_data, updated_model, compressed_data, - compressed_data_len_samples); - TEST_ASSERT_EQUAL_size_t(8, s); - TEST_ASSERT_EQUAL(ima_data, cfg.input_buf); - TEST_ASSERT_EQUAL_INT(ima_model, cfg.model_buf); - TEST_ASSERT_EQUAL_INT(0, cfg.samples); - TEST_ASSERT_EQUAL(ima_up_model, cfg.icu_new_model_buf); - TEST_ASSERT_EQUAL(cmp_data, cfg.icu_output_buf); - TEST_ASSERT_EQUAL_INT(4, cfg.buffer_length); - memset(&cfg, 0, sizeof(cfg)); - - /* error case: compressed_data_len_samples = 0 */ - cfg = cmp_cfg_icu_create(DATA_TYPE_IMAGETTE, CMP_MODE_MODEL_ZERO, 16, CMP_LOSSLESS); - data_samples = 4; - compressed_data_len_samples = 0; - s = cmp_cfg_icu_buffers(&cfg, data_to_compress, data_samples, - model_of_data, updated_model, compressed_data, - compressed_data_len_samples); - TEST_ASSERT_EQUAL_size_t(0, s); - - /* this should now work */ - /* if data_samples = 0 -> compressed_data_len_samples = 0 is allowed */ - cfg = cmp_cfg_icu_create(DATA_TYPE_IMAGETTE, CMP_MODE_MODEL_ZERO, 16, CMP_LOSSLESS); - data_samples = 0; - compressed_data_len_samples = 0; - s = cmp_cfg_icu_buffers(&cfg, data_to_compress, data_samples, - model_of_data, updated_model, compressed_data, - compressed_data_len_samples); - TEST_ASSERT_EQUAL_size_t(0, s); /* not an error, it is the size of the compressed data */ - TEST_ASSERT_EQUAL(ima_data, cfg.input_buf); - TEST_ASSERT_EQUAL_INT(ima_model, cfg.model_buf); - TEST_ASSERT_EQUAL_INT(0, cfg.samples); - TEST_ASSERT_EQUAL(ima_up_model, cfg.icu_new_model_buf); - TEST_ASSERT_EQUAL(cmp_data, cfg.icu_output_buf); - TEST_ASSERT_EQUAL_INT(0, cfg.buffer_length); - - /* this should now work */ - /* if compressed_data = NULL -> compressed_data_len_samples = 0 is allowed */ - cfg = cmp_cfg_icu_create(DATA_TYPE_IMAGETTE, CMP_MODE_MODEL_ZERO, 16, CMP_LOSSLESS); - data_samples = 4; - compressed_data = NULL; - compressed_data_len_samples = 0; - s = cmp_cfg_icu_buffers(&cfg, data_to_compress, data_samples, - model_of_data, updated_model, compressed_data, - compressed_data_len_samples); - TEST_ASSERT_EQUAL_size_t(0, s); /* not an error, it is the size of the compressed data */ - TEST_ASSERT_EQUAL(ima_data, cfg.input_buf); - TEST_ASSERT_EQUAL_INT(ima_model, cfg.model_buf); - TEST_ASSERT_EQUAL_INT(4, cfg.samples); - TEST_ASSERT_EQUAL(ima_up_model, cfg.icu_new_model_buf); - TEST_ASSERT_EQUAL(NULL, cfg.icu_output_buf); - TEST_ASSERT_EQUAL_INT(0, cfg.buffer_length); - - /* error case: RAW mode compressed_data smaller than data_samples */ - compressed_data = cmp_data; - compressed_data_len_samples = 3; - cfg = cmp_cfg_icu_create(DATA_TYPE_IMAGETTE, CMP_MODE_RAW, 16, CMP_LOSSLESS); - s = cmp_cfg_icu_buffers(&cfg, data_to_compress, data_samples, - model_of_data, updated_model, compressed_data, - compressed_data_len_samples); - TEST_ASSERT_EQUAL_size_t(0, s); - - /* this should now work */ - compressed_data = NULL; - cfg = cmp_cfg_icu_create(DATA_TYPE_IMAGETTE, CMP_MODE_RAW, 16, CMP_LOSSLESS); - s = cmp_cfg_icu_buffers(&cfg, data_to_compress, data_samples, - model_of_data, updated_model, compressed_data, - compressed_data_len_samples); - TEST_ASSERT_EQUAL_size_t(6, s); - TEST_ASSERT_EQUAL(ima_data, cfg.input_buf); - TEST_ASSERT_EQUAL_INT(ima_model, cfg.model_buf); - TEST_ASSERT_EQUAL_INT(4, cfg.samples); - TEST_ASSERT_EQUAL(ima_up_model, cfg.icu_new_model_buf); - TEST_ASSERT_EQUAL(NULL, cfg.icu_output_buf); - TEST_ASSERT_EQUAL_INT(3, cfg.buffer_length); - - /* this should also now work */ - compressed_data = cmp_data; - compressed_data_len_samples = 4; - cfg = cmp_cfg_icu_create(DATA_TYPE_IMAGETTE, CMP_MODE_RAW, 16, CMP_LOSSLESS); - s = cmp_cfg_icu_buffers(&cfg, data_to_compress, data_samples, - model_of_data, updated_model, compressed_data, - compressed_data_len_samples); - TEST_ASSERT_EQUAL_size_t(8, s); - TEST_ASSERT_EQUAL(ima_data, cfg.input_buf); - TEST_ASSERT_EQUAL_INT(ima_model, cfg.model_buf); - TEST_ASSERT_EQUAL_INT(4, cfg.samples); - TEST_ASSERT_EQUAL(ima_up_model, cfg.icu_new_model_buf); - TEST_ASSERT_EQUAL(cmp_data, cfg.icu_output_buf); - TEST_ASSERT_EQUAL_INT(4, cfg.buffer_length); - - /* error case: compressed data buffer bigger than max compression entity - * data size */ - cfg = cmp_cfg_icu_create(DATA_TYPE_IMAGETTE, CMP_MODE_DIFF_ZERO, 16, CMP_LOSSLESS); - s = cmp_cfg_icu_buffers(&cfg, data_to_compress, data_samples, - model_of_data, updated_model, compressed_data, - 0x7FFFED+1); - TEST_ASSERT_EQUAL_size_t(0, s); - - cfg = cmp_cfg_icu_create(DATA_TYPE_IMAGETTE, CMP_MODE_DIFF_ZERO, 16, CMP_LOSSLESS); - s = cmp_cfg_icu_buffers(&cfg, data_to_compress, data_samples, - model_of_data, updated_model, compressed_data, - 0x7FFFFFFF); - TEST_ASSERT_EQUAL_size_t(0, s); - - /* this should also now work */ - cfg = cmp_cfg_icu_create(DATA_TYPE_IMAGETTE, CMP_MODE_DIFF_ZERO, 16, CMP_LOSSLESS); - s = cmp_cfg_icu_buffers(&cfg, data_to_compress, data_samples, - model_of_data, updated_model, compressed_data, - 0x7FFFED); - TEST_ASSERT_EQUAL_size_t(0xFFFFDA, s); - - /* error case: cfg = NULL */ - s = cmp_cfg_icu_buffers(NULL, data_to_compress, data_samples, - model_of_data, updated_model, compressed_data, - compressed_data_len_samples); - TEST_ASSERT_EQUAL_size_t(0, s); -} - - -/** - * @test cmp_cfg_icu_max_used_bits - */ - -void test_cmp_cfg_icu_max_used_bits(void) -{ - int error; - struct cmp_cfg cfg = cmp_cfg_icu_create(DATA_TYPE_IMAGETTE, CMP_MODE_MODEL_ZERO, 0, CMP_LOSSLESS); - struct cmp_max_used_bits max_used_bits = MAX_USED_BITS_SAFE; - - error = cmp_cfg_icu_max_used_bits(&cfg, &max_used_bits); - TEST_ASSERT_FALSE(error); - TEST_ASSERT_EQUAL(&max_used_bits, cfg.max_used_bits); - - /* error cases */ - max_used_bits.s_fx = 33; /* this value is to big */ - error = cmp_cfg_icu_max_used_bits(&cfg, &max_used_bits); - TEST_ASSERT_TRUE(error); - max_used_bits.s_fx = 1; - - error = cmp_cfg_icu_max_used_bits(NULL, &max_used_bits); - TEST_ASSERT_TRUE(error); - - error = cmp_cfg_icu_max_used_bits(&cfg, NULL); - TEST_ASSERT_TRUE(error); -} - - -/** - * @test cmp_cfg_icu_imagette - */ - -void test_cmp_cfg_icu_imagette(void) -{ - struct cmp_cfg cfg = {0}; - uint32_t cmp_par; - uint32_t spillover_par; - enum cmp_data_type data_type; - - int error; - - /* lowest values 1d/model mode */ - cfg = cmp_cfg_icu_create(DATA_TYPE_IMAGETTE, CMP_MODE_MODEL_ZERO, 0, CMP_LOSSLESS); - cmp_par = MIN_IMA_GOLOMB_PAR; - spillover_par = MIN_IMA_SPILL; - error = cmp_cfg_icu_imagette(&cfg, cmp_par, spillover_par); - TEST_ASSERT_FALSE(error); - TEST_ASSERT_EQUAL_INT(cfg.golomb_par, 1); - TEST_ASSERT_EQUAL_INT(cfg.spill, 2); - - /* highest values 1d/model mode */ - cfg = cmp_cfg_icu_create(DATA_TYPE_F_CAM_IMAGETTE, CMP_MODE_DIFF_MULTI, 16, CMP_LOSSLESS); - cmp_par = MAX_IMA_GOLOMB_PAR; - spillover_par = cmp_ima_max_spill(cmp_par); - error = cmp_cfg_icu_imagette(&cfg, cmp_par, spillover_par); - TEST_ASSERT_FALSE(error); - TEST_ASSERT_EQUAL_INT(cfg.golomb_par, MAX_IMA_GOLOMB_PAR); - TEST_ASSERT_EQUAL_INT(cfg.spill, cmp_ima_max_spill(MAX_IMA_GOLOMB_PAR)); - - /* wrong data type test */ - for (data_type = 0; data_type <= DATA_TYPE_F_CAM_BACKGROUND; data_type++) { - cfg = cmp_cfg_icu_create(data_type, CMP_MODE_DIFF_MULTI, 16, CMP_LOSSLESS); - error = cmp_cfg_icu_imagette(&cfg, cmp_par, spillover_par); - if (data_type == DATA_TYPE_IMAGETTE || - data_type == DATA_TYPE_SAT_IMAGETTE || - data_type == DATA_TYPE_F_CAM_IMAGETTE) { - TEST_ASSERT_FALSE(error); - TEST_ASSERT_EQUAL_INT(data_type, cfg.data_type); - TEST_ASSERT_EQUAL_INT(cfg.golomb_par, MAX_IMA_GOLOMB_PAR); - TEST_ASSERT_EQUAL_INT(cfg.spill, cmp_ima_max_spill(MAX_IMA_GOLOMB_PAR)); - } else { - TEST_ASSERT_TRUE(error); - } - } - - /* model/1d MODE tests */ - - /* cmp_par to big */ - cfg = cmp_cfg_icu_create(DATA_TYPE_IMAGETTE, CMP_MODE_MODEL_MULTI, 16, CMP_LOSSLESS); - cmp_par = MAX_NON_IMA_GOLOMB_PAR + 1; - spillover_par = MIN_IMA_SPILL; - error = cmp_cfg_icu_imagette(&cfg, cmp_par, spillover_par); - TEST_ASSERT_TRUE(error); - /* ignore in RAW MODE */ - cfg = cmp_cfg_icu_create(DATA_TYPE_IMAGETTE, CMP_MODE_RAW, 16, CMP_LOSSLESS); - error = cmp_cfg_icu_imagette(&cfg, cmp_par, spillover_par); - TEST_ASSERT_FALSE(error); - - /* cmp_par to small */ - cfg = cmp_cfg_icu_create(DATA_TYPE_IMAGETTE, CMP_MODE_MODEL_MULTI, 16, CMP_LOSSLESS); - cmp_par = MIN_IMA_GOLOMB_PAR - 1; - spillover_par = MIN_IMA_SPILL; - error = cmp_cfg_icu_imagette(&cfg, cmp_par, spillover_par); - TEST_ASSERT_TRUE(error); - /* ignore in RAW MODE */ - cfg = cmp_cfg_icu_create(DATA_TYPE_IMAGETTE, CMP_MODE_RAW, 16, CMP_LOSSLESS); - error = cmp_cfg_icu_imagette(&cfg, cmp_par, spillover_par); - TEST_ASSERT_FALSE(error); - - /* spillover_par to big */ - cfg = cmp_cfg_icu_create(DATA_TYPE_IMAGETTE, CMP_MODE_MODEL_MULTI, 16, CMP_LOSSLESS); - cmp_par = MIN_IMA_GOLOMB_PAR; - spillover_par = cmp_icu_max_spill(cmp_par)+1; - error = cmp_cfg_icu_imagette(&cfg, cmp_par, spillover_par); - TEST_ASSERT_TRUE(error); - /* ignore in RAW MODE */ - cfg = cmp_cfg_icu_create(DATA_TYPE_IMAGETTE, CMP_MODE_RAW, 16, CMP_LOSSLESS); - error = cmp_cfg_icu_imagette(&cfg, cmp_par, spillover_par); - TEST_ASSERT_FALSE(error); - - /* spillover_par to small */ - cfg = cmp_cfg_icu_create(DATA_TYPE_IMAGETTE, CMP_MODE_DIFF_ZERO, 0, CMP_LOSSLESS); - cmp_par = MAX_IMA_GOLOMB_PAR; - spillover_par = MIN_IMA_SPILL-1; - error = cmp_cfg_icu_imagette(&cfg, cmp_par, spillover_par); - TEST_ASSERT_TRUE(error); - /* ignore in RAW MODE */ - cfg = cmp_cfg_icu_create(DATA_TYPE_IMAGETTE, CMP_MODE_RAW, 16, CMP_LOSSLESS); - error = cmp_cfg_icu_imagette(&cfg, cmp_par, spillover_par); - TEST_ASSERT_FALSE(error); - - /* cfg = NULL test*/ - error = cmp_cfg_icu_imagette(NULL, cmp_par, spillover_par); - TEST_ASSERT_TRUE(error); -} - - -/** - * @test cmp_cfg_fx_cob - */ - -void test_cmp_cfg_fx_cob(void) -{ - struct cmp_cfg cfg = {0}; - uint32_t cmp_par_exp_flags = 2; - uint32_t spillover_exp_flags = 2; - uint32_t cmp_par_fx = 2; - uint32_t spillover_fx = 2; - uint32_t cmp_par_ncob = 2; - uint32_t spillover_ncob = 2; - uint32_t cmp_par_efx = 2; - uint32_t spillover_efx = 2; - uint32_t cmp_par_ecob = 2; - uint32_t spillover_ecob = 2; - uint32_t cmp_par_fx_cob_variance = 2; - uint32_t spillover_fx_cob_variance = 2; - int error; - enum cmp_data_type data_type; - - - /* wrong data type test */ - for (data_type = 0; data_type <= DATA_TYPE_F_CAM_BACKGROUND; data_type++) { - cfg = cmp_cfg_icu_create(data_type, CMP_MODE_MODEL_ZERO, 16, CMP_LOSSLESS); - 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); - if (data_type == DATA_TYPE_S_FX || - data_type == DATA_TYPE_S_FX_EFX || - data_type == DATA_TYPE_S_FX_NCOB || - data_type == DATA_TYPE_S_FX_EFX_NCOB_ECOB || - data_type == DATA_TYPE_L_FX || - data_type == DATA_TYPE_L_FX_EFX || - data_type == DATA_TYPE_L_FX_NCOB || - data_type == DATA_TYPE_L_FX_EFX_NCOB_ECOB || - data_type == DATA_TYPE_F_FX || - data_type == DATA_TYPE_F_FX_EFX || - data_type == DATA_TYPE_F_FX_NCOB || - data_type == DATA_TYPE_F_FX_EFX_NCOB_ECOB) { - TEST_ASSERT_FALSE(error); - TEST_ASSERT_EQUAL_INT(data_type, cfg.data_type); - TEST_ASSERT_EQUAL_INT(2, cfg.cmp_par_fx); - TEST_ASSERT_EQUAL_INT(2, cfg.spill_fx); - TEST_ASSERT_EQUAL_INT(2, cfg.cmp_par_exp_flags); - TEST_ASSERT_EQUAL_INT(2, cfg.spill_exp_flags); - TEST_ASSERT_EQUAL_INT(2, cfg.cmp_par_efx); - TEST_ASSERT_EQUAL_INT(2, cfg.spill_efx); - TEST_ASSERT_EQUAL_INT(2, cfg.cmp_par_ncob); - TEST_ASSERT_EQUAL_INT(2, cfg.spill_ncob); - TEST_ASSERT_EQUAL_INT(2, cfg.cmp_par_ecob); - TEST_ASSERT_EQUAL_INT(2, cfg.spill_ecob); - TEST_ASSERT_EQUAL_INT(2, cfg.cmp_par_fx_cob_variance); - TEST_ASSERT_EQUAL_INT(2, cfg.spill_fx_cob_variance); - } else { - TEST_ASSERT_TRUE(error); - } - } - - /* cfg == NULL test */ - error = cmp_cfg_fx_cob(NULL, 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_TRUE(error); - - /* test DATA_TYPE_S_FX */ - cfg = cmp_cfg_icu_create(DATA_TYPE_S_FX, CMP_MODE_MODEL_ZERO, 16, CMP_LOSSLESS); - cmp_par_exp_flags = MAX_NON_IMA_GOLOMB_PAR; - spillover_exp_flags = cmp_icu_max_spill(cmp_par_exp_flags); - cmp_par_fx = MIN_NON_IMA_GOLOMB_PAR; - spillover_fx = MIN_NON_IMA_SPILL; - cmp_par_ncob = ~0U; /* invalid parameter */ - spillover_ncob = ~0U; /* invalid parameter */ - cmp_par_efx = ~0U; /* invalid parameter */ - spillover_efx = ~0U; /* invalid parameter */ - cmp_par_ecob = ~0U; /* invalid parameter */ - spillover_ecob = ~0U; /* invalid parameter */ - cmp_par_fx_cob_variance = ~0U; /* invalid parameter */ - spillover_fx_cob_variance = ~0U; /* invalid parameter */ - - 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); - TEST_ASSERT_EQUAL_INT(cmp_par_fx, cfg.cmp_par_fx); - TEST_ASSERT_EQUAL_INT(spillover_fx, cfg.spill_fx); - TEST_ASSERT_EQUAL_INT(cmp_par_exp_flags, cfg.cmp_par_exp_flags); - TEST_ASSERT_EQUAL_INT(spillover_exp_flags, cfg.spill_exp_flags); - - /* invalid spillover_exp_flags parameter */ - cmp_par_exp_flags = MAX_NON_IMA_GOLOMB_PAR; - spillover_exp_flags = cmp_icu_max_spill(cmp_par_exp_flags)+1; - 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_TRUE(error); - - /* invalid cmp_par_fx parameter */ - cmp_par_exp_flags = MAX_NON_IMA_GOLOMB_PAR; - spillover_exp_flags = cmp_icu_max_spill(cmp_par_exp_flags); - cmp_par_fx = MIN_NON_IMA_GOLOMB_PAR - 1; - spillover_fx = MIN_NON_IMA_SPILL; - 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_TRUE(error); - - - /* test DATA_TYPE_S_FX_EFX */ - cfg = cmp_cfg_icu_create(DATA_TYPE_S_FX_EFX, CMP_MODE_MODEL_ZERO, 0, 1); - cmp_par_exp_flags = MAX_NON_IMA_GOLOMB_PAR; - spillover_exp_flags = cmp_icu_max_spill(cmp_par_exp_flags); - cmp_par_fx = MIN_NON_IMA_GOLOMB_PAR; - spillover_fx = MIN_NON_IMA_SPILL; - cmp_par_ncob = ~0U; /* invalid parameter */ - spillover_ncob = ~0U; /* invalid parameter */ - cmp_par_efx = 23; - spillover_efx = 42; - cmp_par_ecob = ~0U; /* invalid parameter */ - spillover_ecob = ~0U; /* invalid parameter */ - cmp_par_fx_cob_variance = ~0U; /* invalid parameter */ - spillover_fx_cob_variance = ~0U; /* invalid parameter */ - 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); - TEST_ASSERT_EQUAL_INT(cmp_par_fx, cfg.cmp_par_fx); - TEST_ASSERT_EQUAL_INT(spillover_fx, cfg.spill_fx); - TEST_ASSERT_EQUAL_INT(cmp_par_exp_flags, cfg.cmp_par_exp_flags); - TEST_ASSERT_EQUAL_INT(spillover_exp_flags, cfg.spill_exp_flags); - TEST_ASSERT_EQUAL_INT(cmp_par_efx, cfg.cmp_par_efx); - TEST_ASSERT_EQUAL_INT(spillover_efx, cfg.spill_efx); - - /* invalid spillover_efx parameter */ - spillover_efx = 0; - 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_TRUE(error); - - - /* test DATA_TYPE_S_FX_NCOB */ - cfg = cmp_cfg_icu_create(DATA_TYPE_S_FX_NCOB, CMP_MODE_MODEL_ZERO, 0, 1); - cmp_par_exp_flags = MAX_NON_IMA_GOLOMB_PAR; - spillover_exp_flags = cmp_icu_max_spill(cmp_par_exp_flags); - cmp_par_fx = MIN_NON_IMA_GOLOMB_PAR; - spillover_fx = MIN_NON_IMA_SPILL; - cmp_par_ncob = 19; - spillover_ncob = 5; - cmp_par_efx = ~0U; /* invalid parameter */ - spillover_efx = ~0U; /* invalid parameter */ - cmp_par_ecob = ~0U; /* invalid parameter */ - spillover_ecob = ~0U; /* invalid parameter */ - cmp_par_fx_cob_variance = ~0U; /* invalid parameter */ - spillover_fx_cob_variance = ~0U; /* invalid parameter */ - 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); - TEST_ASSERT_EQUAL_INT(cmp_par_fx, cfg.cmp_par_fx); - TEST_ASSERT_EQUAL_INT(spillover_fx, cfg.spill_fx); - TEST_ASSERT_EQUAL_INT(cmp_par_exp_flags, cfg.cmp_par_exp_flags); - TEST_ASSERT_EQUAL_INT(spillover_exp_flags, cfg.spill_exp_flags); - TEST_ASSERT_EQUAL_INT(cmp_par_ncob, cfg.cmp_par_ncob); - TEST_ASSERT_EQUAL_INT(spillover_ncob, cfg.spill_ncob); - - /* invalid cmp_par_ncob parameter */ - cmp_par_ncob = 0; - 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_TRUE(error); - - - /* test DATA_TYPE_S_FX_EFX_NCOB_ECOB */ - cfg = cmp_cfg_icu_create(DATA_TYPE_S_FX_EFX_NCOB_ECOB, CMP_MODE_DIFF_ZERO, 7, CMP_LOSSLESS); - cmp_par_exp_flags = MAX_NON_IMA_GOLOMB_PAR; - spillover_exp_flags = cmp_icu_max_spill(cmp_par_exp_flags); - cmp_par_fx = MIN_NON_IMA_GOLOMB_PAR; - spillover_fx = MIN_NON_IMA_SPILL; - cmp_par_ncob = 19; - spillover_ncob = 5; - cmp_par_efx = 23; - spillover_efx = 42; - cmp_par_ecob = MAX_NON_IMA_GOLOMB_PAR; - spillover_ecob = MIN_NON_IMA_SPILL; - cmp_par_fx_cob_variance = ~0U; /* invalid parameter */ - spillover_fx_cob_variance = ~0U; /* invalid parameter */ - 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); - TEST_ASSERT_EQUAL_INT(cmp_par_fx, cfg.cmp_par_fx); - TEST_ASSERT_EQUAL_INT(spillover_fx, cfg.spill_fx); - TEST_ASSERT_EQUAL_INT(cmp_par_exp_flags, cfg.cmp_par_exp_flags); - TEST_ASSERT_EQUAL_INT(spillover_exp_flags, cfg.spill_exp_flags); - TEST_ASSERT_EQUAL_INT(cmp_par_ncob, cfg.cmp_par_ncob); - TEST_ASSERT_EQUAL_INT(spillover_ncob, cfg.spill_ncob); - TEST_ASSERT_EQUAL_INT(cmp_par_efx, cfg.cmp_par_efx); - TEST_ASSERT_EQUAL_INT(spillover_efx, cfg.spill_efx); - TEST_ASSERT_EQUAL_INT(cmp_par_ecob, cfg.cmp_par_ecob); - TEST_ASSERT_EQUAL_INT(spillover_ecob, cfg.spill_ecob); - - /* invalid cmp_par_ecob parameter */ - cmp_par_ecob = -1U; - 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_TRUE(error); - - - /* DATA_TYPE_L_FX */ - cfg = cmp_cfg_icu_create(DATA_TYPE_L_FX, CMP_MODE_DIFF_ZERO, 7, CMP_LOSSLESS); - cmp_par_exp_flags = MAX_NON_IMA_GOLOMB_PAR; - spillover_exp_flags = cmp_icu_max_spill(cmp_par_exp_flags); - cmp_par_fx = MIN_NON_IMA_GOLOMB_PAR; - spillover_fx = MIN_NON_IMA_SPILL; - cmp_par_ncob = ~0U; /* invalid parameter */ - spillover_ncob = ~0U; /* invalid parameter */ - cmp_par_efx = ~0U; /* invalid parameter */ - spillover_efx = ~0U; /* invalid parameter */ - cmp_par_ecob = ~0U; /* invalid parameter */ - spillover_ecob = ~0U; /* invalid parameter */ - cmp_par_fx_cob_variance = 30; - spillover_fx_cob_variance = 8; - - 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); - TEST_ASSERT_EQUAL_INT(cmp_par_fx, cfg.cmp_par_fx); - TEST_ASSERT_EQUAL_INT(spillover_fx, cfg.spill_fx); - TEST_ASSERT_EQUAL_INT(cmp_par_exp_flags, cfg.cmp_par_exp_flags); - TEST_ASSERT_EQUAL_INT(spillover_exp_flags, cfg.spill_exp_flags); - TEST_ASSERT_EQUAL_INT(cmp_par_fx_cob_variance, cfg.cmp_par_fx_cob_variance); - TEST_ASSERT_EQUAL_INT(spillover_fx_cob_variance, cfg.spill_fx_cob_variance); - - /* invalid spillover_fx_cob_variance parameter */ - spillover_fx_cob_variance = 1; - 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_TRUE(error); - - - /* DATA_TYPE_L_FX_EFX */ - cfg = cmp_cfg_icu_create(DATA_TYPE_L_FX_EFX, CMP_MODE_DIFF_ZERO, 7, CMP_LOSSLESS); - cmp_par_exp_flags = MAX_NON_IMA_GOLOMB_PAR; - spillover_exp_flags = cmp_icu_max_spill(cmp_par_exp_flags); - cmp_par_fx = MIN_NON_IMA_GOLOMB_PAR; - spillover_fx = MIN_NON_IMA_SPILL; - cmp_par_ncob = ~0U; /* invalid parameter */ - spillover_ncob = ~0U; /* invalid parameter */ - cmp_par_efx = 23; - spillover_efx = 42; - cmp_par_ecob = ~0U; /* invalid parameter */ - spillover_ecob = ~0U; /* invalid parameter */ - cmp_par_fx_cob_variance = 30; - spillover_fx_cob_variance = 8; - - 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); - TEST_ASSERT_EQUAL_INT(cmp_par_fx, cfg.cmp_par_fx); - TEST_ASSERT_EQUAL_INT(spillover_fx, cfg.spill_fx); - TEST_ASSERT_EQUAL_INT(cmp_par_exp_flags, cfg.cmp_par_exp_flags); - TEST_ASSERT_EQUAL_INT(spillover_exp_flags, cfg.spill_exp_flags); - TEST_ASSERT_EQUAL_INT(cmp_par_efx, cfg.cmp_par_efx); - TEST_ASSERT_EQUAL_INT(spillover_efx, cfg.spill_efx); - TEST_ASSERT_EQUAL_INT(cmp_par_fx_cob_variance, cfg.cmp_par_fx_cob_variance); - TEST_ASSERT_EQUAL_INT(spillover_fx_cob_variance, cfg.spill_fx_cob_variance); - - - /* DATA_TYPE_L_FX_NCOB */ - cfg = cmp_cfg_icu_create(DATA_TYPE_L_FX_NCOB, CMP_MODE_DIFF_ZERO, 7, CMP_LOSSLESS); - cmp_par_exp_flags = MAX_NON_IMA_GOLOMB_PAR; - spillover_exp_flags = cmp_icu_max_spill(cmp_par_exp_flags); - cmp_par_fx = MIN_NON_IMA_GOLOMB_PAR; - spillover_fx = MIN_NON_IMA_SPILL; - cmp_par_ncob = 19; - spillover_ncob = 5; - cmp_par_efx = ~0U; /* invalid parameter */ - spillover_efx = ~0U; /* invalid parameter */ - cmp_par_ecob = ~0U; /* invalid parameter */ - spillover_ecob = ~0U; /* invalid parameter */ - cmp_par_fx_cob_variance = 30; - spillover_fx_cob_variance = 8; - - 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); - TEST_ASSERT_EQUAL_INT(cmp_par_fx, cfg.cmp_par_fx); - TEST_ASSERT_EQUAL_INT(spillover_fx, cfg.spill_fx); - TEST_ASSERT_EQUAL_INT(cmp_par_exp_flags, cfg.cmp_par_exp_flags); - TEST_ASSERT_EQUAL_INT(spillover_exp_flags, cfg.spill_exp_flags); - TEST_ASSERT_EQUAL_INT(cmp_par_ncob, cfg.cmp_par_ncob); - TEST_ASSERT_EQUAL_INT(spillover_ncob, cfg.spill_ncob); - TEST_ASSERT_EQUAL_INT(cmp_par_fx_cob_variance, cfg.cmp_par_fx_cob_variance); - TEST_ASSERT_EQUAL_INT(spillover_fx_cob_variance, cfg.spill_fx_cob_variance); - - - /* DATA_TYPE_L_FX_EFX_NCOB_ECOB */ - cfg = cmp_cfg_icu_create(DATA_TYPE_L_FX_EFX_NCOB_ECOB, CMP_MODE_DIFF_ZERO, 7, CMP_LOSSLESS); - cmp_par_exp_flags = MAX_NON_IMA_GOLOMB_PAR; - spillover_exp_flags = cmp_icu_max_spill(cmp_par_exp_flags); - cmp_par_fx = MIN_NON_IMA_GOLOMB_PAR; - spillover_fx = MIN_NON_IMA_SPILL; - cmp_par_ncob = 19; - spillover_ncob = 5; - cmp_par_efx = 23; - spillover_efx = 42; - cmp_par_ecob = MAX_NON_IMA_GOLOMB_PAR; - spillover_ecob = MIN_NON_IMA_SPILL; - cmp_par_fx_cob_variance = 30; - spillover_fx_cob_variance = 8; - - 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); - TEST_ASSERT_EQUAL_INT(cmp_par_fx, cfg.cmp_par_fx); - TEST_ASSERT_EQUAL_INT(spillover_fx, cfg.spill_fx); - TEST_ASSERT_EQUAL_INT(cmp_par_exp_flags, cfg.cmp_par_exp_flags); - TEST_ASSERT_EQUAL_INT(spillover_exp_flags, cfg.spill_exp_flags); - TEST_ASSERT_EQUAL_INT(cmp_par_efx, cfg.cmp_par_efx); - TEST_ASSERT_EQUAL_INT(spillover_efx, cfg.spill_efx); - TEST_ASSERT_EQUAL_INT(cmp_par_ncob, cfg.cmp_par_ncob); - TEST_ASSERT_EQUAL_INT(spillover_ncob, cfg.spill_ncob); - TEST_ASSERT_EQUAL_INT(cmp_par_ecob, cfg.cmp_par_ecob); - TEST_ASSERT_EQUAL_INT(spillover_ecob, cfg.spill_ecob); - TEST_ASSERT_EQUAL_INT(cmp_par_fx_cob_variance, cfg.cmp_par_fx_cob_variance); - TEST_ASSERT_EQUAL_INT(spillover_fx_cob_variance, cfg.spill_fx_cob_variance); - - - /* DATA_TYPE_F_FX */ - cfg = cmp_cfg_icu_create(DATA_TYPE_F_FX, CMP_MODE_DIFF_ZERO, 7, CMP_LOSSLESS); - cmp_par_exp_flags = ~0U; /* invalid parameter */ - spillover_exp_flags = ~0U; /* invalid parameter */ - cmp_par_fx = MIN_NON_IMA_GOLOMB_PAR; - spillover_fx = MIN_NON_IMA_SPILL; - cmp_par_ncob = ~0U; /* invalid parameter */ - spillover_ncob = ~0U; /* invalid parameter */ - cmp_par_efx = ~0U; /* invalid parameter */ - spillover_efx = ~0U; /* invalid parameter */ - cmp_par_ecob = ~0U; /* invalid parameter */ - spillover_ecob = ~0U; /* invalid parameter */ - cmp_par_fx_cob_variance = ~0U; /* invalid parameter */ - spillover_fx_cob_variance = ~0U; /* invalid parameter */ - - 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); - TEST_ASSERT_EQUAL_INT(cmp_par_fx, cfg.cmp_par_fx); - TEST_ASSERT_EQUAL_INT(spillover_fx, cfg.spill_fx); - - - /* DATA_TYPE_F_FX_EFX */ - cfg = cmp_cfg_icu_create(DATA_TYPE_F_FX_EFX, CMP_MODE_DIFF_ZERO, 7, CMP_LOSSLESS); - cmp_par_exp_flags = ~0U; /* invalid parameter */ - spillover_exp_flags = ~0U; /* invalid parameter */ - cmp_par_fx = MIN_NON_IMA_GOLOMB_PAR; - spillover_fx = MIN_NON_IMA_SPILL; - cmp_par_ncob = ~0U; /* invalid parameter */ - spillover_ncob = ~0U; /* invalid parameter */ - cmp_par_efx = 23; - spillover_efx = 42; - cmp_par_ecob = ~0U; /* invalid parameter */ - spillover_ecob = ~0U; /* invalid parameter */ - cmp_par_fx_cob_variance = ~0U; /* invalid parameter */ - spillover_fx_cob_variance = ~0U; /* invalid parameter */ - - 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); - TEST_ASSERT_EQUAL_INT(cmp_par_fx, cfg.cmp_par_fx); - TEST_ASSERT_EQUAL_INT(spillover_fx, cfg.spill_fx); - TEST_ASSERT_EQUAL_INT(cmp_par_efx, cfg.cmp_par_efx); - TEST_ASSERT_EQUAL_INT(spillover_efx, cfg.spill_efx); - - - /* DATA_TYPE_F_FX_NCOB */ - cfg = cmp_cfg_icu_create(DATA_TYPE_F_FX_NCOB, CMP_MODE_DIFF_ZERO, 7, CMP_LOSSLESS); - cmp_par_exp_flags = ~0U; /* invalid parameter */ - spillover_exp_flags = ~0U; /* invalid parameter */ - cmp_par_fx = MIN_NON_IMA_GOLOMB_PAR; - spillover_fx = MIN_NON_IMA_SPILL; - cmp_par_ncob = MIN_NON_IMA_GOLOMB_PAR; - spillover_ncob = cmp_icu_max_spill(cmp_par_ncob); - cmp_par_efx = ~0U; /* invalid parameter */ - spillover_efx = ~0U; /* invalid parameter */ - cmp_par_ecob = ~0U; /* invalid parameter */ - spillover_ecob = ~0U; /* invalid parameter */ - cmp_par_fx_cob_variance = ~0U; /* invalid parameter */ - spillover_fx_cob_variance = ~0U; /* invalid parameter */ - - 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); - TEST_ASSERT_EQUAL_INT(cmp_par_fx, cfg.cmp_par_fx); - TEST_ASSERT_EQUAL_INT(spillover_fx, cfg.spill_fx); - TEST_ASSERT_EQUAL_INT(cmp_par_ncob, cfg.cmp_par_ncob); - TEST_ASSERT_EQUAL_INT(spillover_ncob, cfg.spill_ncob); - - - /* DATA_TYPE_F_FX_EFX_NCOB_ECOB */ - cfg = cmp_cfg_icu_create(DATA_TYPE_F_FX_EFX_NCOB_ECOB, CMP_MODE_DIFF_ZERO, 7, CMP_LOSSLESS); - cmp_par_exp_flags = ~0U; /* invalid parameter */ - spillover_exp_flags = ~0U; /* invalid parameter */ - cmp_par_fx = MIN_NON_IMA_GOLOMB_PAR; - spillover_fx = MIN_NON_IMA_SPILL; - cmp_par_ncob = MIN_NON_IMA_GOLOMB_PAR; - spillover_ncob = cmp_icu_max_spill(cmp_par_ncob); - cmp_par_efx = 23; - spillover_efx = 42; - cmp_par_ecob = MAX_NON_IMA_GOLOMB_PAR; - spillover_ecob = MIN_NON_IMA_SPILL; - cmp_par_fx_cob_variance = ~0U; /* invalid parameter */ - spillover_fx_cob_variance = ~0U; /* invalid parameter */ - - 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); - TEST_ASSERT_EQUAL_INT(cmp_par_fx, cfg.cmp_par_fx); - TEST_ASSERT_EQUAL_INT(spillover_fx, cfg.spill_fx); - TEST_ASSERT_EQUAL_INT(cmp_par_ncob, cfg.cmp_par_ncob); - TEST_ASSERT_EQUAL_INT(spillover_ncob, cfg.spill_ncob); - TEST_ASSERT_EQUAL_INT(cmp_par_efx, cfg.cmp_par_efx); - TEST_ASSERT_EQUAL_INT(spillover_efx, cfg.spill_efx); - TEST_ASSERT_EQUAL_INT(cmp_par_ecob, cfg.cmp_par_ecob); - TEST_ASSERT_EQUAL_INT(spillover_ecob, cfg.spill_ecob); -} - - -/** - * @test cmp_cfg_aux - */ - -void test_cmp_cfg_aux(void) -{ struct cmp_cfg cfg; - uint32_t cmp_par_mean = 2; - uint32_t spillover_mean = 3; - uint32_t cmp_par_variance = 4; - uint32_t spillover_variance = 5; - uint32_t cmp_par_pixels_error = 6; - uint32_t spillover_pixels_error = 7; - int error; - enum cmp_data_type data_type; - - /* wrong data type test */ - for (data_type = 0; data_type <= DATA_TYPE_F_CAM_BACKGROUND; data_type++) { - cfg = cmp_cfg_icu_create(data_type, CMP_MODE_MODEL_ZERO, 16, CMP_LOSSLESS); - error = cmp_cfg_aux(&cfg, cmp_par_mean, spillover_mean, - cmp_par_variance, spillover_variance, - cmp_par_pixels_error, spillover_pixels_error); - if (data_type == DATA_TYPE_OFFSET || data_type == DATA_TYPE_F_CAM_OFFSET) { - TEST_ASSERT_FALSE(error); - TEST_ASSERT_EQUAL_INT(data_type, cfg.data_type); - TEST_ASSERT_EQUAL_INT(2, cfg.cmp_par_offset_mean); - TEST_ASSERT_EQUAL_INT(3, cfg.spill_offset_mean); - TEST_ASSERT_EQUAL_INT(4, cfg.cmp_par_offset_variance); - TEST_ASSERT_EQUAL_INT(5, cfg.spill_offset_variance); - } else if (data_type == DATA_TYPE_BACKGROUND || - data_type == DATA_TYPE_F_CAM_BACKGROUND) { - TEST_ASSERT_FALSE(error); - TEST_ASSERT_EQUAL_INT(data_type, cfg.data_type); - TEST_ASSERT_EQUAL_INT(2, cfg.cmp_par_background_mean); - TEST_ASSERT_EQUAL_INT(3, cfg.spill_background_mean); - TEST_ASSERT_EQUAL_INT(4, cfg.cmp_par_background_variance); - TEST_ASSERT_EQUAL_INT(5, cfg.spill_background_variance); - TEST_ASSERT_EQUAL_INT(6, cfg.cmp_par_background_pixels_error); - TEST_ASSERT_EQUAL_INT(7, cfg.spill_background_pixels_error); - } else if (data_type == DATA_TYPE_SMEARING) { - TEST_ASSERT_FALSE(error); - TEST_ASSERT_EQUAL_INT(data_type, cfg.data_type); - TEST_ASSERT_EQUAL_INT(2, cfg.cmp_par_smearing_mean); - TEST_ASSERT_EQUAL_INT(3, cfg.spill_smearing_mean); - TEST_ASSERT_EQUAL_INT(4, cfg.cmp_par_smearing_variance); - TEST_ASSERT_EQUAL_INT(5, cfg.spill_smearing_variance); - TEST_ASSERT_EQUAL_INT(6, cfg.cmp_par_smearing_pixels_error); - TEST_ASSERT_EQUAL_INT(7, cfg.spill_smearing_pixels_error); - } else { - TEST_ASSERT_TRUE(error); - } - } - - /* cfg == NULL test */ - error = cmp_cfg_aux(NULL, cmp_par_mean, spillover_mean, - cmp_par_variance, spillover_variance, - cmp_par_pixels_error, spillover_pixels_error); - TEST_ASSERT_TRUE(error); - - - /* DATA_TYPE_OFFSET */ - cfg = cmp_cfg_icu_create(DATA_TYPE_OFFSET, CMP_MODE_DIFF_ZERO, 7, CMP_LOSSLESS); - cmp_par_mean = MIN_NON_IMA_GOLOMB_PAR; - spillover_mean = cmp_icu_max_spill(MIN_NON_IMA_GOLOMB_PAR); - cmp_par_variance = MIN_NON_IMA_GOLOMB_PAR; - spillover_variance = MIN_NON_IMA_SPILL; - cmp_par_pixels_error = ~0U; - spillover_pixels_error = ~0U; - - 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); - TEST_ASSERT_EQUAL_INT(MIN_NON_IMA_GOLOMB_PAR, cfg.cmp_par_offset_mean); - TEST_ASSERT_EQUAL_INT(cmp_icu_max_spill(MIN_NON_IMA_GOLOMB_PAR), cfg.spill_offset_mean); - TEST_ASSERT_EQUAL_INT(MIN_NON_IMA_GOLOMB_PAR, cfg.cmp_par_offset_variance); - TEST_ASSERT_EQUAL_INT(2, cfg.spill_offset_variance); - - /* This should fail */ - cmp_par_mean = MIN_NON_IMA_GOLOMB_PAR-1; - error = cmp_cfg_aux(&cfg, cmp_par_mean, spillover_mean, - cmp_par_variance, spillover_variance, - cmp_par_pixels_error, spillover_pixels_error); - TEST_ASSERT_TRUE(error); - - - /* DATA_TYPE_F_CAM_OFFSET */ - cfg = cmp_cfg_icu_create(DATA_TYPE_F_CAM_OFFSET, CMP_MODE_DIFF_MULTI, 7, CMP_LOSSLESS); - cmp_par_mean = MIN_NON_IMA_GOLOMB_PAR; - spillover_mean = cmp_icu_max_spill(MIN_NON_IMA_GOLOMB_PAR); - cmp_par_variance = MIN_NON_IMA_GOLOMB_PAR; - spillover_variance = MIN_NON_IMA_SPILL; - cmp_par_pixels_error = ~0U; - spillover_pixels_error = ~0U; - - 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); - TEST_ASSERT_EQUAL_INT(MIN_NON_IMA_GOLOMB_PAR, cfg.cmp_par_offset_mean); - TEST_ASSERT_EQUAL_INT(cmp_icu_max_spill(MIN_NON_IMA_GOLOMB_PAR), cfg.spill_offset_mean); - TEST_ASSERT_EQUAL_INT(MIN_NON_IMA_GOLOMB_PAR, cfg.cmp_par_offset_variance); - TEST_ASSERT_EQUAL_INT(2, cfg.spill_offset_variance); - - /* This should fail */ - cmp_par_variance = MIN_NON_IMA_GOLOMB_PAR-1; - error = cmp_cfg_aux(&cfg, cmp_par_mean, spillover_mean, - cmp_par_variance, spillover_variance, - cmp_par_pixels_error, spillover_pixels_error); - TEST_ASSERT_TRUE(error); - - - cfg = cmp_cfg_icu_create(DATA_TYPE_BACKGROUND, CMP_MODE_DIFF_ZERO, 7, CMP_LOSSLESS); - cmp_par_mean = MAX_NON_IMA_GOLOMB_PAR; - spillover_mean = cmp_icu_max_spill(MAX_NON_IMA_GOLOMB_PAR); - cmp_par_variance = MIN_NON_IMA_GOLOMB_PAR; - spillover_variance = MIN_NON_IMA_SPILL; - cmp_par_pixels_error = 42; - spillover_pixels_error = 23; - - 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); - TEST_ASSERT_EQUAL_INT(MAX_NON_IMA_GOLOMB_PAR, cfg.cmp_par_background_mean); - TEST_ASSERT_EQUAL_INT(cmp_icu_max_spill(MAX_NON_IMA_GOLOMB_PAR), cfg.spill_background_mean); - TEST_ASSERT_EQUAL_INT(MIN_NON_IMA_GOLOMB_PAR, cfg.cmp_par_background_variance); - TEST_ASSERT_EQUAL_INT(MIN_NON_IMA_SPILL, cfg.spill_background_variance); - TEST_ASSERT_EQUAL_INT(42, cfg.cmp_par_background_pixels_error); - TEST_ASSERT_EQUAL_INT(23, cfg.spill_background_pixels_error); - - /* This should fail */ - cmp_par_variance = MIN_NON_IMA_GOLOMB_PAR-1; - error = cmp_cfg_aux(&cfg, cmp_par_mean, spillover_mean, - cmp_par_variance, spillover_variance, - cmp_par_pixels_error, spillover_pixels_error); - TEST_ASSERT_TRUE(error); - - - /* DATA_TYPE_BACKGROUND */ - cfg = cmp_cfg_icu_create(DATA_TYPE_BACKGROUND, CMP_MODE_DIFF_ZERO, 7, CMP_LOSSLESS); - cmp_par_mean = MAX_NON_IMA_GOLOMB_PAR; - spillover_mean = cmp_icu_max_spill(MAX_NON_IMA_GOLOMB_PAR); - cmp_par_variance = MIN_NON_IMA_GOLOMB_PAR; - spillover_variance = MIN_NON_IMA_SPILL; - cmp_par_pixels_error = 42; - spillover_pixels_error = 23; - - 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); - TEST_ASSERT_EQUAL_INT(MAX_NON_IMA_GOLOMB_PAR, cfg.cmp_par_background_mean); - TEST_ASSERT_EQUAL_INT(cmp_icu_max_spill(MAX_NON_IMA_GOLOMB_PAR), cfg.spill_background_mean); - TEST_ASSERT_EQUAL_INT(MIN_NON_IMA_GOLOMB_PAR, cfg.cmp_par_background_variance); - TEST_ASSERT_EQUAL_INT(MIN_NON_IMA_SPILL, cfg.spill_background_variance); - TEST_ASSERT_EQUAL_INT(42, cfg.cmp_par_background_pixels_error); - TEST_ASSERT_EQUAL_INT(23, cfg.spill_background_pixels_error); - - /* This should fail */ - cmp_par_variance = MIN_NON_IMA_GOLOMB_PAR-1; - error = cmp_cfg_aux(&cfg, cmp_par_mean, spillover_mean, - cmp_par_variance, spillover_variance, - cmp_par_pixels_error, spillover_pixels_error); - TEST_ASSERT_TRUE(error); - - - /* DATA_TYPE_F_CAM_BACKGROUND */ - cfg = cmp_cfg_icu_create(DATA_TYPE_F_CAM_BACKGROUND, CMP_MODE_DIFF_MULTI, 7, CMP_LOSSLESS); - cmp_par_mean = MAX_NON_IMA_GOLOMB_PAR; - spillover_mean = cmp_icu_max_spill(MAX_NON_IMA_GOLOMB_PAR); - cmp_par_variance = MIN_NON_IMA_GOLOMB_PAR; - spillover_variance = MIN_NON_IMA_SPILL; - cmp_par_pixels_error = 42; - spillover_pixels_error = 23; - - 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); - TEST_ASSERT_EQUAL_INT(MAX_NON_IMA_GOLOMB_PAR, cfg.cmp_par_background_mean); - TEST_ASSERT_EQUAL_INT(cmp_icu_max_spill(MAX_NON_IMA_GOLOMB_PAR), cfg.spill_background_mean); - TEST_ASSERT_EQUAL_INT(MIN_NON_IMA_GOLOMB_PAR, cfg.cmp_par_background_variance); - TEST_ASSERT_EQUAL_INT(MIN_NON_IMA_SPILL, cfg.spill_background_variance); - TEST_ASSERT_EQUAL_INT(42, cfg.cmp_par_background_pixels_error); - TEST_ASSERT_EQUAL_INT(23, cfg.spill_background_pixels_error); - - /* This should fail */ - cmp_par_pixels_error = MIN_NON_IMA_GOLOMB_PAR-1; - error = cmp_cfg_aux(&cfg, cmp_par_mean, spillover_mean, - cmp_par_variance, spillover_variance, - cmp_par_pixels_error, spillover_pixels_error); - TEST_ASSERT_TRUE(error); - - - /* DATA_TYPE_SMEARING */ - cfg = cmp_cfg_icu_create(DATA_TYPE_SMEARING, CMP_MODE_DIFF_ZERO, 7, CMP_LOSSLESS); - cmp_par_mean = MAX_NON_IMA_GOLOMB_PAR; - spillover_mean = cmp_icu_max_spill(MAX_NON_IMA_GOLOMB_PAR); - cmp_par_variance = MIN_NON_IMA_GOLOMB_PAR; - spillover_variance = MIN_NON_IMA_SPILL; - cmp_par_pixels_error = 42; - spillover_pixels_error = 23; - - 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); - TEST_ASSERT_EQUAL_INT(MAX_NON_IMA_GOLOMB_PAR, cfg.cmp_par_smearing_mean); - TEST_ASSERT_EQUAL_INT(cmp_icu_max_spill(MAX_NON_IMA_GOLOMB_PAR), cfg.spill_smearing_mean); - TEST_ASSERT_EQUAL_INT(MIN_NON_IMA_GOLOMB_PAR, cfg.cmp_par_smearing_variance); - TEST_ASSERT_EQUAL_INT(MIN_NON_IMA_SPILL, cfg.spill_smearing_variance); - TEST_ASSERT_EQUAL_INT(42, cfg.cmp_par_smearing_pixels_error); - TEST_ASSERT_EQUAL_INT(23, cfg.spill_smearing_pixels_error); - - /* This should fail */ - spillover_pixels_error = cmp_icu_max_spill(42)+1; - error = cmp_cfg_aux(&cfg, cmp_par_mean, spillover_mean, - cmp_par_variance, spillover_variance, - cmp_par_pixels_error, spillover_pixels_error); - TEST_ASSERT_TRUE(error); -} - - /** * @test map_to_pos */ @@ -2327,33 +1127,33 @@ void test_compress_imagette_diff(void) { uint16_t data[] = {0xFFFF, 1, 0, 42, 0x8000, 0x7FFF, 0xFFFF}; uint32_t output_buf[3] = {0xFFFF, 0xFFFF, 0xFFFF}; - uint32_t output_buf_size; - struct cmp_cfg cfg = {0}; - int error, cmp_size; + struct rdcu_cfg rcfg = {0}; + int error; + int32_t cmp_size; uint32_t golomb_par = 1; uint32_t spill = 8; uint32_t samples = 7; - cfg = cmp_cfg_icu_create(DATA_TYPE_IMAGETTE, CMP_MODE_DIFF_ZERO, - CMP_PAR_UNUSED, CMP_LOSSLESS); - TEST_ASSERT(cfg.data_type != DATA_TYPE_UNKNOWN); - output_buf_size = cmp_cfg_icu_buffers(&cfg, data, samples, NULL, NULL, - (uint32_t *)output_buf, samples); - TEST_ASSERT_EQUAL_INT(samples*sizeof(uint16_t), output_buf_size); - - error = cmp_cfg_icu_imagette(&cfg, golomb_par, spill); + error = rdcu_cfg_create(&rcfg, CMP_MODE_DIFF_ZERO, 8, CMP_LOSSLESS); TEST_ASSERT_FALSE(error); + rcfg.input_buf = data; + rcfg.samples = samples; + rcfg.icu_output_buf = output_buf; + rcfg.buffer_length = samples; + rcfg.golomb_par = golomb_par; + rcfg.spill = spill; + - cmp_size = icu_compress_data(&cfg); + cmp_size = compress_like_rdcu(&rcfg, NULL); TEST_ASSERT_EQUAL_INT(66, cmp_size); TEST_ASSERT_EQUAL_HEX(0xDF6002AB, be32_to_cpu(output_buf[0])); TEST_ASSERT_EQUAL_HEX(0xFEB70000, be32_to_cpu(output_buf[1])); TEST_ASSERT_EQUAL_HEX(0x00000000, be32_to_cpu(output_buf[2])); /* test: icu_output_buf = NULL */ - cfg.icu_output_buf = NULL; - cmp_size = icu_compress_data(&cfg); + rcfg.icu_output_buf = NULL; + cmp_size = compress_like_rdcu(&rcfg, NULL); TEST_ASSERT_EQUAL_INT(66, cmp_size); } @@ -2368,25 +1168,27 @@ void test_compress_imagette_model(void) uint16_t model[] = {0x0000, 0xFFFF, 0xF301, 0x8FFF, 0x0000, 0xFFFF, 0x0000}; uint16_t model_up[7] = {0}; uint32_t output_buf[3] = {~0U, ~0U, ~0U}; - uint32_t output_buf_size; - struct cmp_cfg cfg = {0}; + struct rdcu_cfg rcfg = {0}; uint32_t model_value = 8; uint32_t samples = 7; uint32_t buffer_length = 8; uint32_t golomb_par = 3; uint32_t spill = 8; - int cmp_size, error; - - cfg = cmp_cfg_icu_create(DATA_TYPE_IMAGETTE, CMP_MODE_MODEL_MULTI, - model_value, CMP_LOSSLESS); - TEST_ASSERT(cfg.data_type != DATA_TYPE_UNKNOWN); - output_buf_size = cmp_cfg_icu_buffers(&cfg, data, samples, model, model_up, - output_buf, buffer_length); - TEST_ASSERT_EQUAL_INT(buffer_length*sizeof(uint16_t), output_buf_size); - error = cmp_cfg_icu_imagette(&cfg, golomb_par, spill); + int32_t cmp_size; + int error; + + error = rdcu_cfg_create(&rcfg, CMP_MODE_MODEL_MULTI, model_value, CMP_LOSSLESS); TEST_ASSERT_FALSE(error); + rcfg.input_buf = data; + rcfg.samples = samples; + rcfg.model_buf = model; + rcfg.icu_new_model_buf = model_up; + rcfg.icu_output_buf = output_buf; + rcfg.buffer_length = buffer_length; + rcfg.golomb_par = golomb_par; + rcfg.spill = spill; - cmp_size = icu_compress_data(&cfg); + cmp_size = compress_like_rdcu(&rcfg, NULL); TEST_ASSERT_EQUAL_INT(76, cmp_size); TEST_ASSERT_EQUAL_HEX(0x2BDB4F5E, be32_to_cpu(output_buf[0])); @@ -2403,8 +1205,8 @@ void test_compress_imagette_model(void) /* error case: model mode without model data */ - cfg.model_buf = NULL; /* this is the error */ - cmp_size = icu_compress_data(&cfg); + rcfg.model_buf = NULL; /* this is the error */ + cmp_size = compress_like_rdcu(&rcfg, NULL); TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_size)); TEST_ASSERT_EQUAL(CMP_ERROR_PAR_BUFFERS, cmp_get_error_code((uint32_t)cmp_size)); } @@ -2419,18 +1221,17 @@ void test_compress_imagette_raw(void) uint16_t data[] = {0x0, 0x1, 0x23, 0x42, (uint16_t)INT16_MIN, INT16_MAX, UINT16_MAX}; void *output_buf = malloc(7*sizeof(uint16_t)); uint16_t cmp_data[7]; - struct cmp_cfg cfg = {0}; - int cmp_size; + struct rdcu_cfg rcfg = {0}; + int32_t cmp_size; - cfg.cmp_mode = CMP_MODE_RAW; - cfg.data_type = DATA_TYPE_IMAGETTE; - cfg.model_buf = NULL; - cfg.input_buf = data; - cfg.samples = 7; - cfg.icu_output_buf = output_buf; - cfg.buffer_length = 7; + rcfg.cmp_mode = CMP_MODE_RAW; + rcfg.model_buf = NULL; + rcfg.input_buf = data; + rcfg.samples = 7; + rcfg.icu_output_buf = output_buf; + rcfg.buffer_length = 7; - cmp_size = icu_compress_data(&cfg); + cmp_size = compress_like_rdcu(&rcfg, NULL); memcpy(cmp_data, output_buf, sizeof(cmp_data)); TEST_ASSERT_EQUAL_INT(7*16, cmp_size); TEST_ASSERT_EQUAL_HEX16(0x0, be16_to_cpu(cmp_data[0])); @@ -2443,42 +1244,36 @@ void test_compress_imagette_raw(void) /* compressed data buf = NULL test */ - memset(&cfg, 0, sizeof(struct cmp_cfg)); - cfg.data_type = DATA_TYPE_IMAGETTE; - cfg.input_buf = data; - cfg.samples = 7; - cfg.icu_output_buf = NULL; - cfg.buffer_length = 7; - cfg.max_used_bits = &MAX_USED_BITS_SAFE; + memset(&rcfg, 0, sizeof(rcfg)); + rcfg.input_buf = data; + rcfg.samples = 7; + rcfg.icu_output_buf = NULL; + rcfg.buffer_length = 7; - cmp_size = icu_compress_data(&cfg); + cmp_size = compress_like_rdcu(&rcfg, NULL); TEST_ASSERT_EQUAL_INT(7*16, cmp_size); /* error case: input_buf = NULL */ - memset(&cfg, 0, sizeof(struct cmp_cfg)); - cfg.data_type = DATA_TYPE_IMAGETTE; - cfg.input_buf = NULL; /* no data to compress */ - cfg.samples = 7; - cfg.icu_output_buf = output_buf; - cfg.buffer_length = 7; - cfg.max_used_bits = &MAX_USED_BITS_SAFE; + memset(&rcfg, 0, sizeof(rcfg)); + rcfg.input_buf = NULL; /* no data to compress */ + rcfg.samples = 7; + rcfg.icu_output_buf = output_buf; + rcfg.buffer_length = 7; - cmp_size = icu_compress_data(&cfg); + cmp_size = compress_like_rdcu(&rcfg, NULL); TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_size)); TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_BUFFERS, cmp_get_error_code((uint32_t)cmp_size)); /* error case: compressed data buffer to small */ - memset(&cfg, 0, sizeof(struct cmp_cfg)); - cfg.data_type = DATA_TYPE_IMAGETTE; - cfg.input_buf = data; - cfg.samples = 7; - cfg.icu_output_buf = output_buf; - cfg.buffer_length = 6; /* the buffer is to small */ - cfg.max_used_bits = &MAX_USED_BITS_SAFE; + memset(&rcfg, 0, sizeof(rcfg)); + rcfg.input_buf = data; + rcfg.samples = 7; + rcfg.icu_output_buf = output_buf; + rcfg.buffer_length = 6; /* the buffer is to small */ - cmp_size = icu_compress_data(&cfg); + cmp_size = compress_like_rdcu(&rcfg, NULL); TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_size)); TEST_ASSERT_EQUAL_INT(CMP_ERROR_SMALL_BUF_, cmp_get_error_code((uint32_t)cmp_size)); @@ -2494,150 +1289,69 @@ void test_compress_imagette_error_cases(void) { uint16_t data[] = {0xFFFF, 1, 0, 42, 0x8000, 0x7FFF, 0xFFFF}; uint32_t output_buf[2] = {0xFFFF, 0xFFFF}; - struct cmp_cfg cfg = {0}; - int cmp_size; - struct cmp_max_used_bits my_max_used_bits; - - cfg.data_type = DATA_TYPE_IMAGETTE; - cfg.cmp_mode = CMP_MODE_DIFF_ZERO; - cfg.input_buf = NULL; - cfg.samples = 0; /* nothing to compress */ - cfg.golomb_par = 1; - cfg.spill = 8; - cfg.icu_output_buf = NULL; - cfg.buffer_length = 0; - cfg.max_used_bits = &MAX_USED_BITS_SAFE; - - cmp_size = icu_compress_data(&cfg); + struct rdcu_cfg rcfg = {0}; + int32_t cmp_size; + + rcfg.cmp_mode = CMP_MODE_DIFF_ZERO; + rcfg.input_buf = NULL; + rcfg.samples = 0; /* nothing to compress */ + rcfg.golomb_par = 1; + rcfg.spill = 8; + rcfg.icu_output_buf = NULL; + rcfg.buffer_length = 0; + + cmp_size = compress_like_rdcu(&rcfg, NULL); TEST_ASSERT_EQUAL_INT(0, cmp_size); /* compressed data buffer to small test */ - cfg.data_type = DATA_TYPE_IMAGETTE; - cfg.cmp_mode = CMP_MODE_DIFF_ZERO; - cfg.input_buf = data; - cfg.samples = 7; - cfg.golomb_par = 1; - cfg.spill = 8; - cfg.icu_output_buf = (uint32_t *)output_buf; - cfg.buffer_length = 4; - cfg.max_used_bits = &MAX_USED_BITS_SAFE; - - cmp_size = icu_compress_data(&cfg); + rcfg.cmp_mode = CMP_MODE_DIFF_ZERO; + rcfg.input_buf = data; + rcfg.samples = 7; + rcfg.golomb_par = 1; + rcfg.spill = 8; + rcfg.icu_output_buf = (uint32_t *)output_buf; + rcfg.buffer_length = 4; + + cmp_size = compress_like_rdcu(&rcfg, NULL); TEST_ASSERT_EQUAL_INT(CMP_ERROR_SMALL_BUF, cmp_size); /* compressed data buffer to small test part 2 */ - cfg.data_type = DATA_TYPE_IMAGETTE; - cfg.cmp_mode = CMP_MODE_DIFF_ZERO; - cfg.input_buf = data; - cfg.samples = 7; - cfg.golomb_par = 1; - cfg.spill = 8; - cfg.icu_output_buf = (uint32_t *)output_buf; - cfg.buffer_length = 1; - cfg.max_used_bits = &MAX_USED_BITS_SAFE; - - cmp_size = icu_compress_data(&cfg); + rcfg.cmp_mode = CMP_MODE_DIFF_ZERO; + rcfg.input_buf = data; + rcfg.samples = 7; + rcfg.golomb_par = 1; + rcfg.spill = 8; + rcfg.icu_output_buf = (uint32_t *)output_buf; + rcfg.buffer_length = 1; + + cmp_size = compress_like_rdcu(&rcfg, NULL); TEST_ASSERT_EQUAL_INT(CMP_ERROR_SMALL_BUF, cmp_size); - /* error invalid data_type */ - cfg.data_type = DATA_TYPE_UNKNOWN; - cfg.cmp_mode = CMP_MODE_DIFF_ZERO; - cfg.input_buf = data; - cfg.samples = 7; - cfg.golomb_par = 1; - cfg.spill = 8; - cfg.icu_output_buf = (uint32_t *)output_buf; - cfg.buffer_length = 4; - cfg.max_used_bits = &MAX_USED_BITS_SAFE; - cmp_size = icu_compress_data(&cfg); - TEST_ASSERT_EQUAL_INT(-1, cmp_size); - - cfg.data_type = DATA_TYPE_F_CAM_BACKGROUND+1; - cmp_size = icu_compress_data(&cfg); - TEST_ASSERT_EQUAL_INT(-1, cmp_size); - - /* error my_max_used_bits.nc_imagette value is to high */ - my_max_used_bits = MAX_USED_BITS_SAFE; - my_max_used_bits.nc_imagette = 33; - - cfg.max_used_bits = &my_max_used_bits; - cfg.data_type = DATA_TYPE_IMAGETTE; - cfg.cmp_mode = CMP_MODE_DIFF_ZERO; - cfg.input_buf = data; - cfg.samples = 2; - cfg.golomb_par = 1; - cfg.spill = 8; - cfg.icu_output_buf = (uint32_t *)output_buf; - cfg.buffer_length = 4; - - cmp_size = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_size)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_size)); - - /* error my_max_used_bits.saturated_imagette value is to high */ - my_max_used_bits = MAX_USED_BITS_SAFE; - my_max_used_bits.saturated_imagette = 17; - - cfg.max_used_bits = &my_max_used_bits; - cfg.data_type = DATA_TYPE_SAT_IMAGETTE_ADAPTIVE; - cfg.cmp_mode = CMP_MODE_DIFF_ZERO; - cfg.input_buf = data; - cfg.samples = 2; - cfg.golomb_par = 1; - cfg.spill = 8; - cfg.icu_output_buf = (uint32_t *)output_buf; - cfg.buffer_length = 4; - - cmp_size = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_size)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_size)); - - /* error my_max_used_bits.fc_imagette value is to high */ - my_max_used_bits = MAX_USED_BITS_SAFE; - my_max_used_bits.fc_imagette = 17; - - cfg.max_used_bits = &my_max_used_bits; - cfg.data_type = DATA_TYPE_F_CAM_IMAGETTE; - cfg.cmp_mode = CMP_MODE_DIFF_ZERO; - cfg.input_buf = data; - cfg.samples = 2; - cfg.golomb_par = 1; - cfg.spill = 8; - cfg.icu_output_buf = (uint32_t *)output_buf; - cfg.buffer_length = 4; - - cmp_size = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_size)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_size)); /* test unknown cmp_mode */ - cfg.max_used_bits = &MAX_USED_BITS_SAFE; - cfg.data_type = DATA_TYPE_F_CAM_IMAGETTE; - cfg.cmp_mode = (enum cmp_mode)(MAX_CMP_MODE+1); - cfg.input_buf = data; - cfg.samples = 2; - cfg.golomb_par = 1; - cfg.spill = 8; - cfg.icu_output_buf = (uint32_t *)output_buf; - cfg.buffer_length = 4; - - cmp_size = icu_compress_data(&cfg); + rcfg.cmp_mode = (enum cmp_mode)(MAX_CMP_MODE+1); + rcfg.input_buf = data; + rcfg.samples = 2; + rcfg.golomb_par = 1; + rcfg.spill = 8; + rcfg.icu_output_buf = (uint32_t *)output_buf; + rcfg.buffer_length = 4; + + cmp_size = compress_like_rdcu(&rcfg, NULL); TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_size)); TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_GENERIC, cmp_get_error_code((uint32_t)cmp_size)); /* test golomb_par = 0 */ - cfg.max_used_bits = &MAX_USED_BITS_SAFE; - cfg.data_type = DATA_TYPE_F_CAM_IMAGETTE; - cfg.cmp_mode = CMP_MODE_DIFF_ZERO; - cfg.input_buf = data; - cfg.samples = 2; - cfg.golomb_par = 0; - cfg.spill = 8; - cfg.icu_output_buf = (uint32_t *)output_buf; - cfg.buffer_length = 4; - - cmp_size = icu_compress_data(&cfg); + rcfg.cmp_mode = CMP_MODE_DIFF_ZERO; + rcfg.input_buf = data; + rcfg.samples = 2; + rcfg.golomb_par = 0; + rcfg.spill = 8; + rcfg.icu_output_buf = (uint32_t *)output_buf; + rcfg.buffer_length = 4; + + cmp_size = compress_like_rdcu(&rcfg, NULL); TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_size)); TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_SPECIFIC, cmp_get_error_code((uint32_t)cmp_size)); } @@ -2727,1531 +1441,6 @@ void no_test_compress_multi_entry_hdr(void) #endif -void test_compress_s_fx_raw(void) -{ - struct s_fx data[7]; - struct cmp_cfg cfg = {0}; - int cmp_size, cmp_size_exp; - size_t i; - struct collection_hdr *hdr; - - cfg.data_type = DATA_TYPE_S_FX; - cfg.model_buf = NULL; - cfg.samples = 7; - cfg.input_buf = malloc(cmp_cal_size_of_data(cfg.samples, cfg.data_type)); - cfg.buffer_length = 7; - cfg.icu_output_buf = malloc(cmp_cal_size_of_data(cfg.buffer_length, cfg.data_type)); - TEST_ASSERT_NOT_NULL(cfg.icu_output_buf); - TEST_ASSERT_NOT_NULL(cfg.input_buf); - - data[0].exp_flags = 0x0; - data[0].fx = 0x0; - data[1].exp_flags = 0x1; - data[1].fx = 0x1; - data[2].exp_flags = 0x2; - data[2].fx = 0x23; - data[3].exp_flags = 0x3; - data[3].fx = 0x42; - data[4].exp_flags = 0x0; - data[4].fx = (uint32_t)INT32_MIN; - data[5].exp_flags = 0x3; - data[5].fx = INT32_MAX; - data[6].exp_flags = 0x1; - data[6].fx = UINT32_MAX; - - hdr = cfg.input_buf; - memset(hdr, 0x42, sizeof(struct collection_hdr)); - memcpy(hdr->entry, data, sizeof(data)); - - cmp_size = icu_compress_data(&cfg); - - cmp_size_exp = (sizeof(data) + sizeof(struct collection_hdr)) * CHAR_BIT; - TEST_ASSERT_EQUAL_INT(cmp_size_exp, cmp_size); - - for (i = 0; i < ARRAY_SIZE(data); i++) { - struct s_fx *p; - - hdr = (struct collection_hdr *)cfg.icu_output_buf; - p = (struct s_fx *)hdr->entry; - - TEST_ASSERT_EQUAL_HEX(data[i].exp_flags, p[i].exp_flags); - TEST_ASSERT_EQUAL_HEX(data[i].fx, cpu_to_be32(p[i].fx)); - } - - free(cfg.input_buf); - free(cfg.icu_output_buf); -} - - -void test_compress_s_fx_model_multi(void) -{ - struct s_fx data[6], model[6]; - struct s_fx *up_model_buf; - struct cmp_cfg cfg = {0}; - int cmp_size; - struct collection_hdr *hdr; - uint32_t *cmp_data; - struct cmp_max_used_bits my_max_used_bits; - - /* setup configuration */ - cfg.data_type = DATA_TYPE_S_FX; - cfg.cmp_mode = CMP_MODE_MODEL_MULTI; - cfg.model_value = 11; - cfg.samples = 6; - cfg.input_buf = malloc(cmp_cal_size_of_data(cfg.samples, cfg.data_type)); - TEST_ASSERT_NOT_NULL(cfg.input_buf); - cfg.model_buf = malloc(cmp_cal_size_of_data(cfg.samples, cfg.data_type)); - TEST_ASSERT_NOT_NULL(cfg.model_buf); - cfg.icu_new_model_buf = malloc(cmp_cal_size_of_data(cfg.samples, cfg.data_type)); - TEST_ASSERT_NOT_NULL(cfg.icu_new_model_buf); - cfg.buffer_length = 6; - cfg.icu_output_buf = malloc(cmp_cal_size_of_data(cfg.buffer_length, cfg.data_type)); - TEST_ASSERT_NOT_NULL(cfg.icu_output_buf); - cfg.cmp_par_exp_flags = 1; - cfg.spill_exp_flags = 8; - cfg.cmp_par_fx = 3; - cfg.spill_fx = 35; - - - /* generate input data */ - hdr = cfg.input_buf; - /* use dummy data for the header */ - memset(hdr, 0x42, sizeof(struct collection_hdr)); - data[0].exp_flags = 0x0; - data[0].fx = 0x0; - data[1].exp_flags = 0x1; - data[1].fx = 0x1; - data[2].exp_flags = 0x2; - data[2].fx = 0x23; - data[3].exp_flags = 0x3; - data[3].fx = 0x42; - data[4].exp_flags = 0x0; - data[4].fx = 0x001FFFFF; - data[5].exp_flags = 0x0; - data[5].fx = 0x0; - memcpy(hdr->entry, data, sizeof(data)); - - /* generate model data */ - hdr = cfg.model_buf; - /* use dummy data for the header */ - memset(hdr, 0x41, sizeof(struct collection_hdr)); - model[0].exp_flags = 0x0; - model[0].fx = 0x0; - model[1].exp_flags = 0x3; - model[1].fx = 0x1; - model[2].exp_flags = 0x0; - model[2].fx = 0x42; - model[3].exp_flags = 0x0; - model[3].fx = 0x23; - model[4].exp_flags = 0x3; - model[4].fx = 0x0; - model[5].exp_flags = 0x2; - model[5].fx = 0x001FFFFF; - memcpy(hdr->entry, model, sizeof(model)); - - my_max_used_bits = MAX_USED_BITS_SAFE; - my_max_used_bits.s_exp_flags = 2; - my_max_used_bits.s_fx = 21; - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - - cmp_size = icu_compress_data(&cfg); - - TEST_ASSERT_EQUAL_INT(166, cmp_size); - TEST_ASSERT_FALSE(memcmp(cfg.input_buf, cfg.icu_output_buf, COLLECTION_HDR_SIZE)); - cmp_data = &cfg.icu_output_buf[COLLECTION_HDR_SIZE/sizeof(uint32_t)]; - TEST_ASSERT_EQUAL_HEX(0x1C77FFA6, be32_to_cpu(cmp_data[0])); - TEST_ASSERT_EQUAL_HEX(0xAFFF4DE5, be32_to_cpu(cmp_data[1])); - TEST_ASSERT_EQUAL_HEX(0xCC000000, be32_to_cpu(cmp_data[2])); - - hdr = cfg.icu_new_model_buf; - up_model_buf = (struct s_fx *)hdr->entry; - TEST_ASSERT_FALSE(memcmp(hdr, cfg.icu_output_buf, COLLECTION_HDR_SIZE)); - TEST_ASSERT_EQUAL_HEX(0x0, up_model_buf[0].exp_flags); - TEST_ASSERT_EQUAL_HEX(0x0, up_model_buf[0].fx); - TEST_ASSERT_EQUAL_HEX(0x2, up_model_buf[1].exp_flags); - TEST_ASSERT_EQUAL_HEX(0x1, up_model_buf[1].fx); - TEST_ASSERT_EQUAL_HEX(0x0, up_model_buf[2].exp_flags); - TEST_ASSERT_EQUAL_HEX(0x38, up_model_buf[2].fx); - TEST_ASSERT_EQUAL_HEX(0x0, up_model_buf[3].exp_flags); - TEST_ASSERT_EQUAL_HEX(0x2C, up_model_buf[3].fx); - TEST_ASSERT_EQUAL_HEX(0x2, up_model_buf[4].exp_flags); - TEST_ASSERT_EQUAL_HEX(0x9FFFF, up_model_buf[4].fx); - TEST_ASSERT_EQUAL_HEX(0x1, up_model_buf[5].exp_flags); - TEST_ASSERT_EQUAL_HEX(0x15FFFF, up_model_buf[5].fx); - - free(cfg.input_buf); - free(cfg.model_buf); - free(cfg.icu_new_model_buf); - free(cfg.icu_output_buf); -} - - -/** - * @test compress_s_fx - */ - -void test_compress_s_fx_error_cases(void) -{ - int error, cmp_bits; - uint32_t compressed_data_size; - struct cmp_cfg cfg = {0}; - uint32_t cmp_par_exp_flags = MAX_NON_IMA_GOLOMB_PAR; - uint32_t spillover_exp_flags = 6; - uint32_t cmp_par_fx = 2; - uint32_t spillover_fx = 8; - uint8_t data_to_compress[COLLECTION_HDR_SIZE+3*sizeof(struct s_fx)] = {0}; - uint32_t cmp_buf_size = COLLECTION_HDR_SIZE+1*sizeof(struct s_fx); - uint32_t *compressed_data = calloc(1, cmp_buf_size); - struct cmp_max_used_bits my_max_used_bits = MAX_USED_BITS_SAFE; - struct s_fx *data_p = (struct s_fx *)&data_to_compress[COLLECTION_HDR_SIZE]; - - 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, compressed_data, 1); - TEST_ASSERT_EQUAL_INT(cmp_buf_size, compressed_data_size); - - my_max_used_bits.s_exp_flags = 2; - my_max_used_bits.s_fx = 21; - error = cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - TEST_ASSERT_FALSE(error); - - /* test if data are higher than max used bits value */ - data_p[0].fx = 0x200000; /* has more than 21 bits (my_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 */ - my_max_used_bits.s_exp_flags = 8; - my_max_used_bits.s_fx = 32; - error = cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - TEST_ASSERT_FALSE(error); - 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); - - my_max_used_bits.s_exp_flags = 33; /* more than 32 bits are not allowed */ - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - my_max_used_bits.s_exp_flags = 32; - my_max_used_bits.s_fx = 33; /* more than 32 bits are not allowed */ - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - free(compressed_data); -} - - -/** - * @test compress_s_fx_efx - */ - -void test_compress_s_fx_efx_error_cases(void) -{ - int error, cmp_bits; - uint32_t 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_NON_IMA_GOLOMB_PAR; - uint32_t spillover_efx = cmp_icu_max_spill(MAX_NON_IMA_GOLOMB_PAR); - uint8_t data_to_compress[COLLECTION_HDR_SIZE+2*sizeof(struct s_fx_efx)] = {0}; - uint32_t cmp_buf_size = COLLECTION_HDR_SIZE+1*sizeof(struct s_fx_efx); - uint32_t *compressed_data = calloc(1, cmp_buf_size); - struct cmp_max_used_bits my_max_used_bits = MAX_USED_BITS_SAFE; - struct s_fx_efx *data_p = (struct s_fx_efx *)&data_to_compress[COLLECTION_HDR_SIZE]; - - 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, compressed_data, 1); - TEST_ASSERT_EQUAL_INT(cmp_buf_size, compressed_data_size); - - my_max_used_bits.s_exp_flags = 2; - my_max_used_bits.s_fx = 21; - my_max_used_bits.s_efx = 16; - error = cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - TEST_ASSERT_FALSE(error); - - /* test if data are higher than max used bits value */ - data_p[0].exp_flags = 0x4; /* has more than 2 bits (my_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 (my_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 (my_max_used_bits.efx) */ - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); - - /* error case exp_flag */ - my_max_used_bits.s_exp_flags = 33; - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - /* error case fx */ - my_max_used_bits.s_exp_flags = 2; - my_max_used_bits.s_fx = 33; - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - /* error case efx */ - my_max_used_bits.s_fx = 21; - my_max_used_bits.s_efx = 33; - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - free(compressed_data); -} - - -/** - * @test compress_s_fx_ncob - */ - -void test_compress_s_fx_ncob_error_cases(void) -{ - int error, cmp_bits; - uint32_t 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_NON_IMA_GOLOMB_PAR; - uint32_t spillover_ncob = cmp_icu_max_spill(MAX_NON_IMA_GOLOMB_PAR); - uint8_t data_to_compress[COLLECTION_HDR_SIZE+3*sizeof(struct s_fx_ncob)] = {0}; - uint8_t model_data[COLLECTION_HDR_SIZE+3*sizeof(struct s_fx_ncob)] = {0}; - uint32_t cmp_buf_size = COLLECTION_HDR_SIZE+1*sizeof(struct s_fx_ncob); - uint32_t *compressed_data = calloc(1, cmp_buf_size); - struct cmp_max_used_bits my_max_used_bits = MAX_USED_BITS_SAFE; - struct s_fx_ncob *data_p = (struct s_fx_ncob *)&data_to_compress[COLLECTION_HDR_SIZE]; - - - my_max_used_bits.s_exp_flags = 2; - my_max_used_bits.s_fx = 21; - my_max_used_bits.s_ncob = 31; - - 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); - - error = cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - TEST_ASSERT_FALSE(error); - - compressed_data_size = cmp_cfg_icu_buffers(&cfg, data_to_compress, 3, model_data, - NULL, compressed_data, 1); - TEST_ASSERT_EQUAL_INT(cmp_buf_size, 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 (my_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 */ - my_max_used_bits.s_exp_flags = 33; - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - - /* error case fx */ - my_max_used_bits.s_exp_flags = 2; - my_max_used_bits.s_fx = 33; - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - /* error case efx */ - my_max_used_bits.s_fx = 21; - my_max_used_bits.s_ncob = 33; - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - free(compressed_data); -} - - -/** - * @test compress_s_fx_efx_ncob_ecob - */ - -void test_compress_s_fx_efx_ncob_ecob_error_cases(void) -{ - int error, cmp_bits; - uint32_t 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_NON_IMA_GOLOMB_PAR; - uint32_t spillover_ncob = cmp_icu_max_spill(MAX_NON_IMA_GOLOMB_PAR); - uint32_t cmp_par_efx = MAX_NON_IMA_GOLOMB_PAR; - uint32_t spillover_efx = cmp_icu_max_spill(MAX_NON_IMA_GOLOMB_PAR); - uint32_t cmp_par_ecob = 23; - uint32_t spillover_ecob = cmp_icu_max_spill(23); - uint8_t data_to_compress[COLLECTION_HDR_SIZE+3*sizeof(struct s_fx_efx_ncob_ecob)] = {0}; - uint8_t model_data[COLLECTION_HDR_SIZE+3*sizeof(struct s_fx_efx_ncob_ecob)] = {0}; - uint32_t cmp_buf_size = COLLECTION_HDR_SIZE+1*sizeof(struct s_fx_efx_ncob_ecob); - uint32_t *compressed_data = calloc(1, cmp_buf_size); - struct cmp_max_used_bits my_max_used_bits = MAX_USED_BITS_SAFE; - struct s_fx_efx_ncob_ecob *data_p = (struct s_fx_efx_ncob_ecob *)&data_to_compress[COLLECTION_HDR_SIZE]; - - - 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, compressed_data, 1); - TEST_ASSERT_EQUAL_INT(cmp_buf_size, compressed_data_size); - - my_max_used_bits.s_exp_flags = 2; - my_max_used_bits.s_fx = 21; - my_max_used_bits.s_ncob = 31; - my_max_used_bits.s_efx = 23; - my_max_used_bits.s_ecob = 7; - error = cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - TEST_ASSERT_FALSE(error); - - /* 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 */ - my_max_used_bits.s_exp_flags = 33; - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - /* error case fx */ - my_max_used_bits.s_exp_flags = 32; - my_max_used_bits.s_fx = 33; - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - /* error case efx */ - my_max_used_bits.s_fx = 32; - my_max_used_bits.s_ncob = 33; - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - my_max_used_bits.s_ncob = 32; - my_max_used_bits.s_efx = 33; - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - my_max_used_bits.s_efx = 32; - my_max_used_bits.s_ecob = 33; - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - free(compressed_data); -} - - -/** - * @test compress_f_fx - */ - -void test_compress_f_fx_error_cases(void) -{ - int error, cmp_bits; - uint32_t compressed_data_size; - struct cmp_cfg cfg = {0}; - uint32_t cmp_par_fx = MAX_NON_IMA_GOLOMB_PAR; - uint32_t spillover_fx = 8; - uint8_t data_to_compress[COLLECTION_HDR_SIZE+3*sizeof(struct f_fx)] = {0}; - uint32_t cmp_buf_size = COLLECTION_HDR_SIZE+1*sizeof(struct f_fx); - uint32_t *compressed_data = calloc(1, cmp_buf_size); - struct cmp_max_used_bits my_max_used_bits = MAX_USED_BITS_SAFE; - - my_max_used_bits.f_fx = 23; - cmp_cfg_icu_max_used_bits(&cfg, &my_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, compressed_data, 1); - TEST_ASSERT_EQUAL_INT(cmp_buf_size, 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); - - my_max_used_bits.f_fx = 33; /* more than 32 bits are not allowed */ - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - free(compressed_data); -} - - -/** - * @test compress_f_fx_efx - */ - -void test_compress_f_fx_efx_error_cases(void) -{ - int error, cmp_bits; - uint32_t 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[COLLECTION_HDR_SIZE+2*sizeof(struct f_fx_efx)] = {0}; - uint32_t cmp_buf_size = COLLECTION_HDR_SIZE+1*sizeof(struct f_fx_efx); - uint32_t *compressed_data = calloc(1, cmp_buf_size); - struct cmp_max_used_bits my_max_used_bits = MAX_USED_BITS_SAFE; - struct f_fx_efx *data_p = (struct f_fx_efx *)&data_to_compress[COLLECTION_HDR_SIZE]; - - my_max_used_bits.f_fx = 23; - my_max_used_bits.f_efx = 31; - cmp_cfg_icu_max_used_bits(&cfg, &my_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, - compressed_data, 1); - TEST_ASSERT_EQUAL_INT(cmp_buf_size, 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); - - /* fx value is to big for the max used bits values */ - data_p[0].fx = 0x800000; - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); - data_p[0].fx = 0x7FFFFF; - - /* efx value is to big for the max used bits values */ - data_p[0].efx = 0x80000000; - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_HIGH_VALUE, cmp_bits); - data_p[0].efx = 0x7FFFFFFF; - - my_max_used_bits.f_fx = 33; /* more than 32 bits are not allowed */ - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - my_max_used_bits.f_fx = 32; - my_max_used_bits.f_efx = 33; /* more than 32 bits are not allowed */ - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - free(compressed_data); -} - - -/** - * @test compress_f_fx_ncob - */ - -void test_compress_f_fx_ncob_error_cases(void) -{ - int error, cmp_bits; - uint32_t compressed_data_size; - struct cmp_cfg cfg = {0}; - uint32_t cmp_par_fx = MAX_NON_IMA_GOLOMB_PAR; - uint32_t spillover_fx = 8; - uint32_t cmp_par_ncob = 1; - uint32_t spillover_ncob = 8; - uint8_t data_to_compress[COLLECTION_HDR_SIZE+2*sizeof(struct f_fx_ncob)] = {0}; - uint32_t cmp_buf_size = COLLECTION_HDR_SIZE+1*sizeof(struct f_fx_ncob); - uint32_t *compressed_data = calloc(1, cmp_buf_size); - struct cmp_max_used_bits my_max_used_bits = MAX_USED_BITS_SAFE; - struct f_fx_ncob *data_p = (struct f_fx_ncob *)&data_to_compress[COLLECTION_HDR_SIZE]; - - my_max_used_bits.f_fx = 31; - my_max_used_bits.f_ncob = 23; - cmp_cfg_icu_max_used_bits(&cfg, &my_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, - compressed_data, 1); - TEST_ASSERT_EQUAL_INT(cmp_buf_size, 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_cfg_icu_max_used_bits(&cfg, &my_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_cfg_icu_max_used_bits(&cfg, &my_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; - - my_max_used_bits.f_fx = 33; /* more than 32 bits are not allowed */ - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - my_max_used_bits.f_fx = 32; - my_max_used_bits.f_ncob = 33; /* more than 32 bits are not allowed */ - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - free(compressed_data); -} - - -/** - * @test compress_f_fx_efx_ncob_ecob - */ - -void test_compress_f_fx_efx_ncob_ecob(void) -{ - int error, cmp_bits; - uint32_t 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[COLLECTION_HDR_SIZE+4*sizeof(struct f_fx_efx_ncob_ecob)] = {0}; - uint32_t cmp_buf_size = COLLECTION_HDR_SIZE+1*sizeof(struct f_fx_efx_ncob_ecob); - uint32_t *compressed_data = calloc(1, cmp_buf_size); - struct cmp_max_used_bits my_max_used_bits = MAX_USED_BITS_SAFE; - struct f_fx_efx_ncob_ecob *data_p = (struct f_fx_efx_ncob_ecob *)&data_to_compress[COLLECTION_HDR_SIZE]; - - 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, - compressed_data, 1); - TEST_ASSERT_EQUAL_INT(cmp_buf_size, compressed_data_size); - - my_max_used_bits.f_fx = 31; - my_max_used_bits.f_ncob = 3; - my_max_used_bits.f_efx = 16; - my_max_used_bits.f_ecob = 8; - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - - /* 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; - - my_max_used_bits.f_fx = 33; /* more than 32 bits are not allowed */ - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - my_max_used_bits.f_fx = 32; - my_max_used_bits.f_ncob = 33; /* more than 32 bits are not allowed */ - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - my_max_used_bits.f_ncob = 32; - my_max_used_bits.f_efx = 33; /* more than 32 bits are not allowed */ - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - my_max_used_bits.f_efx = 32; - my_max_used_bits.f_ecob = 33; /* more than 32 bits are not allowed */ - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - free(compressed_data); -} - - -/** - * @test compress_l_fx - */ - -void test_compress_l_fx_error_cases(void) -{ - int error, cmp_bits; - uint32_t 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[COLLECTION_HDR_SIZE+3*sizeof(struct l_fx)] = {0}; - uint32_t cmp_buf_size = COLLECTION_HDR_SIZE+1*sizeof(struct l_fx); - uint32_t *compressed_data = calloc(1, cmp_buf_size); - struct cmp_max_used_bits my_max_used_bits = MAX_USED_BITS_SAFE; - struct l_fx *data_p = (struct l_fx *)&data_to_compress[COLLECTION_HDR_SIZE]; - - 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, - compressed_data, 1); - TEST_ASSERT_EQUAL_INT(cmp_buf_size, compressed_data_size); - - my_max_used_bits.l_exp_flags = 23; - my_max_used_bits.l_fx = 31; - my_max_used_bits.l_efx = 1; - my_max_used_bits.l_fx_variance = 23; - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - - /* 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; - - my_max_used_bits.l_exp_flags = 33; /* more than 32 bits are not allowed */ - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - my_max_used_bits.l_exp_flags = 32; - my_max_used_bits.l_fx = 33; /* more than 32 bits are not allowed */ - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - my_max_used_bits.l_fx = 32; - my_max_used_bits.l_fx_variance = 33; /* more than 32 bits are not allowed */ - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - free(compressed_data); -} - - -/** - * @test compress_l_fx_efx - */ - -void test_compress_l_fx_efx_error_cases(void) -{ - int error, cmp_bits; - uint32_t compressed_data_size; - struct cmp_cfg cfg = {0}; - uint32_t cmp_par_exp_flags = MAX_NON_IMA_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[COLLECTION_HDR_SIZE+3*sizeof(struct l_fx_efx)] = {0}; - uint32_t cmp_buf_size = COLLECTION_HDR_SIZE+1*sizeof(struct l_fx_efx); - uint32_t *compressed_data = calloc(1, cmp_buf_size); - struct cmp_max_used_bits my_max_used_bits = MAX_USED_BITS_SAFE; - struct l_fx_efx *data_p = (struct l_fx_efx *)&data_to_compress[COLLECTION_HDR_SIZE]; - - 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, - compressed_data, 1); - TEST_ASSERT_EQUAL_INT(cmp_buf_size, compressed_data_size); - - my_max_used_bits.l_exp_flags = 23; - my_max_used_bits.l_fx = 31; - my_max_used_bits.l_efx = 1; - my_max_used_bits.l_fx_variance = 23; - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - - /* 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; - - my_max_used_bits.l_exp_flags = 33; /* more than 32 bits are not allowed */ - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - my_max_used_bits.l_exp_flags = 32; - my_max_used_bits.l_fx = 33; /* more than 32 bits are not allowed */ - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - my_max_used_bits.l_fx = 32; - my_max_used_bits.l_efx = 33; /* more than 32 bits are not allowed */ - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - my_max_used_bits.l_efx = 32; - my_max_used_bits.l_fx_variance = 33; /* more than 32 bits are not allowed */ - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - free(compressed_data); -} - - -/** - * @test compress_l_fx_ncob - */ - -void test_compress_l_fx_ncob_error_cases(void) -{ - int error, cmp_bits; - uint32_t compressed_data_size; - struct cmp_cfg cfg = {0}; - uint32_t cmp_par_exp_flags = MAX_NON_IMA_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[COLLECTION_HDR_SIZE+3*sizeof(struct l_fx_ncob)] = {0}; - uint32_t cmp_buf_size = COLLECTION_HDR_SIZE+1*sizeof(struct l_fx_ncob); - uint32_t *compressed_data = calloc(1, cmp_buf_size); - struct cmp_max_used_bits my_max_used_bits = MAX_USED_BITS_SAFE; - struct l_fx_ncob *data_p = (struct l_fx_ncob *)&data_to_compress[COLLECTION_HDR_SIZE]; - - 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, - compressed_data, 1); - TEST_ASSERT_EQUAL_INT(cmp_buf_size, compressed_data_size); - - my_max_used_bits.l_exp_flags = 23; - my_max_used_bits.l_fx = 31; - my_max_used_bits.l_ncob = 2; - my_max_used_bits.l_fx_variance = 23; - my_max_used_bits.l_cob_variance = 11; - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - - /* 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; - - my_max_used_bits.l_exp_flags = 33; /* more than 32 bits are not allowed */ - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - my_max_used_bits.l_exp_flags = 32; - my_max_used_bits.l_fx = 33; /* more than 32 bits are not allowed */ - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - my_max_used_bits.l_fx = 32; - my_max_used_bits.l_ncob = 33; /* more than 32 bits are not allowed */ - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - my_max_used_bits.l_ncob = 32; - my_max_used_bits.l_fx_variance = 33; /* more than 32 bits are not allowed */ - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - my_max_used_bits.l_fx_variance = 32; - my_max_used_bits.l_cob_variance = 33; /* more than 32 bits are not allowed */ - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - free(compressed_data); -} - - -/** - * @test compress_l_fx_efx_ncob_ecob - */ - -void test_compress_l_fx_efx_ncob_ecob_error_cases(void) -{ - int error, cmp_bits; - uint32_t compressed_data_size; - struct cmp_cfg cfg = {0}; - uint32_t cmp_par_exp_flags = MAX_NON_IMA_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[COLLECTION_HDR_SIZE+3*sizeof(struct l_fx_efx_ncob_ecob)] = {0}; - uint32_t cmp_buf_size = COLLECTION_HDR_SIZE+1*sizeof(struct l_fx_efx_ncob_ecob); - uint32_t *compressed_data = calloc(1, cmp_buf_size); - struct cmp_max_used_bits my_max_used_bits = MAX_USED_BITS_SAFE; - struct l_fx_efx_ncob_ecob *data_p = (struct l_fx_efx_ncob_ecob *)&data_to_compress[COLLECTION_HDR_SIZE]; - - 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, - compressed_data, 1); - TEST_ASSERT_EQUAL_INT(cmp_buf_size, compressed_data_size); - - my_max_used_bits.l_exp_flags = 23; - my_max_used_bits.l_fx = 31; - my_max_used_bits.l_ncob = 2; - my_max_used_bits.l_efx = 1; - my_max_used_bits.l_ecob = 3; - my_max_used_bits.l_fx_variance = 23; - my_max_used_bits.l_cob_variance = 11; - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - - /* 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; - - my_max_used_bits.l_exp_flags = 33; /* more than 32 bits are not allowed */ - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - my_max_used_bits.l_exp_flags = 32; - my_max_used_bits.l_fx = 33; /* more than 32 bits are not allowed */ - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - my_max_used_bits.l_fx = 32; - my_max_used_bits.l_ncob = 33; /* more than 32 bits are not allowed */ - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - my_max_used_bits.l_ncob = 32; - my_max_used_bits.l_efx = 33; /* more than 32 bits are not allowed */ - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - my_max_used_bits.l_efx = 32; - my_max_used_bits.l_ecob = 33; /* more than 32 bits are not allowed */ - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - my_max_used_bits.l_ecob = 32; - my_max_used_bits.l_fx_variance = 33; /* more than 32 bits are not allowed */ - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - my_max_used_bits.l_fx_variance = 32; - my_max_used_bits.l_cob_variance = 33; /* more than 32 bits are not allowed */ - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - free(compressed_data); -} - - -/** - * @test compress_offset - */ - -void test_compress_offset_error_cases(void) -{ - int error, cmp_bits; - uint32_t 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_NON_IMA_GOLOMB_PAR; - uint32_t spillover_variance = cmp_icu_max_spill(MAX_NON_IMA_GOLOMB_PAR); - uint8_t data_to_compress[COLLECTION_HDR_SIZE+3*sizeof(struct offset)] = {0}; - uint32_t cmp_buf_size = COLLECTION_HDR_SIZE+1*sizeof(struct offset); - uint32_t *compressed_data = calloc(1, cmp_buf_size); - struct cmp_max_used_bits my_max_used_bits = MAX_USED_BITS_SAFE; - struct offset *data_p = (struct offset *)&data_to_compress[COLLECTION_HDR_SIZE]; - - 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, - compressed_data, 1); - TEST_ASSERT_EQUAL_INT(cmp_buf_size, compressed_data_size); - - my_max_used_bits.nc_offset_mean = 1; - my_max_used_bits.nc_offset_variance = 31; - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - - /* 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; - - my_max_used_bits.nc_offset_mean = 33; /* more than 32 bits are not allowed */ - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - my_max_used_bits.nc_offset_mean = 32; - my_max_used_bits.nc_offset_variance = 33; /* more than 32 bits are not allowed */ - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - - cfg.data_type = DATA_TYPE_F_CAM_OFFSET; - my_max_used_bits.fc_offset_mean = 33; /* more than 32 bits are not allowed */ - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - my_max_used_bits.fc_offset_mean = 32; - my_max_used_bits.fc_offset_variance = 33; /* more than 32 bits are not allowed */ - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - free(compressed_data); -} - - -/** - * @test compress_background - */ - -void test_compress_background_error_cases(void) -{ - int error, cmp_bits; - uint32_t 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_NON_IMA_GOLOMB_PAR; - uint32_t spillover_variance = cmp_icu_max_spill(MAX_NON_IMA_GOLOMB_PAR); - uint32_t cmp_par_pixels_error = 23; - uint32_t spillover_pixels_error = 42; - uint8_t data_to_compress[COLLECTION_HDR_SIZE+3*sizeof(struct background)] = {0}; - uint32_t cmp_buf_size = COLLECTION_HDR_SIZE+1*sizeof(struct background); - uint32_t *compressed_data = calloc(1, cmp_buf_size); - struct cmp_max_used_bits my_max_used_bits = MAX_USED_BITS_SAFE; - struct background *data_p = (struct background *)&data_to_compress[COLLECTION_HDR_SIZE]; - - 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, - compressed_data, 1); - TEST_ASSERT_EQUAL_INT(cmp_buf_size, compressed_data_size); - - my_max_used_bits.nc_background_mean = 1; - my_max_used_bits.nc_background_variance = 31; - my_max_used_bits.nc_background_outlier_pixels = 2; - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - - /* 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; - - my_max_used_bits.nc_background_mean = 33; /* more than 32 bits are not allowed */ - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - my_max_used_bits.nc_background_mean = 32; - my_max_used_bits.nc_background_variance = 33; /* more than 32 bits are not allowed */ - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - my_max_used_bits.nc_background_variance = 32; - my_max_used_bits.nc_background_outlier_pixels = 33; /* more than 32 bits are not allowed */ - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - - cfg.data_type = DATA_TYPE_F_CAM_BACKGROUND; - my_max_used_bits.fc_background_mean = 33; /* more than 32 bits are not allowed */ - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - my_max_used_bits.fc_background_mean = 32; - my_max_used_bits.fc_background_variance = 33; /* more than 32 bits are not allowed */ - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - my_max_used_bits.fc_background_variance = 32; - my_max_used_bits.fc_background_outlier_pixels = 33; /* more than 32 bits are not allowed */ - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - free(compressed_data); -} - - -/** - * @test compress_smearing - */ - -void test_compress_smearing_error_cases(void) -{ - int error, cmp_bits; - uint32_t 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_NON_IMA_GOLOMB_PAR; - uint32_t spillover_variance = cmp_icu_max_spill(MAX_NON_IMA_GOLOMB_PAR); - uint32_t cmp_par_pixels_error = 23; - uint32_t spillover_pixels_error = 42; - uint8_t data_to_compress[COLLECTION_HDR_SIZE+3*sizeof(struct smearing)] = {0}; - uint32_t cmp_buf_size = COLLECTION_HDR_SIZE+1*sizeof(struct smearing); - uint32_t *compressed_data = calloc(1, cmp_buf_size); - struct cmp_max_used_bits my_max_used_bits = MAX_USED_BITS_SAFE; - struct smearing *data_p = (struct smearing *)&data_to_compress[COLLECTION_HDR_SIZE]; - - 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, - compressed_data, 1); - TEST_ASSERT_EQUAL_INT(cmp_buf_size, compressed_data_size); - - my_max_used_bits.smearing_mean = 1; - my_max_used_bits.smearing_variance_mean = 15; - my_max_used_bits.smearing_outlier_pixels = 2; - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - - /* 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; - - my_max_used_bits.smearing_mean = 33; /* more than 32 bits are not allowed */ - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - my_max_used_bits.smearing_mean = 32; - my_max_used_bits.smearing_variance_mean = 33; /* more than 32 bits are not allowed */ - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - my_max_used_bits.smearing_variance_mean = 32; - my_max_used_bits.smearing_outlier_pixels = 33; /* more than 32 bits are not allowed */ - cmp_cfg_icu_max_used_bits(&cfg, &my_max_used_bits); - cmp_bits = icu_compress_data(&cfg); - TEST_ASSERT_TRUE(cmp_is_error((uint32_t)cmp_bits)); - TEST_ASSERT_EQUAL_INT(CMP_ERROR_PAR_MAX_USED_BITS, cmp_get_error_code((uint32_t)cmp_bits)); - - free(compressed_data); -} - - /** * @test pad_bitstream */ @@ -4754,21 +1943,21 @@ void nootest_collection_zero_data_length_2(void) #endif /** - * @test icu_compress_data + * @test compress_like_rdcu */ -void test_icu_compress_data_error_cases(void) +void test_compress_like_rdcu_error_cases(void) { - int cmp_size; - struct cmp_cfg cfg = {0}; + int32_t cmp_size; + struct rdcu_cfg rcfg = {0}; /* cfg = NULL test */ - cmp_size = icu_compress_data(NULL); + cmp_size = compress_like_rdcu(NULL, NULL); TEST_ASSERT_EQUAL(-1, cmp_size); /* samples = 0 test */ - cfg.samples = 0; - cmp_size = icu_compress_data(&cfg); + rcfg.samples = 0; + cmp_size = compress_like_rdcu(&rcfg, NULL); TEST_ASSERT_EQUAL(0, cmp_size); } @@ -5000,7 +2189,10 @@ void test_compress_chunk_set_model_id_and_counter(void) void test_support_function_call_NULL(void) { - struct cmp_cfg cfg = cmp_cfg_icu_create(DATA_TYPE_IMAGETTE, CMP_MODE_DIFF_ZERO, 16, CMP_LOSSLESS); + struct cmp_cfg cfg = {0}; + + cfg.data_type = DATA_TYPE_IMAGETTE; + cfg.cmp_mode = CMP_MODE_DIFF_ZERO; TEST_ASSERT_TRUE(cmp_cfg_gen_par_is_invalid(NULL, ICU_CHECK)); TEST_ASSERT_TRUE(cmp_cfg_gen_par_is_invalid(&cfg, RDCU_CHECK+1)); -- GitLab