/simpletypesystem/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk
109.1.1 by Gustav Hartvigsson
* SMap seems to be broken... Or could it be SObject's Callback stuff? Or SLinkedList?
1
#include "../libssts/SimpleTypeSystem.h"
2
#include "callback.h"
3
#include "test_macros.h"
4
5
int
6
test_callback_test_func1 (SObject * obj, spointer user_data) {
7
  return 2;
8
}
9
10
spointer
115 by Gustav Hartvigsson
*More tests to the test god!
11
test_callback_test_func2 (SObject * obj, sint * output) {
12
  s_print ("Hello from the callback!\n");
13
  *output = 1337;
109.1.1 by Gustav Hartvigsson
* SMap seems to be broken... Or could it be SObject's Callback stuff? Or SLinkedList?
14
  return NULL;
15
}
16
17
enum {
18
  TEST_CALLBACK1,
19
  TEST_CALLBACK2,
20
  TEST_CALLBACK_END
21
};
22
23
static SCallbackEntry * callback_entries[] = {NULL,};
24
109.1.3 by Gustav Hartvigsson
* just commiting for the sake of commiting
25
int
26
test_callback (void) {
109.1.1 by Gustav Hartvigsson
* SMap seems to be broken... Or could it be SObject's Callback stuff? Or SLinkedList?
27
  setup_unit ();
28
29
  SObject * obj = s_object_new ();
30
31
  callback_entries[TEST_CALLBACK1] =
32
    s_callback_entry_new ("test1",
33
                          test_callback_test_func1,
34
                          S_CALLBACK_CALLBACK);
35
36
  callback_entries[TEST_CALLBACK2] =
37
    s_callback_entry_new ("test2",
115 by Gustav Hartvigsson
*More tests to the test god!
38
                          CALLBACK(test_callback_test_func2)  ,
109.1.1 by Gustav Hartvigsson
* SMap seems to be broken... Or could it be SObject's Callback stuff? Or SLinkedList?
39
                          S_CALLBACK_CALLBACK);
40
109.1.8 by Gustav Hartvigsson
* Fixed SMap so the callbacks will work... What a single line of code can do..
41
  s_object_install_callbacks (obj, TEST_CALLBACK_END, callback_entries);
116.1.1 by Gustav Hartvigsson
* Implemented the SMainLoop
42
150 by Gustav Hartvigsson
* Fixed the tests in the CMake file
43
  test_case ((slong)s_object_notify (obj, "test1", NULL) == 2,
115 by Gustav Hartvigsson
*More tests to the test god!
44
            "the output from the callback is the expected value");
116.1.1 by Gustav Hartvigsson
* Implemented the SMainLoop
45
121.1.3 by Gustav Hartvigsson
* Made the GC switchable at rutime (once) when compiled with S_USE_GC set.
46
  sint * output = s_malloc (sizeof (sint));
116.1.1 by Gustav Hartvigsson
* Implemented the SMainLoop
47
115 by Gustav Hartvigsson
*More tests to the test god!
48
  s_object_notify (obj, "test2", (spointer)output);
116.1.1 by Gustav Hartvigsson
* Implemented the SMainLoop
49
150 by Gustav Hartvigsson
* Fixed the tests in the CMake file
50
  test_case (output !=  NULL, "The value that was givef vida the user_data"
116 by Gustav Hartvigsson
* woops
51
                              " pointer is not null");
116.1.1 by Gustav Hartvigsson
* Implemented the SMainLoop
52
115 by Gustav Hartvigsson
*More tests to the test god!
53
  test_case (*output == 1337, "The value that was given via the"
54
                              " user_data pointer has the corret"
55
                              " value");
121.1.3 by Gustav Hartvigsson
* Made the GC switchable at rutime (once) when compiled with S_USE_GC set.
56
  s_free (output);
116.1.1 by Gustav Hartvigsson
* Implemented the SMainLoop
57
109.1.1 by Gustav Hartvigsson
* SMap seems to be broken... Or could it be SObject's Callback stuff? Or SLinkedList?
58
  s_object_free (obj);
59
60
  end_unit ();
61
}