From 963c854ad779496a6aaae648c0f26f5d9fecb044 Mon Sep 17 00:00:00 2001 From: wanghaemq Date: Wed, 8 Nov 2023 16:58:59 +0800 Subject: [PATCH] * NEW add unit test for new vector. --- src/proto.c | 2 +- test/vector.c | 134 +++++++++++++++++++++++++++++--------------------- 2 files changed, 79 insertions(+), 57 deletions(-) diff --git a/src/proto.c b/src/proto.c index 8876238..7d803b4 100644 --- a/src/proto.c +++ b/src/proto.c @@ -33,7 +33,7 @@ struct buf { }; HashTable files; -nftp_vec *fcb_reg; +nftp_vec *fcb_reg = NULL; HashTable senderfiles; struct nctx { diff --git a/test/vector.c b/test/vector.c index 5b5ab69..72034c3 100644 --- a/test/vector.c +++ b/test/vector.c @@ -16,73 +16,95 @@ int test_vector() { nftp_log("test_vector"); - nftp_vec *v1, *v2; - char *e0 = "e0", *e1, *e2 = "e2"; + nftp_vec *v1; + char *e, *e0 = "e0", *e1 = "e1", *e2 = "e2"; int idx; + int cap = NFTP_SIZE / 4; - assert(0 == nftp_vec_alloc(&v1, NFTP_SIZE * 2)); + assert(0 == nftp_vec_alloc(&v1, cap)); assert(NULL != v1); assert(0 == nftp_vec_len(v1)); - assert(NFTP_SIZE * 2 == nftp_vec_cap(v1)); + assert(cap == nftp_vec_cap(v1)); assert(0 == nftp_vec_append(v1, (void *)e0)); assert(1 == nftp_vec_len(v1)); - assert(0 == nftp_vec_get(v1, 0, (void **)&e1)); - assert(e1 == e0); - - assert(0 == nftp_vec_insert(v1, (void *)e2, 1)); - assert(2 == nftp_vec_len(v1)); - assert(0 == nftp_vec_delete(v1, (void **)&e1, 1)); - assert(1 == nftp_vec_len(v1)); - assert(e2 == e1); - assert(0 == nftp_vec_delete(v1, (void **)&e1, 0)); - assert(0 == nftp_vec_len(v1)); - assert(e0 == e1); - - assert(0 == nftp_vec_push(v1, (void *)e0, NFTP_HEAD)); + assert(0 == nftp_vec_get(v1, 0, (void **)&e)); + assert(e == e0); + + char *earr[3] = {e0, e1, e2}; + + // Push test + int k=0; + for (int i=0; i