Skip to content

Commit

Permalink
Test: Errors: Test for copying invalid binary value parent in schema
Browse files Browse the repository at this point in the history
The parent of the binary type must be mapping.
  • Loading branch information
tlsa committed Jul 20, 2024
1 parent 2b69dff commit a15b55a
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions test/units/errs.c
Original file line number Diff line number Diff line change
Expand Up @@ -3423,6 +3423,68 @@ static bool test_err_copy_schema_required_mapping_missing(
return ttest_pass(&tc);
}

/**
* Test copying with schema with a data type without mapping parent.
*
* \param[in] report The test report context.
* \param[in] config The CYAML config to use for the test.
* \return true if test passes, false otherwise.
*/
static bool test_err_copy_schema_required_mapping_missing2(
ttest_report_ctx_t *report,
const cyaml_config_t *config)
{
static int values[] = { 10, 20 };
static const struct target_struct {
int *value;
unsigned value_count;
} val = {
.value = values,
.value_count = CYAML_ARRAY_LEN(values),
};
static const struct cyaml_schema_value entry_schema = {
.type = CYAML_BINARY,
.flags = CYAML_FLAG_POINTER,
.data_size = 8,
.binary = {
.min = 0,
.max = CYAML_UNLIMITED,
.validation_cb = NULL,
.missing = NULL,
.missing_len = 0,
},
};
static const struct cyaml_schema_value top_schema = {
CYAML_VALUE_SEQUENCE(CYAML_FLAG_POINTER, int,
&entry_schema, 0, CYAML_UNLIMITED),
};
struct target_struct *data_tgt = NULL;
test_data_t td = {
.data = (cyaml_data_t **) &data_tgt,
.config = config,
.schema = &top_schema,
};
cyaml_err_t err;
ttest_ctx_t tc;

if (!ttest_start(report, __func__, cyaml_cleanup, &td, &tc)) {
return true;
}

err = cyaml_copy(config, &top_schema,
(const cyaml_data_t *) &val, 2,
(cyaml_data_t **) &data_tgt);
if (err != CYAML_ERR_MAPPING_REQUIRED) {
return ttest_fail(&tc, cyaml_strerror(err));
}

if (data_tgt != NULL) {
return ttest_fail(&tc, "Data non-NULL on error.");
}

return ttest_pass(&tc);
}

/**
* Test loading when schema expects uint, but value is invalid.
*
Expand Down Expand Up @@ -10649,6 +10711,7 @@ bool errs_tests(
pass &= test_err_save_schema_sequence_in_sequence(rc, &config);
pass &= test_err_copy_schema_sequence_in_sequence(rc, &config);
pass &= test_err_copy_schema_required_mapping_missing(rc, &config);
pass &= test_err_copy_schema_required_mapping_missing2(rc, &config);

ttest_heading(rc, "YAML / schema mismatch: bad values");

Expand Down

0 comments on commit a15b55a

Please sign in to comment.