summaryrefslogtreecommitdiff
path: root/src/tests/eolian_cxx/eolian_cxx_test_callback.cc
blob: 81b6ac569b6e2b685a904f4ccf2edf45a0239b6b (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include <Eo.h>
#include <Ecore.h>

#include <callback.eo.hh>

#include <check.h>

void foo(void*) {}

START_TEST(eolian_cxx_test_callback_constructor)
{
  efl::eo::eo_init i;

  bool called1 = false, called2 = false;
  ::callback c1 (std::bind([&called1] { called1 = true; }));
  ::callback c2 (std::bind([&called2] { called2 = true; }), &foo);
  fail_if(!called1);
  fail_if(!called2);
}
END_TEST

START_TEST(eolian_cxx_test_callback_method)
{
  efl::eo::eo_init i;

  callback c;

  bool called1 = false, called2 = false;

  c.onecallback(std::bind([&called1] { called1 = true; }));
  c.twocallback(std::bind([&called2] { called2 = true; }), &foo);

  fail_if(!called1);
  fail_if(!called2);
}
END_TEST

START_TEST(eolian_cxx_test_callback_event_add)
{
  efl::eo::eo_init i;

  callback c;

  bool called1 = false, called2 = false;


  c.callback_call_on_add_add(std::bind([&called1] { called1 = true; }));
  c.callback_call_on_add_add(std::bind([&called2] { called2 = true; }));

  fail_if(!called1);
  fail_if(!called2);
}
END_TEST

START_TEST(eolian_cxx_test_callback_event_del)
{
  efl::eo::eo_init i;

  callback c;

  int called1 = 0, called2 = 0, called3 = 0, called4 = 0;

  efl::eo::signal_connection s1 = c.callback_call_on_add_add
    (std::bind([&]
     {
       std::cerr << "called1 " << called1 << " called2 " << called2 << " called3 " << called3
                 << " called4 " << called4 << " 1" << std::endl;
       fail_if(!(    (called1 == 0 && called2 == 0 && called3 == 0 && called4 == 0)
                  || (called1 == 1 && called2 == 1 && called3 == 0 && called4 == 0)
               ));
       ++called1;
     }));
  efl::eo::signal_connection s2 = c.callback_call_on_add_add
    (std::bind([&]
     {
       std::cerr << "called1 " << called1 << " called2 " << called2 << " called3 " << called3
                 << " called4 " << called4 << " 2" << std::endl;
       fail_if(!(    (called1 == 1 && called2 == 0 && called3 == 0 && called4 == 0)
                  || (called1 == 1 && called2 == 1 && called3 == 0 && called4 == 0)
                  || (called1 == 2 && called2 == 1 && called3 == 1 && called4 == 0)
              ));
       ++called2;
     }));

  s1.disconnect();

  c.callback_call_on_add_add
    (
     std::bind([&]
     {
       std::cerr << "called1 " << called1 << " called2 " << called2 << " called3 " << called3
                 << " called4 " << called4 << " 3" << std::endl;
       fail_if(!(    (called1 == 2 && called2 == 1 && called3 == 0 && called4 == 0)
                  || (called1 == 2 && called2 == 2 && called3 == 1 && called4 == 1)
              ));
       ++called3;
     }));

  s2.disconnect();

  c.callback_call_on_add_add
    (
     std::bind([&]
     {
       std::cerr << "called1 " << called1 << " called2 " << called2 << " called3 " << called3
                 << " called4 " << called4 << " 4" << std::endl;
       fail_if(!(    (called1 == 2 && called2 == 2 && called3 == 1 && called4 == 0)
              ));
       ++called4;
     }));
  
  fail_if(called1 != 2);
  fail_if(called2 != 2);
  fail_if(called3 != 2);
  fail_if(called4 != 1);
}
END_TEST

void
eolian_cxx_test_callback(TCase* tc)
{
   tcase_add_test(tc, eolian_cxx_test_callback_constructor);
   tcase_add_test(tc, eolian_cxx_test_callback_method);
   tcase_add_test(tc, eolian_cxx_test_callback_event_add);
   tcase_add_test(tc, eolian_cxx_test_callback_event_del);
}