summaryrefslogtreecommitdiff
path: root/src/tests/ecore/ecore_test_coroutine.c
blob: 8d807375bea95e271c6cb2a40e8dca809d7dd01d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include <stdio.h>
#include <unistd.h>

#include <Eina.h>
#include <Ecore.h>

#include "ecore_suite.h"

typedef struct _Ecore_Coroutine_Test Ecore_Coroutine_Test;
struct _Ecore_Coroutine_Test
{
   unsigned int v;
   unsigned int s;
};

static Ecore_Coroutine_Test t1;

static int
_ecore_test_v1(void *data, Ecore_Coroutine *coro)
{
   int *t = data;

   ecore_coroutine_yield(coro, 7);
   t1.v = *t;
   ecore_coroutine_yield(coro, 42);
   t1.s = *t;

   return 0xDEADBEEF;
}

static int
_ecore_test_v2(void *data, Ecore_Coroutine *coro EINA_UNUSED)
{
   int *t = data;

   ecore_coroutine_yield(coro, 42);
   t1.v = *t;
   ecore_coroutine_yield(coro, 7);
   t1.s = *t;

   return 0xDEADBEEF;
}

START_TEST(ecore_test_coroutine_simple)
{
   Ecore_Coroutine *coro1;
   Ecore_Coroutine *coro2;
   unsigned int value[] = { 7, 42, 0xDEADBEEF };

   ecore_init();

   t1.v = 0xDEADBEEF; t1.s = 0xDEADBEEF;

   coro1 = ecore_coroutine_add(0, _ecore_test_v1, &value[0]);
   coro2 = ecore_coroutine_add(4*1024*1024, _ecore_test_v2, &value[1]);

   fail_if(ecore_coroutine_state_get(coro1) != ECORE_COROUTINE_NEW);
   fail_if(ecore_coroutine_resume(coro1) != 7);
   fail_if(t1.v != 0xDEADBEEF || t1.s != 0xDEADBEEF);
   fail_if(ecore_coroutine_resume(coro2) != 42);
   fail_if(t1.v != 0xDEADBEEF || t1.s != 0xDEADBEEF);
   fail_if(ecore_coroutine_resume(coro1) != 42);
   fail_if(t1.v != value[0] || t1.s != 0xDEADBEEF);
   fail_if((unsigned int) ecore_coroutine_resume(coro1) != 0xDEADBEEF);
   fail_if(t1.v != value[0] || t1.s != value[0]);
   fail_if(ecore_coroutine_resume(coro2) != 7);
   fail_if(t1.v != value[1] || t1.s != value[0]);
   fail_if((unsigned int) ecore_coroutine_resume(coro2) != 0xDEADBEEF);
   fail_if(t1.v != value[1] || t1.s != value[1]);
   fail_if(ecore_coroutine_state_get(coro2) != ECORE_COROUTINE_FINISHED);

   fail_if(ecore_coroutine_del(coro1) != &value[0]);
   fail_if(ecore_coroutine_del(coro2) != &value[1]);

   ecore_shutdown();
}
END_TEST

void ecore_test_coroutine(TCase *tc)
{
  tcase_add_test(tc, ecore_test_coroutine_simple);
}