From e7d5aeaf222f55f8f05ad06aad50e7f5ec7c0fd0 Mon Sep 17 00:00:00 2001 From: Vincent Dupont Date: Mon, 2 Apr 2018 09:42:30 -0700 Subject: [PATCH] test: add array remove tests --- test/cbor_test.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/cbor_test.c b/test/cbor_test.c index eafea5d..251c923 100644 --- a/test/cbor_test.c +++ b/test/cbor_test.c @@ -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) @@ -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)