diff --git a/src/unit/test_zipmap.c b/src/unit/test_zipmap.c index 8db8713fb6..24740c4cc8 100644 --- a/src/unit/test_zipmap.c +++ b/src/unit/test_zipmap.c @@ -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); @@ -60,20 +52,14 @@ 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(" 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; @@ -81,11 +67,9 @@ int test_zipmapLookUpLargeKey(int argc, char *argv[], int flags) { 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); @@ -104,18 +88,12 @@ 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; @@ -123,11 +101,9 @@ int test_zipmapPerformDirectLookup(int argc, char *argv[], int flags) { 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); @@ -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;