aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoe Hildebrand <joe-github@cursive.net>2015-03-31 23:19:54 -0600
committerJoe Hildebrand <joe-github@cursive.net>2015-03-31 23:19:54 -0600
commit086317455574684ee2923e3b7bab9cb51ef03531 (patch)
treec7a7eecf276e8492e610ef6116ebfc4e203ec1df
parenta995401f2bca1a0348ec182788c27d9a338505ca (diff)
downloadplatform_external_cn-cbor-086317455574684ee2923e3b7bab9cb51ef03531.tar.gz
platform_external_cn-cbor-086317455574684ee2923e3b7bab9cb51ef03531.tar.bz2
platform_external_cn-cbor-086317455574684ee2923e3b7bab9cb51ef03531.zip
Add coverage, remove the duplicated strcmp/memcmp
-rw-r--r--src/cn-get.c9
-rw-r--r--test/cbor_test.c6
2 files changed, 5 insertions, 10 deletions
diff --git a/src/cn-get.c b/src/cn-get.c
index 78ccdc9..e5e5de6 100644
--- a/src/cn-get.c
+++ b/src/cn-get.c
@@ -33,14 +33,7 @@ const cn_cbor* cn_cbor_mapget_string(const cn_cbor* cb, const char* key) {
keylen = strlen(key);
for (cp = cb->first_child; cp && cp->next; cp = cp->next->next) {
switch(cp->type) {
- case CN_CBOR_TEXT:
- if (keylen != cp->length) {
- continue;
- }
- if (strncmp(key, cp->v.str, cp->length) == 0) {
- return cp->next;
- }
- break;
+ case CN_CBOR_TEXT: // fall-through
case CN_CBOR_BYTES:
if (keylen != cp->length) {
continue;
diff --git a/test/cbor_test.c b/test/cbor_test.c
index 0d5404b..a8e5a0e 100644
--- a/test/cbor_test.c
+++ b/test/cbor_test.c
@@ -79,7 +79,9 @@ CTEST(cbor, parse)
"3b0000000100000000", // -4294967297
"4161", // h"a"
"6161", // "a"
+ "80", // []
"8100", // [0]
+ "820102", // [1,2]
"818100", // [[0]]
"a1616100", // {"a":0}
"d8184100", // tag
@@ -185,7 +187,7 @@ CTEST(cbor, getset)
const cn_cbor *val;
cn_cbor_errback err;
- ASSERT_TRUE(parse_hex("a3436363630262626201616100", &b));
+ ASSERT_TRUE(parse_hex("a40000436363630262626201616100", &b));
cb = cn_cbor_decode(b.ptr, b.sz CONTEXT_NULL, &err);
ASSERT_NOT_NULL(cb);
val = cn_cbor_mapget_string(cb, "a");
@@ -199,7 +201,7 @@ CTEST(cbor, getset)
free(b.ptr);
cn_cbor_free(cb CONTEXT_NULL);
- ASSERT_TRUE(parse_hex("a2006161206162", &b));
+ ASSERT_TRUE(parse_hex("a3616100006161206162", &b));
cb = cn_cbor_decode(b.ptr, b.sz CONTEXT_NULL, &err);
ASSERT_NOT_NULL(cb);
val = cn_cbor_mapget_int(cb, 0);