Skip to content

Commit

Permalink
remove prints
Browse files Browse the repository at this point in the history
Signed-off-by: Shivshankar-Reddy <[email protected]>
  • Loading branch information
Shivshankar-Reddy committed May 10, 2024
1 parent f8d6188 commit f9a6ae0
Showing 1 changed file with 31 additions and 59 deletions.
90 changes: 31 additions & 59 deletions src/unit/test_zipmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,32 @@ static void zipmapRepr(unsigned char *p) {
printf("{status %u}",*p++);
while(1) {
if (p[0] == ZIPMAP_END) {
printf("{end}");
break;
} else {
unsigned char e;

l = zipmapDecodeLength(p);
printf("{key %u}",l);
p += zipmapEncodeLength(NULL,l);
if (l != 0 && fwrite(p,l,1,stdout) == 0) perror("fwrite");
p += l;

l = zipmapDecodeLength(p);
printf("{value %u}",l);
p += zipmapEncodeLength(NULL,l);
e = *p++;
if (l != 0 && fwrite(p,l,1,stdout) == 0) perror("fwrite");
p += l+e;
if (e) {
printf("[");
while(e--) printf(".");
printf("]");
while(e--);
}
}
}
printf("\n");
}

int test_zipmapLookUpLargeKey(int argc, char *argv[], int flags) {
unsigned char *zm;

UNUSED(argc);
UNUSED(argv);
UNUSED(flags);

zm = zipmapNew();

zm = zipmapSet(zm,(unsigned char*) "name",4, (unsigned char*) "foo",3,NULL);
Expand All @@ -60,32 +52,24 @@ int test_zipmapLookUpLargeKey(int argc, char *argv[], int flags) {
zm = zipmapDel(zm,(unsigned char*) "new",3,NULL);
zipmapRepr(zm);

printf("\nLook up large key:\n");
{
unsigned char buf[512];
unsigned char *value;
unsigned int vlen, i;
for (i = 0; i < 512; i++) buf[i] = 'a';

zm = zipmapSet(zm,buf,512,(unsigned char*) "long",4,NULL);
if (zipmapGet(zm,buf,512,&value,&vlen)) {
printf(" <long key> is associated to the %d bytes value: %.*s val:%s\n",
vlen, vlen, value,value);
TEST_ASSERT(4 == vlen);
TEST_ASSERT(strncmp("long", (const char*)value, vlen) == 0);
}
unsigned char buf[512];
unsigned char *value;
unsigned int vlen, i;
for (i = 0; i < 512; i++) buf[i] = 'a';
zm = zipmapSet(zm,buf,512,(unsigned char*) "long",4,NULL);
if (zipmapGet(zm,buf,512,&value,&vlen)) {
TEST_ASSERT(4 == vlen);
TEST_ASSERT(strncmp("long", (const char*)value, vlen) == 0);
}
zfree(zm);
return 0;
}

int test_zipmapPerformDirectLookup(int argc, char *argv[], int flags) {
unsigned char *zm;

UNUSED(argc);
UNUSED(argv);
UNUSED(flags);

zm = zipmapNew();

zm = zipmapSet(zm,(unsigned char*) "name",4, (unsigned char*) "foo",3,NULL);
Expand All @@ -104,30 +88,22 @@ int test_zipmapPerformDirectLookup(int argc, char *argv[], int flags) {
zipmapRepr(zm);
zm = zipmapDel(zm,(unsigned char*) "new",3,NULL);
zipmapRepr(zm);
unsigned char *value;
unsigned int vlen;

printf("\nPerform a direct lookup:\n");
{
unsigned char *value;
unsigned int vlen;

if (zipmapGet(zm,(unsigned char*) "foo",3,&value,&vlen)) {
printf(" foo is associated to the %d bytes value: %.*s\n",
vlen, vlen, value);
TEST_ASSERT(5 == vlen);
TEST_ASSERT(strcmp("12345", (const char*)value));
}
if (zipmapGet(zm,(unsigned char*) "foo",3,&value,&vlen)) {
TEST_ASSERT(5 == vlen);
TEST_ASSERT(strcmp("12345", (const char*)value));
}
zfree(zm);
return 0;
}

int test_zipmapIterateThroughElements(int argc, char *argv[], int flags) {
unsigned char *zm;

UNUSED(argc);
UNUSED(argv);
UNUSED(flags);

zm = zipmapNew();

zm = zipmapSet(zm,(unsigned char*) "name",4, (unsigned char*) "foo",3,NULL);
Expand All @@ -147,27 +123,23 @@ int test_zipmapIterateThroughElements(int argc, char *argv[], int flags) {
zm = zipmapDel(zm,(unsigned char*) "new",3,NULL);
zipmapRepr(zm);

printf("\nIterate through elements:\n");
{
unsigned char *i = zipmapRewind(zm);
unsigned char *key, *value;
unsigned int klen, vlen;
char* expected_key[] = {"name", "surname", "age", "hello", "foo", "noval"};
char* expected_value[] = {"foo", "foo", "foo", "world!", "12345", NULL};
unsigned int expected_klen[] = {4,7,3,5,3,5};
unsigned int expected_vlen[] = {3,3,3,6,5,0};
int iter = 0;

while((i = zipmapNext(i,&key,&klen,&value,&vlen)) != NULL) {
printf(" %d:%.*s => %d:%.*s\n", klen, klen, key, vlen, vlen, value);
char *tmp = expected_key[iter];
TEST_ASSERT(klen == expected_klen[iter]);
TEST_ASSERT(strncmp((const char*)tmp, (const char*)key, klen) == 0);
tmp = expected_value[iter];
TEST_ASSERT(vlen == expected_vlen[iter]);
TEST_ASSERT(strncmp((const char*)tmp, (const char*)value, vlen) == 0);
iter++;
}
unsigned char *i = zipmapRewind(zm);
unsigned char *key, *value;
unsigned int klen, vlen;
char* expected_key[] = {"name", "surname", "age", "hello", "foo", "noval"};
char* expected_value[] = {"foo", "foo", "foo", "world!", "12345", NULL};
unsigned int expected_klen[] = {4,7,3,5,3,5};
unsigned int expected_vlen[] = {3,3,3,6,5,0};
int iter = 0;

while((i = zipmapNext(i,&key,&klen,&value,&vlen)) != NULL) {
char *tmp = expected_key[iter];
TEST_ASSERT(klen == expected_klen[iter]);
TEST_ASSERT(strncmp((const char*)tmp, (const char*)key, klen) == 0);
tmp = expected_value[iter];
TEST_ASSERT(vlen == expected_vlen[iter]);
TEST_ASSERT(strncmp((const char*)tmp, (const char*)value, vlen) == 0);
iter++;
}
zfree(zm);
return 0;
Expand Down

0 comments on commit f9a6ae0

Please sign in to comment.