Skip to content
This repository has been archived by the owner on Apr 9, 2020. It is now read-only.

Commit

Permalink
test: add array remove tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Dupont committed Apr 10, 2018
1 parent c6bcf1e commit 883ba7a
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/cbor_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,28 @@ CTEST(cbor, array)
cn_cbor_array_append(a, cn_cbor_string_create("five", CONTEXT_NULL_COMMA &err), &err);
ASSERT_TRUE(err.err == CN_CBOR_NO_ERROR);
ASSERT_EQUAL(a->length, 2);

cn_cbor_array_append(a, cn_cbor_string_create("six", CONTEXT_NULL_COMMA &err), &err);
ASSERT_TRUE(err.err == CN_CBOR_NO_ERROR);
ASSERT_EQUAL(a->length, 3);

cn_cbor *e = cn_cbor_index(a, 1);
ASSERT_NOT_NULL(e);
cn_cbor_array_remove(a, e, &err);
ASSERT_TRUE(err.err == CN_CBOR_NO_ERROR);
ASSERT_EQUAL(a->length, 2);

e = cn_cbor_index(a, 1);
ASSERT_NOT_NULL(e);
cn_cbor_array_remove(a, e, &err);
ASSERT_TRUE(err.err == CN_CBOR_NO_ERROR);
ASSERT_EQUAL(a->length, 1);

e = cn_cbor_index(a, 0);
ASSERT_NOT_NULL(e);
cn_cbor_array_remove(a, e, &err);
ASSERT_TRUE(err.err == CN_CBOR_NO_ERROR);
ASSERT_EQUAL(a->length, 0);
}

CTEST(cbor, array_errors)
Expand All @@ -429,6 +451,11 @@ CTEST(cbor, array_errors)
ASSERT_EQUAL(err.err, CN_CBOR_ERR_INVALID_PARAMETER);
cn_cbor_array_append(ci, NULL, &err);
ASSERT_EQUAL(err.err, CN_CBOR_ERR_INVALID_PARAMETER);

cn_cbor *e = cn_cbor_string_create("six", CONTEXT_NULL_COMMA &err);
cn_cbor *a = cn_cbor_array_create(CONTEXT_NULL_COMMA &err);
cn_cbor_array_remove(a, e, &err);
ASSERT_EQUAL(err.err, CN_CBOR_ERR_INVALID_PARAMETER);
}

CTEST(cbor, create_encode)
Expand Down

0 comments on commit 883ba7a

Please sign in to comment.