/simpletypesystem/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk
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
#include "../libssts/SimpleTypeSystem.h"
#include "callback.h"
#include "test_macros.h"

int
test_callback_test_func1 (SObject * obj, spointer user_data) {
  return 2;
}

spointer
test_callback_test_func2 (SObject * obj, sint * output) {
  s_print ("Hello from the callback!\n");
  *output = 1337;
  return NULL;
}

enum {
  TEST_CALLBACK1,
  TEST_CALLBACK2,
  TEST_CALLBACK_END
};

static SCallbackEntry * callback_entries[] = {NULL,};

int
test_callback (void) {
  setup_unit ();

  SObject * obj = s_object_new ();

  callback_entries[TEST_CALLBACK1] =
    s_callback_entry_new ("test1",
                          test_callback_test_func1,
                          S_CALLBACK_CALLBACK);

  callback_entries[TEST_CALLBACK2] =
    s_callback_entry_new ("test2",
                          CALLBACK(test_callback_test_func2)  ,
                          S_CALLBACK_CALLBACK);

  s_object_install_callbacks (obj, TEST_CALLBACK_END, callback_entries);

  test_case (s_object_notify (obj, "test1", NULL) == 2,
            "the output from the callback is the expected value");

  sint * output = s_malloc (sizeof (sint));

  s_object_notify (obj, "test2", (spointer)output);

  test_case (*output != NULL, "The value that was givef vida the user_data"
                              " pointer is not null");

  test_case (*output == 1337, "The value that was given via the"
                              " user_data pointer has the corret"
                              " value");
  s_free (output);

  s_object_free (obj);

  end_unit ();
}