Skip to content

Commit

Permalink
Ensure correctness of value pointers in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
squidfunk committed Dec 16, 2015
1 parent 3f2b7f8 commit dedc80e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
14 changes: 7 additions & 7 deletions tests/message/cursor/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ START_TEST(test_create_packed_merged) {
} END_TEST

/*
* Create a cursor over a message for a packed field.
* Create a cursor over a nested message for a packed field.
*/
START_TEST(test_create_packed_nested) {
const uint8_t data[] = { 82, 6, 26, 4, 1, 2, 3, 4 };
Expand Down Expand Up @@ -2228,9 +2228,9 @@ START_TEST(test_get_string) {

/* Read value from cursor */
for (size_t f = 0; f < 2; f++, pb_cursor_next(&cursor)) {
pb_string_t value1 = pb_string_init_from_chars("DEFAULT"), value2;
ck_assert_uint_eq(PB_ERROR_NONE, pb_cursor_get(&cursor, &value2));
fail_unless(pb_string_equals(&value1, &value2));
pb_string_t check = pb_string_init_from_chars("DEFAULT"), value;
ck_assert_uint_eq(PB_ERROR_NONE, pb_cursor_get(&cursor, &value));
fail_unless(pb_string_equals(&check, &value));

/* Assert cursor validity and error */
fail_unless(pb_cursor_valid(&cursor));
Expand Down Expand Up @@ -2399,17 +2399,17 @@ START_TEST(test_put) {
ck_assert_uint_eq(PB_ERROR_NONE, pb_cursor_error(&cursor));

/* Write values to cursor */
uint64_t value;
for (size_t f = 1; f < 5; f++, pb_cursor_next(&cursor)) {
ck_assert_uint_eq(PB_ERROR_NONE, pb_cursor_put(&cursor, &f));
uint64_t check = f, value;
ck_assert_uint_eq(PB_ERROR_NONE, pb_cursor_put(&cursor, &check));

/* Assert cursor validity and error */
fail_unless(pb_cursor_valid(&cursor));
ck_assert_uint_eq(PB_ERROR_NONE, pb_cursor_error(&cursor));

/* Read value from cursor */
ck_assert_uint_eq(PB_ERROR_NONE, pb_cursor_get(&cursor, &value));
ck_assert_uint_eq(f, value);
ck_assert_uint_eq(check, value);

/* Assert cursor tag and position */
ck_assert_uint_eq(2, pb_cursor_tag(&cursor));
Expand Down
27 changes: 18 additions & 9 deletions tests/message/nested/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ START_TEST(test_has) {

/* Create a hundred nested submessages and write values to them */
for (size_t m = 1; m < 101; m++) {
uint64_t value = m;
messages[m] = pb_message_create_within(&(messages[m - 1]), 11);
ck_assert_uint_eq(PB_ERROR_NONE,
pb_message_put(&(messages[m]), 2, &m));
pb_message_put(&(messages[m]), 2, &value));
}

/* Iterate over submessages */
Expand Down Expand Up @@ -139,9 +140,10 @@ START_TEST(test_has_repeated) {

/* Create a hundred nested submessages and write values to them */
for (size_t m = 1; m < 101; m++) {
uint64_t value = m;
messages[m] = pb_message_create_within(&(messages[m - 1]), 11);
ck_assert_uint_eq(PB_ERROR_NONE,
pb_message_put(&(messages[m]), 4, &m));
pb_message_put(&(messages[m]), 4, &value));
}

/* Iterate over submessages */
Expand Down Expand Up @@ -176,9 +178,10 @@ START_TEST(test_has_unaligned) {

/* Create a hundred nested submessages and write values to them */
for (size_t m = 1; m < 101; m++) {
uint64_t value = m;
messages[m] = pb_message_create_within(&(messages[m - 1]), 11);
ck_assert_uint_eq(PB_ERROR_NONE,
pb_message_put(&(messages[m]), 2, &m));
pb_message_put(&(messages[m]), 2, &value));
}

/* Write value to message */
Expand Down Expand Up @@ -241,9 +244,10 @@ START_TEST(test_match) {

/* Create a hundred nested submessages and write values to them */
for (size_t m = 1; m < 101; m++) {
uint64_t value = m;
messages[m] = pb_message_create_within(&(messages[m - 1]), 11);
ck_assert_uint_eq(PB_ERROR_NONE,
pb_message_put(&(messages[m]), 2, &m));
pb_message_put(&(messages[m]), 2, &value));
}

/* Iterate over submessages */
Expand Down Expand Up @@ -301,9 +305,10 @@ START_TEST(test_match_repeated) {

/* Create a hundred nested submessages and write values to them */
for (size_t m = 1; m < 101; m++) {
uint64_t value = m;
messages[m] = pb_message_create_within(&(messages[m - 1]), 11);
ck_assert_uint_eq(PB_ERROR_NONE,
pb_message_put(&(messages[m]), 4, &m));
pb_message_put(&(messages[m]), 4, &value));
}

/* Iterate over submessages */
Expand Down Expand Up @@ -339,9 +344,10 @@ START_TEST(test_match_unaligned) {

/* Create a hundred nested submessages and write values to them */
for (size_t m = 1; m < 101; m++) {
uint64_t value = m;
messages[m] = pb_message_create_within(&(messages[m - 1]), 11);
ck_assert_uint_eq(PB_ERROR_NONE,
pb_message_put(&(messages[m]), 2, &m));
pb_message_put(&(messages[m]), 2, &value));
}

/* Write value to message */
Expand Down Expand Up @@ -402,9 +408,10 @@ START_TEST(test_get) {

/* Create a hundred nested submessages and write values to them */
for (size_t m = 1; m < 101; m++) {
uint64_t value = m;
messages[m] = pb_message_create_within(&(messages[m - 1]), 11);
ck_assert_uint_eq(PB_ERROR_NONE,
pb_message_put(&(messages[m]), 2, &m));
pb_message_put(&(messages[m]), 2, &value));
}

/* Iterate over submessages */
Expand Down Expand Up @@ -471,9 +478,10 @@ START_TEST(test_get_absent) {

/* Create a hundred nested submessages and write values to them */
for (size_t m = 1; m < 101; m++) {
uint64_t value = m;
messages[m] = pb_message_create_within(&(messages[m - 1]), 11);
ck_assert_uint_eq(PB_ERROR_NONE,
pb_message_put(&(messages[m]), 2, &m));
pb_message_put(&(messages[m]), 2, &value));
}

/* Create tags */
Expand Down Expand Up @@ -507,9 +515,10 @@ START_TEST(test_get_unaligned) {

/* Create a hundred nested submessages and write values to them */
for (size_t m = 1; m < 101; m++) {
uint64_t value = m;
messages[m] = pb_message_create_within(&(messages[m - 1]), 11);
ck_assert_uint_eq(PB_ERROR_NONE,
pb_message_put(&(messages[m]), 2, &m));
pb_message_put(&(messages[m]), 2, &value));
}

/* Write value to message */
Expand Down

0 comments on commit dedc80e

Please sign in to comment.