Skip to content
Snippets Groups Projects
Commit 58ae2f85 authored by Ali Mohammed's avatar Ali Mohammed
Browse files

add few tests to increase coverage for ui64 and ui128, added few more...

add few tests to increase coverage for ui64 and ui128, added few more operations in check_uuid, added more subscribtions in check_subscribe_local and few bug fixes there
parent f135fe93
No related branches found
No related tags found
No related merge requests found
...@@ -87,7 +87,7 @@ CHEAT_TEST(init_finalize_negativecomponentindex, ...@@ -87,7 +87,7 @@ CHEAT_TEST(init_finalize_negativecomponentindex,
} }
) )
CHEAT_TEST(init_finalize_twice, CHEAT_TEST(init_twice_finalize,
{ {
cheat_assert(mstro_status_description(mstro_status_MAX)==mstro_status_description(mstro_status_MAX+1)); cheat_assert(mstro_status_description(mstro_status_MAX)==mstro_status_description(mstro_status_MAX+1));
cheat_assert(MSTRO_OK == mstro_init("Tests","Init",20)); cheat_assert(MSTRO_OK == mstro_init("Tests","Init",20));
......
...@@ -46,8 +46,8 @@ ...@@ -46,8 +46,8 @@
#include <unistd.h> #include <unistd.h>
CHEAT_DECLARE( CHEAT_DECLARE(
mstro_subscription decl_sub, offer_sub, withdraw_sub; mstro_subscription decl_sub, decl_ack_sub, offer_sub, withdraw_sub, seal_sub, dispose_sub;
mstro_cdo_selector match_all_selector;
atomic_bool subscriber_dead; atomic_bool subscriber_dead;
...@@ -56,36 +56,48 @@ CHEAT_DECLARE( ...@@ -56,36 +56,48 @@ CHEAT_DECLARE(
void void
subscribe(void) subscribe(void)
{ {
mstro_cdo_selector match_all_selector;
cheat_assert(MSTRO_OK==mstro_cdo_selector_create( cheat_assert(MSTRO_OK==mstro_cdo_selector_create(
NULL, NULL, NULL, &match_all_selector)); NULL, NULL, NULL, &match_all_selector));
cheat_assert(MSTRO_OK==mstro_subscribe(match_all_selector,
MSTRO_POOL_EVENT_DECLARE_ACK,
false,
&decl_ack_sub));
cheat_assert(MSTRO_OK==mstro_subscribe(match_all_selector, cheat_assert(MSTRO_OK==mstro_subscribe(match_all_selector,
MSTRO_POOL_EVENT_DECLARE, MSTRO_POOL_EVENT_DECLARE,
false, false,
&decl_sub)); &decl_sub));
cheat_assert(MSTRO_OK==mstro_subscribe(match_all_selector,MSTRO_POOL_EVENT_SEAL,false, &seal_sub));
cheat_assert(MSTRO_OK==mstro_subscribe(match_all_selector, cheat_assert(MSTRO_OK==mstro_subscribe(match_all_selector,
MSTRO_POOL_EVENT_OFFER, MSTRO_POOL_EVENT_OFFER,
false, false,
&offer_sub)); &offer_sub));
cheat_assert(MSTRO_OK==mstro_subscribe(match_all_selector, cheat_assert(MSTRO_OK==mstro_subscribe(match_all_selector,
MSTRO_POOL_EVENT_OFFER, MSTRO_POOL_EVENT_WITHDRAW,
true, true,
&withdraw_sub)); &withdraw_sub));
cheat_assert(MSTRO_OK==mstro_subscribe(match_all_selector,MSTRO_POOL_EVENT_DISPOSE,false, &dispose_sub));
} }
/* perform the un-subscriptions */ /* perform the un-subscriptions */
void void
unsubscribe(void) unsubscribe(void)
{ {
mstro_cdo_selector match_all_selector; cheat_assert(MSTRO_OK==mstro_cdo_selector_dispose(match_all_selector));
cheat_assert(MSTRO_OK==mstro_cdo_selector_create(
NULL, NULL, NULL, &match_all_selector));
cheat_assert(MSTRO_OK==mstro_subscription_dispose(decl_sub)); cheat_assert(MSTRO_OK==mstro_subscription_dispose(decl_sub));
cheat_assert(MSTRO_OK==mstro_subscription_dispose(offer_sub)); cheat_assert(MSTRO_OK==mstro_subscription_dispose(offer_sub));
cheat_assert(MSTRO_OK==mstro_subscription_dispose(withdraw_sub)); cheat_assert(MSTRO_OK==mstro_subscription_dispose(withdraw_sub));
cheat_assert(MSTRO_OK==mstro_subscription_dispose(decl_ack_sub));
cheat_assert(MSTRO_OK==mstro_subscription_dispose(seal_sub));
cheat_assert(MSTRO_OK==mstro_subscription_dispose(dispose_sub));
} }
size_t num_offer=0, num_withdraw=0, num_declare=0; size_t num_offer=0, num_withdraw=0, num_declare=0, num_decl_ack=0, num_seal=0, num_dispose=0;
void mark_subscriber_dead(void*unused) void mark_subscriber_dead(void*unused)
{ {
...@@ -93,8 +105,12 @@ CHEAT_DECLARE( ...@@ -93,8 +105,12 @@ CHEAT_DECLARE(
subscriber_dead = true; subscriber_dead = true;
cheat_assert(num_declare==3); cheat_assert(num_declare==3);
cheat_assert(num_decl_ack==3);
cheat_assert(num_seal==3);
cheat_assert(num_offer==3); cheat_assert(num_offer==3);
cheat_assert(num_withdraw==3); cheat_assert(num_withdraw==3);
cheat_assert(num_dispose==3);
fprintf(stdout, "Subscriber terminated\n"); fprintf(stdout, "Subscriber terminated\n");
} }
...@@ -103,8 +119,15 @@ CHEAT_DECLARE( ...@@ -103,8 +119,15 @@ CHEAT_DECLARE(
subscriber_thread(void*unused) subscriber_thread(void*unused)
{ {
unused=unused; unused=unused;
struct timespec t;
t.tv_sec = 0;
t.tv_nsec = 100;
mstro_pool_event e2;
pthread_cleanup_push(mark_subscriber_dead, NULL); pthread_cleanup_push(mark_subscriber_dead, NULL);
cheat_assert(MSTRO_OK!=mstro_subscription_timedwait(decl_sub, &t, &e2));
fprintf(stdout, "subscriber started\n"); fprintf(stdout, "subscriber started\n");
while(1) { while(1) {
mstro_pool_event e; mstro_pool_event e;
...@@ -117,6 +140,25 @@ CHEAT_DECLARE( ...@@ -117,6 +140,25 @@ CHEAT_DECLARE(
fprintf(stdout, "%zu decl event(s)\n", count); fprintf(stdout, "%zu decl event(s)\n", count);
num_declare+=count; num_declare+=count;
} }
cheat_assert(MSTRO_OK==mstro_subscription_poll(decl_ack_sub,&e));
if(e!=NULL) {
mstro_pool_event tmp;
size_t count=0;
LL_COUNT(e,tmp, count);
fprintf(stdout, "%zu decl ack event(s)\n", count);
num_decl_ack+=count;
}
cheat_assert(MSTRO_OK==mstro_subscription_poll(seal_sub,&e));
if(e!=NULL) {
mstro_pool_event tmp;
size_t count=0;
LL_COUNT(e,tmp, count);
fprintf(stdout, "%zu seal event(s)\n", count);
num_seal+=count;
}
cheat_assert(MSTRO_OK==mstro_subscription_poll(offer_sub,&e)); cheat_assert(MSTRO_OK==mstro_subscription_poll(offer_sub,&e));
if(e!=NULL) { if(e!=NULL) {
mstro_pool_event tmp; mstro_pool_event tmp;
...@@ -125,6 +167,10 @@ CHEAT_DECLARE( ...@@ -125,6 +167,10 @@ CHEAT_DECLARE(
fprintf(stdout, "%zu offer event(s)\n", count); fprintf(stdout, "%zu offer event(s)\n", count);
num_offer+=count; num_offer+=count;
} }
// test invalid input
// FIXME mstro_subscription_wait wait forever with correct input
cheat_assert(MSTRO_OK!=mstro_subscription_wait(withdraw_sub, NULL));
cheat_assert(MSTRO_OK==mstro_subscription_poll(withdraw_sub,&e)); cheat_assert(MSTRO_OK==mstro_subscription_poll(withdraw_sub,&e));
if(e!=NULL) { if(e!=NULL) {
mstro_pool_event tmp; mstro_pool_event tmp;
...@@ -135,6 +181,16 @@ CHEAT_DECLARE( ...@@ -135,6 +181,16 @@ CHEAT_DECLARE(
cheat_assert(MSTRO_OK==mstro_subscription_ack(withdraw_sub, e)); cheat_assert(MSTRO_OK==mstro_subscription_ack(withdraw_sub, e));
num_withdraw+=count; num_withdraw+=count;
} }
cheat_assert(MSTRO_OK==mstro_subscription_poll(dispose_sub,&e));
if(e!=NULL) {
mstro_pool_event tmp;
size_t count=0;
LL_COUNT(e,tmp, count);
fprintf(stdout, "%zu dispose event(s)\n", count);
num_dispose+=count;
}
if(e==NULL) if(e==NULL)
cheat_assert(MSTRO_INVARG==mstro_pool_event_dispose(e)); cheat_assert(MSTRO_INVARG==mstro_pool_event_dispose(e));
else else
...@@ -189,6 +245,3 @@ CHEAT_TEST(cdo_local_subscriptions_work, ...@@ -189,6 +245,3 @@ CHEAT_TEST(cdo_local_subscriptions_work,
unsubscribe(); unsubscribe();
cheat_assert(MSTRO_OK == mstro_finalize()); cheat_assert(MSTRO_OK == mstro_finalize());
) )
...@@ -72,4 +72,53 @@ CHEAT_TEST(uuid_create_dup, ...@@ -72,4 +72,53 @@ CHEAT_TEST(uuid_create_dup,
cheat_assert(UUID_RC_OK==uuid_destroy(uuid2)); cheat_assert(UUID_RC_OK==uuid_destroy(uuid2));
) )
CHEAT_TEST(uuid_compare,
uuid_t *uuid1, *uuid2;
int result = -1;
cheat_assert(UUID_RC_OK==uuid_create(&uuid1));
cheat_assert(UUID_RC_OK==uuid_load(uuid1,"nil"));
cheat_assert(UUID_RC_OK==uuid_clone(uuid1, &uuid2));
/*Test cloned uuids if they are the same*/
uuid_compare(uuid1, uuid2, &result);
cheat_assert(result==0);
cheat_assert(UUID_RC_OK==uuid_destroy(uuid1));
uuid1 = NULL; /*set the pointer manually to NULL to avoid further use*/
cheat_assert(UUID_RC_OK==uuid_compare(uuid1, uuid2, &result));
cheat_assert(UUID_RC_OK==uuid_compare(uuid2, uuid1, &result));
cheat_assert(UUID_RC_OK==uuid_destroy(uuid2));
uuid2 = NULL; /*set the pointer manually to NULL to avoid further use*/
//compare two null uuids
cheat_assert(UUID_RC_OK==uuid_compare(uuid1, uuid2, &result));
cheat_assert(result==0);
)
CHEAT_TEST(uuid_import_export,
uuid_t *uuid1, *uuid2;
uuid_rc_t msg;
size_t data_len = 100;
char *data = NULL;
char *data2 = NULL;
cheat_assert(UUID_RC_OK==uuid_create(&uuid1));
cheat_assert(UUID_RC_OK==uuid_create(&uuid2));
cheat_assert(UUID_RC_OK==uuid_load(uuid1,"nil"));
cheat_assert(UUID_RC_OK==uuid_export(uuid1, UUID_FMT_TXT, &data, NULL));
cheat_assert(UUID_RC_OK==uuid_export(uuid1, UUID_FMT_STR, &data2, NULL));
msg = uuid_import(uuid2, UUID_FMT_STR, data2, &data_len);
printf("%s", uuid_error(msg));
cheat_assert(UUID_RC_OK==uuid_destroy(uuid1));
)
...@@ -44,8 +44,10 @@ ...@@ -44,8 +44,10 @@
#include "maestro.h" #include "maestro.h"
#include "maestro/i_cdo.h" #include "maestro/i_cdo.h"
#include <stdint.h> #include <stdint.h>
#include "maestro/i_uuid_ui64.h"
#include "maestro/i_uuid_ui128.h"
#include "maestro/i_base64.h" #include "maestro/i_base64.h"
CHEAT_TEST(base64, CHEAT_TEST(base64,
{ {
size_t dummy; size_t dummy;
...@@ -96,3 +98,103 @@ CHEAT_TEST(invalid_cdo_withdraw, { ...@@ -96,3 +98,103 @@ CHEAT_TEST(invalid_cdo_withdraw, {
CHEAT_TEST(invalid_cdo_dispose, { CHEAT_TEST(invalid_cdo_dispose, {
cheat_assert(MSTRO_INVARG==mstro_cdo_dispose(NULL)); cheat_assert(MSTRO_INVARG==mstro_cdo_dispose(NULL));
}) })
CHEAT_TEST(math64,
ui64_t zero,max, value_64, tmp_64;
unsigned long value_ul = 50505050;
unsigned long value_ul2;
char * str;
zero = ui64_zero();
max = ui64_max();
value_64 = ui64_n2i(value_ul);
value_ul2 = ui64_i2n(value_64);
value_64 = ui64_s2i("01010101010101", NULL, 2);
cheat_assert( NULL == ui64_i2s(value_64, NULL, 0 , 2));
tmp_64 = ui64_add(max, zero, NULL);
cheat_assert(0 == ui64_cmp(max,tmp_64));
tmp_64 = ui64_sub(max, zero, NULL);
cheat_assert(0 == ui64_cmp(max,tmp_64));
tmp_64 = ui64_addn(zero, 1, NULL);
tmp_64 = ui64_subn(tmp_64, 1, NULL);
cheat_assert(0 == ui64_cmp(tmp_64,zero));
tmp_64 = ui64_mul(max, zero, NULL);
cheat_assert(0 == ui64_cmp(tmp_64,zero));
tmp_64 = ui64_muln(max,1, NULL);
cheat_assert(0 == ui64_cmp(tmp_64,max));
tmp_64 = ui64_div(max,value_64, NULL);
cheat_assert(0 != ui64_cmp(max,tmp_64));
tmp_64 = ui64_divn(value_64, 1, NULL);
cheat_assert(0 == ui64_cmp(value_64,tmp_64));
tmp_64 = ui64_rol(value_64,1, NULL);
tmp_64 = ui64_ror(tmp_64,1, NULL);
cheat_assert(0 == ui64_cmp(value_64,tmp_64));
cheat_assert(1 < ui64_len(max));
)
CHEAT_TEST(math128,
ui128_t zero,max, value_128, tmp_128;
unsigned long value_ul = 50505050;
unsigned long value_ul2;
char * str;
zero = ui128_zero();
max = ui128_max();
value_128 = ui128_n2i(value_ul);
value_ul2 = ui128_i2n(value_128);
value_128 = ui128_s2i("01010101010101", NULL, 2);
cheat_assert( NULL == ui128_i2s(value_128, NULL, 0 , 2));
tmp_128 = ui128_add(max, zero, NULL);
cheat_assert(0 == ui128_cmp(max,tmp_128));
tmp_128 = ui128_sub(max, zero, NULL);
cheat_assert(0 == ui128_cmp(max,tmp_128));
tmp_128 = ui128_addn(zero, 1, NULL);
tmp_128 = ui128_subn(tmp_128, 1, NULL);
cheat_assert(0 == ui128_cmp(tmp_128,zero));
tmp_128 = ui128_mul(max, zero, NULL);
cheat_assert(0 == ui128_cmp(tmp_128,zero));
tmp_128 = ui128_muln(max,1, NULL);
cheat_assert(0 == ui128_cmp(tmp_128,max));
tmp_128 = ui128_div(max,value_128, NULL);
cheat_assert(0 != ui128_cmp(max,tmp_128));
tmp_128 = ui128_divn(value_128, 1, NULL);
cheat_assert(0 == ui128_cmp(value_128,tmp_128));
tmp_128 = ui128_rol(value_128,1, NULL);
tmp_128 = ui128_ror(tmp_128,1, NULL);
cheat_assert(0 == ui128_cmp(value_128,tmp_128));
cheat_assert(1 < ui128_len(max));
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment