summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/CMakeLists.txt4
-rw-r--r--tests/helper.c16
-rw-r--r--tests/helper.h26
-rw-r--r--tests/main.c115
-rw-r--r--tests/particle.c97
-rw-r--r--tests/spin.c46
-rw-r--r--tests/user_door.c55
7 files changed, 250 insertions, 109 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 20b3e39..07f7dd8 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -1,5 +1,9 @@
LIST(APPEND TESTS_CC_SOURCES
main.c
+ helper.c
+ spin.c
+ particle.c
+ user_door.c
)
include_directories(
diff --git a/tests/helper.c b/tests/helper.c
new file mode 100644
index 0000000..929aef7
--- /dev/null
+++ b/tests/helper.c
@@ -0,0 +1,16 @@
+
+#include "helper.h"
+
+void check_cond(Eina_Bool cond, char *msg) {
+ if(!cond) {
+ EINA_LOG_DOM_ERR(_eiotas_log_dom,"%s",msg);
+ }
+}
+
+void check_str(char *s0, char *s1, char *msg) {
+ if(strcmp(s0,s1)!=0) {
+ EINA_LOG_DOM_ERR(_eiotas_log_dom,"%s => %s != %s\n",msg,s0,s1);
+ }
+}
+
+
diff --git a/tests/helper.h b/tests/helper.h
new file mode 100644
index 0000000..b0f9449
--- /dev/null
+++ b/tests/helper.h
@@ -0,0 +1,26 @@
+#ifndef _HELPER_H_
+#define _HELPER_H_
+
+#include "Eiotas.h"
+
+#include <stdio.h>
+
+#include <eina_log.h>
+#include <eina_array.h>
+#include <eina_stringshare.h>
+
+#undef PRINTPTR
+#ifdef __clang__
+# define PRINTPTR(_p) (unsigned int)_p
+#else
+# define PRINTPTR(_p) (_p)
+#endif
+
+void check_cond(Eina_Bool cond, char *msg);
+void check_str(char *s0, char *s1, char *msg);
+
+void test_spin();
+void test_particle();
+void test_user_door();
+
+#endif // _HELPER_H_
diff --git a/tests/main.c b/tests/main.c
index 6de02a1..b19b5f4 100644
--- a/tests/main.c
+++ b/tests/main.c
@@ -1,120 +1,17 @@
-#include "Eiotas.h"
-#include <eina_log.h>
-#include <stdio.h>
-
-#undef PRINTPTR
-#ifdef __clang__
-# define PRINTPTR(_p) (unsigned int)_p
-#else
-# define PRINTPTR(_p) (_p)
-#endif
-
-typedef struct {
- char txt[32];
- int idx;
-} Input;
-
-static Input* input_create(char *txt)
-{
- Input *input = (Input*)malloc(sizeof(Input));
- strncpy(input->txt,txt,32);
- input->txt[31] = '\0';
- input->idx = 0;
- return input;
-}
-
-static void input_free(Input *input)
-{
- EINA_LOG_DOM_DBG(_eiotas_log_dom,"free Input\n");
- free(input);
-}
-
-static void input_show(Input *input)
-{
- EINA_LOG_DOM_DBG(_eiotas_log_dom,"Input [%d] %s\n",input->idx,input->txt);
-}
-
-static void input_receive(const Eiotas_Door *door, Eiotas_Particle *particle, Eiotas_User_Data *data)
-{
- EINA_LOG_DOM_DBG(_eiotas_log_dom,"input_receive 0x%X\n",PRINTPTR(data));
-}
+#include "helper.h"
int main(int argc, char **argv)
{
- int i;
- Eiotas_Particle *p0, *p1, *p2, *p3, *p4, *p5, *p6, *p7, *p8, *p9, *p10;
-
if(eiotas_init()==0) {
return EXIT_FAILURE;
}
- eina_log_domain_level_set("eiotas",EINA_LOG_LEVEL_DBG);
- EINA_LOG_DOM_DBG(_eiotas_log_dom,"Eiotas version %d.%d.%d",eiotas_version->major,eiotas_version->minor,eiotas_version->micro);
+ eina_log_domain_level_set("eiotas",EINA_LOG_LEVEL_ERR);
+ EINA_LOG_DOM_INFO(_eiotas_log_dom,"Eiotas version %d.%d.%d",eiotas_version->major,eiotas_version->minor,eiotas_version->micro);
- Eiotas_Spin *dom0 = eiotas_spin_add("dom0",10);
- eiotas_iota_show((Eiotas_Iota*)dom0);
-
- Eiotas_Room *room = &dom0->room;
- char name[8];
- for(i=0; i<5; i++) {
- sprintf(name,"room%d",i);
- Eiotas_Room *tmp = eiotas_room_add(name,room);
- if(tmp!=NULL) {
- room = tmp;
- eiotas_iota_show((Eiotas_Iota*)room); // MACROS
- }
- }
- room = eiotas_room_add("room0",&dom0->room);
-
- Input *input = input_create("hello world");
- input_show(input);
-
- Eiotas_User_Bits user_bits;
-
- user_bits.data = input;
- user_bits.free_fct = (Eiotas_User_Data_Free)&input_free;
- user_bits.recv_fct = (Eiotas_Receive_Particle)&input_receive;
- Eiotas_Door *din0 = eiotas_door_add("input0",&dom0->room,&user_bits);
- eiotas_iota_show(&din0->iota); // eiotas_iota_show((Eiotas_Iota*)din0);
-
- p0 = eiotas_require_particle(din0);
- p1 = eiotas_require_particle(din0);
- p2 = eiotas_require_particle(din0);
- p3 = eiotas_require_particle(din0);
- p4 = eiotas_require_particle(din0);
- p5 = eiotas_require_particle(din0);
- p6 = eiotas_require_particle(din0);
- p7 = eiotas_require_particle(din0);
- p8 = eiotas_require_particle(din0);
- p9 = eiotas_require_particle(din0);
-
- eiotas_release_particle(din0,p0);
- eiotas_release_particle(din0,p1);
- p10 = eiotas_require_particle(din0);
- if(p10!=p1) {
- fprintf(stderr,"Particle require fail\n");
- }
- eiotas_release_particle(din0,p10);
-
- eiotas_spin_send_particle((Eiotas_Spin*)din0->iota.spin,p2,EINA_FALSE);
- eiotas_spin_send_particle((Eiotas_Spin*)din0->iota.spin,p3,EINA_TRUE);
-
- eiotas_particle_merge(p4,p5);
- eiotas_particle_merge(p4,p6);
- eiotas_particle_merge(p5,p7);
- eiotas_particle_merge(p5,p8);
- eiotas_particle_merge(p5,p9);
-
- eiotas_particle_add_destinations(p4,"dom0/room0/door0?get");
- eiotas_particle_add_destinations(p4," dom0/room0/door0?get ");
- eiotas_particle_add_destinations(p4," dom0/room0/door0?get ");
- eiotas_particle_add_destinations(p4,"dom0/room0/room1/doorx?get,door?get,dom0/room0/door0?get");
- eiotas_particle_add_destinations(p4," dom0/room0/room1/doorx?get,door?get , dom0/room0/door0?get ");
- eiotas_particle_add_destinations(p4," , , dom0/room0/room1/doorx?get,door?get ,, dom0/room0/door0?get ");
-
- eiotas_release_particle(din0,p4);
-
- eiotas_spin_free(dom0);
+ test_spin();
+ test_particle();
return eiotas_shutdown();
}
+
diff --git a/tests/particle.c b/tests/particle.c
new file mode 100644
index 0000000..cc9e8d2
--- /dev/null
+++ b/tests/particle.c
@@ -0,0 +1,97 @@
+
+#include "helper.h"
+
+void test_particle()
+{
+ void *p;
+ Eina_Accessor *acc;
+ Eiotas_Particle *p0, *p1, *p2, *p3, *p4;
+
+ Eiotas_Spin *dom0 = eiotas_spin_add("dom0",10);
+
+ p0 = eiotas_require_particle(dom0);
+
+ eiotas_particle_destinations_add(p0,"dom0/room0/door0?get");
+ eiotas_particle_destinations_add(p0," dom0/room0/door0?get ");
+ eiotas_particle_destinations_add(p0," dom0/room0/door0?get ");
+ eiotas_particle_destinations_add(p0,"dom0/room0/room1/doorx?get,door?get,dom0/room0/door0?get");
+ eiotas_particle_destinations_add(p0," dom0/room0/room1/doorx?get,door?get , dom0/room0/door0?get ");
+ eiotas_particle_destinations_add(p0," , , dom0/room0/room1/doorx?get,door?get ,, dom0/room0/door0?get ");
+
+ acc = eina_array_accessor_new(p0->dsts);
+ eina_accessor_data_get(acc,0,&p);
+ check_str("dom0/room0/door0?get",(char*)p,"eiotas_particle_destinations_add");
+ eina_accessor_data_get(acc,1,&p);
+ check_str("dom0/room0/door0?get",(char*)p,"eiotas_particle_destinations_add");
+ eina_accessor_data_get(acc,2,&p);
+ check_str("dom0/room0/door0?get",(char*)p,"eiotas_particle_destinations_add");
+ eina_accessor_data_get(acc,3,&p);
+ check_str("dom0/room0/room1/doorx?get",(char*)p,"eiotas_particle_destinations_add");
+ eina_accessor_data_get(acc,4,&p);
+ check_str("door?get",(char*)p,"eiotas_particle_destinations_add");
+ eina_accessor_data_get(acc,5,&p);
+ check_str("dom0/room0/door0?get",(char*)p,"eiotas_particle_destinations_add");
+ eina_accessor_data_get(acc,6,&p);
+ check_str("dom0/room0/room1/doorx?get",(char*)p,"eiotas_particle_destinations_add");
+ eina_accessor_data_get(acc,7,&p);
+ check_str("door?get",(char*)p,"eiotas_particle_destinations_add");
+ eina_accessor_data_get(acc,8,&p);
+ check_str("dom0/room0/door0?get",(char*)p,"eiotas_particle_destinations_add");
+ eina_accessor_data_get(acc,9,&p);
+ check_str("dom0/room0/room1/doorx?get",(char*)p,"eiotas_particle_destinations_add");
+ eina_accessor_data_get(acc,10,&p);
+ check_str("door?get",(char*)p,"eiotas_particle_destinations_add");
+ eina_accessor_data_get(acc,11,&p);
+ check_str("dom0/room0/door0?get",(char*)p,"eiotas_particle_destinations_add");
+ check_cond((eina_accessor_data_get(acc,12,&p)==EINA_FALSE),"!!!!! eina_accessor_data_get should fail");;
+
+ eiotas_particle_link_fields_set(p0," key2,key9 , key1,key10 ");
+ acc = eina_array_accessor_new(p0->link_fields);
+ eina_accessor_data_get(acc,0,&p);
+ check_str("key2",(char*)p,"eiotas_particle_link_fields_set");
+ eina_accessor_data_get(acc,1,&p);
+ check_str("key9",(char*)p,"eiotas_particle_link_fields_set");
+ eina_accessor_data_get(acc,2,&p);
+ check_str("key1",(char*)p,"eiotas_particle_link_fields_set");
+ eina_accessor_data_get(acc,3,&p);
+ check_str("key10",(char*)p,"eiotas_particle_link_fields_set");
+ check_cond((eina_accessor_data_get(acc,4,&p)==EINA_FALSE),"!!!!! eina_accessor_data_get should fail");;
+
+
+ check_cond((p0->link_value==NULL),"!!!!! link_value should be NULL");;
+
+ eiotas_particle_data_set(p0,"key0","val0");
+ check_cond((p0->link_value==NULL),"!!!!! link_value should be NULL");;
+ eiotas_particle_data_set(p0,"key1","val1");
+ check_str((char*)p0->link_value,"val1","!!!!! link_value is wrong");;
+ eiotas_particle_data_set(p0,"key2","val2");
+ check_str((char*)p0->link_value,"val2val1","!!!!! link_value is wrong");;
+ eiotas_particle_data_set(p0,"key3","val3");
+ check_str((char*)p0->link_value,"val2val1","!!!!! link_value is wrong");;
+
+ if(strcmp(eiotas_particle_data_get(p0,"key0"),"val0")!=0) fprintf(stderr,"ERROR\n");
+ if(strcmp(eiotas_particle_data_get(p0,"key1"),"val1")!=0) fprintf(stderr,"ERROR\n");
+ if(strcmp(eiotas_particle_data_get(p0,"key2"),"val2")!=0) fprintf(stderr,"ERROR\n");
+ if(strcmp(eiotas_particle_data_get(p0,"key3"),"val3")!=0) fprintf(stderr,"ERROR\n");
+
+ eiotas_particle_data_del(p0,"key0");
+ if(eiotas_particle_data_get(p0,"key0")!=NULL) fprintf(stderr,"ERROR\n");
+ check_str((char*)p0->link_value,"val2val1","!!!!! link_value is wrong");;
+ eiotas_particle_data_del(p0,"key2");
+ if(eiotas_particle_data_get(p0,"key2")!=NULL) fprintf(stderr,"ERROR\n");
+ check_str((char*)p0->link_value,"val1","!!!!! link_value is wrong");;
+
+ p1 = eiotas_require_particle(dom0);
+ p2 = eiotas_require_particle(dom0);
+ p3 = eiotas_require_particle(dom0);
+ p4 = eiotas_require_particle(dom0);
+ eiotas_particle_merge(p0,p1);
+ eiotas_particle_merge(p0,p2);
+ eiotas_particle_merge(p2,p3);
+ eiotas_particle_merge(p2,p4);
+
+ eiotas_particle_free(p0);
+
+ eiotas_spin_free(dom0);
+}
+
diff --git a/tests/spin.c b/tests/spin.c
new file mode 100644
index 0000000..5f80a21
--- /dev/null
+++ b/tests/spin.c
@@ -0,0 +1,46 @@
+
+#include "helper.h"
+
+void test_spin()
+{
+ int i;
+ Eiotas_Particle *p0, *p1, *p2;
+
+ /* add spin */
+ Eiotas_Spin *dom0 = eiotas_spin_add("dom0",10);
+ eiotas_iota_show((Eiotas_Iota*)dom0);
+
+ /* particle require/release */
+ p0 = eiotas_spin_require_particle(dom0);
+ p1 = eiotas_spin_require_particle(dom0);
+
+ eiotas_spin_release_particle(dom0,p0);
+ eiotas_spin_release_particle(dom0,p1);
+ p2 = eiotas_spin_require_particle(dom0);
+ check_cond((p2==p1),"Particle require fail\n");
+
+ eiotas_release_particle(dom0,p2);
+
+ /* particle send(sys) */
+ p0 = eiotas_spin_require_particle(dom0);
+ p1 = eiotas_spin_require_particle(dom0);
+ eiotas_spin_send_particle(dom0,p0,EINA_FALSE);
+ eiotas_spin_send_particle(dom0,p1,EINA_TRUE);
+
+ /* add rooms */
+ Eiotas_Room *room = &dom0->room;
+ char name[8];
+ for(i=0; i<5; i++) {
+ sprintf(name,"room%d",i);
+ Eiotas_Room *tmp = eiotas_room_add(name,room);
+ if(tmp!=NULL) {
+ room = tmp;
+ eiotas_iota_show((Eiotas_Iota*)room); // MACROS
+ }
+ }
+ room = eiotas_room_add("room0",&dom0->room);
+ check_cond(room==NULL,"room0 should already exists");
+
+ eiotas_spin_free(dom0);
+}
+
diff --git a/tests/user_door.c b/tests/user_door.c
new file mode 100644
index 0000000..7a7c705
--- /dev/null
+++ b/tests/user_door.c
@@ -0,0 +1,55 @@
+
+#include "helper.h"
+
+typedef struct {
+ char txt[32];
+ int idx;
+} Input;
+
+static int free_called = 0;
+
+static Input* input_create(char *txt)
+{
+ Input *input = (Input*)malloc(sizeof(Input));
+ strncpy(input->txt,txt,32);
+ input->txt[31] = '\0';
+ input->idx = 0;
+ return input;
+}
+
+static void input_free(Input *input)
+{
+ EINA_LOG_DOM_DBG(_eiotas_log_dom,"free Input\n");
+ free(input);
+ free_called = 1;
+}
+
+static void input_show(Input *input)
+{
+ EINA_LOG_DOM_DBG(_eiotas_log_dom,"Input [%d] %s\n",input->idx,input->txt);
+}
+
+static void input_receive(const Eiotas_Door *door, Eiotas_Particle *particle, Eiotas_User_Data *data)
+{
+ EINA_LOG_DOM_DBG(_eiotas_log_dom,"input_receive 0x%X\n",PRINTPTR(data));
+}
+
+void test_user_door()
+{
+ Eiotas_Spin *dom0 = eiotas_spin_add("dom0",10);
+
+ Input *input = input_create("hello world");
+ input_show(input);
+
+ Eiotas_User_Bits user_bits;
+
+ user_bits.data = input;
+ user_bits.free_fct = (Eiotas_User_Data_Free)&input_free;
+ user_bits.recv_fct = (Eiotas_Receive_Particle)&input_receive;
+ Eiotas_Door *din0 = eiotas_door_add("input0",&dom0->room,&user_bits);
+ eiotas_iota_show(&din0->iota); // eiotas_iota_show((Eiotas_Iota*)din0);
+
+ eiotas_spin_free(dom0);
+ check_cond((free_called==1),"input_free not called");
+}
+