Eobj: Improved tests a bit.

SVN revision: 70137
This commit is contained in:
Tom Hacohen 2012-04-12 11:20:26 +00:00
parent d113debcd2
commit ef994b8163
5 changed files with 43 additions and 48 deletions

View File

@ -2,6 +2,8 @@
#include "simple.h"
#include "comp.h"
#include "../eunit_tests.h"
static int cb_called = EINA_FALSE;
static Eina_Bool
@ -29,18 +31,11 @@ main(int argc, char *argv[])
int a;
eobj_do(obj, SIMPLE_A_SET(1));
if (!cb_called)
{
printf("Error! %d\n", __LINE__);
return 1;
}
fail_if(!cb_called);
eobj_do(obj, SIMPLE_A_GET(&a));
if (a != 1)
{
printf("Error! %d\n", __LINE__);
return 1;
}
fail_if(a != 1);
eobj_unref(obj);
eobj_shutdown();

View File

@ -5,6 +5,8 @@
#include "simple4.h"
#include "mixin.h"
#include "../eunit_tests.h"
int my_init_count = 0;
int
@ -17,11 +19,7 @@ main(int argc, char *argv[])
Eobj *obj = eobj_add(SIMPLE_CLASS, NULL);
if (my_init_count != 2)
{
printf("Error! my_init_count == %d\n", my_init_count);
ret = 1;
}
fail_if(my_init_count != 2);
eobj_do(obj, SIMPLE_A_SET(1), SIMPLE_B_SET(2));
@ -30,42 +28,22 @@ main(int argc, char *argv[])
eobj_unref(obj);
if (my_init_count != 0)
{
printf("Error! my_init_count == %d\n", my_init_count);
ret = 1;
}
fail_if(my_init_count != 0);
obj = eobj_add(SIMPLE2_CLASS, NULL);
if (obj)
{
printf("Error! obj is supposed to be NULL.\n");
ret = 1;
}
fail_if(obj);
obj = eobj_add(SIMPLE3_CLASS, NULL);
if (obj)
{
printf("Error! obj is supposed to be NULL.\n");
ret = 1;
}
fail_if(obj);
my_init_count = 0;
obj = eobj_add(SIMPLE4_CLASS, NULL);
if (my_init_count != 2)
{
printf("Error! my_init_count == %d\n", my_init_count);
ret = 1;
}
fail_if(my_init_count != 2);
eobj_unref(obj);
if (my_init_count != 0)
{
printf("Error! my_init_count == %d\n", my_init_count);
ret = 1;
}
fail_if(my_init_count != 0);
eobj_shutdown();
return ret;

View File

@ -0,0 +1,17 @@
#ifndef _EUNIT_TESTS_H
#define _EUNIT_TESTS_H
#define _EUNIT_EXIT_CODE 1
#define fail_if(x) \
do { \
if (x) \
{ \
fprintf(stderr, "%s:%d - Failure '%s' is TRUE.", \
__FILE__, __LINE__, # x); \
exit(_EUNIT_EXIT_CODE); \
} \
} while (0)
#endif

View File

@ -4,6 +4,8 @@
#include "inherit2.h"
#include "inherit3.h"
#include "../eunit_tests.h"
int
main(int argc, char *argv[])
{
@ -15,20 +17,15 @@ main(int argc, char *argv[])
eobj_do(obj, SIMPLE_A_SET(1));
Simple_Public_Data *pd = eobj_data_get(obj, SIMPLE_CLASS);
if (pd->a != 2)
{
return 1;
}
fail_if(pd->a != 2);
eobj_unref(obj);
obj = eobj_add(INHERIT3_CLASS, NULL);
eobj_do(obj, SIMPLE_A_SET(1));
pd = eobj_data_get(obj, SIMPLE_CLASS);
if (pd->a != 3)
{
return 1;
}
fail_if(pd->a != 3);
eobj_unref(obj);

View File

@ -1,6 +1,10 @@
#include "Eobj.h"
#include "simple.h"
#include "../eunit_tests.h"
static int cb_count = 0;
static Eina_Bool
_a_changed_cb(void *data, Eobj *obj, const Eobj_Event_Description *desc, void *event_info)
{
@ -10,6 +14,8 @@ _a_changed_cb(void *data, Eobj *obj, const Eobj_Event_Description *desc, void *e
int new_a = *((int *) event_info);
printf("%s event_info:'%d' data:'%s'\n", __func__, new_a, (const char *) data);
cb_count++;
/* Fix data is NULL, stop. */
return !!data;
}
@ -33,6 +39,8 @@ main(int argc, char *argv[])
eobj_do(obj, SIMPLE_A_SET(1));
fail_if(cb_count != 3);
eobj_event_callback_del_full(obj, SIG_A_CHANGED, _a_changed_cb, NULL);
eobj_unref(obj);