Skip to content

Commit

Permalink
zcbor_print.h: Add missing errors to zcbor_error_str()
Browse files Browse the repository at this point in the history
Signed-off-by: Øyvind Rønningstad <oyvind.ronningstad@nordicsemi.no>
  • Loading branch information
oyvindronningstad committed Jan 3, 2024
1 parent e9ee55e commit 6273ad3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 7 additions & 0 deletions include/zcbor_print.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ static const char *zcbor_error_str(int error)
ZCBOR_ERR_CASE(ZCBOR_ERR_WRONG_RANGE)
ZCBOR_ERR_CASE(ZCBOR_ERR_ITERATIONS)
ZCBOR_ERR_CASE(ZCBOR_ERR_ASSERTION)
ZCBOR_ERR_CASE(ZCBOR_ERR_PAYLOAD_OUTDATED)
ZCBOR_ERR_CASE(ZCBOR_ERR_ELEM_NOT_FOUND)
ZCBOR_ERR_CASE(ZCBOR_ERR_MAP_MISALIGNED)
ZCBOR_ERR_CASE(ZCBOR_ERR_ELEMS_NOT_PROCESSED)
ZCBOR_ERR_CASE(ZCBOR_ERR_NOT_AT_END)
ZCBOR_ERR_CASE(ZCBOR_ERR_MAP_FLAGS_NOT_AVAILABLE)
ZCBOR_ERR_CASE(ZCBOR_ERR_INVALID_VALUE_ENCODING)
}
#undef ZCBOR_ERR_CASE

Expand Down
9 changes: 8 additions & 1 deletion tests/unit/test1_unit_tests/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -997,10 +997,17 @@ ZTEST(zcbor_unit_tests, test_error_str)
test_str(ZCBOR_ERR_WRONG_RANGE);
test_str(ZCBOR_ERR_ITERATIONS);
test_str(ZCBOR_ERR_ASSERTION);
test_str(ZCBOR_ERR_PAYLOAD_OUTDATED);
test_str(ZCBOR_ERR_ELEM_NOT_FOUND);
test_str(ZCBOR_ERR_MAP_MISALIGNED);
test_str(ZCBOR_ERR_ELEMS_NOT_PROCESSED);
test_str(ZCBOR_ERR_NOT_AT_END);
test_str(ZCBOR_ERR_MAP_FLAGS_NOT_AVAILABLE);
test_str(ZCBOR_ERR_INVALID_VALUE_ENCODING);
test_str(ZCBOR_ERR_UNKNOWN);
zassert_mem_equal(zcbor_error_str(-1), "ZCBOR_ERR_UNKNOWN", sizeof("ZCBOR_ERR_UNKNOWN"), NULL);
zassert_mem_equal(zcbor_error_str(-10), "ZCBOR_ERR_UNKNOWN", sizeof("ZCBOR_ERR_UNKNOWN"), NULL);
zassert_mem_equal(zcbor_error_str(ZCBOR_ERR_ASSERTION + 1), "ZCBOR_ERR_UNKNOWN", sizeof("ZCBOR_ERR_UNKNOWN"), NULL);
zassert_mem_equal(zcbor_error_str(ZCBOR_ERR_INVALID_VALUE_ENCODING + 1), "ZCBOR_ERR_UNKNOWN", sizeof("ZCBOR_ERR_UNKNOWN"), NULL);
zassert_mem_equal(zcbor_error_str(100000), "ZCBOR_ERR_UNKNOWN", sizeof("ZCBOR_ERR_UNKNOWN"), NULL);
}

Expand Down

0 comments on commit 6273ad3

Please sign in to comment.