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
|
#include "SimpleTypeSystem.h"
#include "test_macros.h"
int test_refcount (void) {
setup_unit();
SObject * obj = NULL;
obj = s_object_new ();
test_case (obj != NULL, "Object is not NULL.");
test_case (s_object_get_refcount (obj) == 1, "Start refcount == 1");
s_object_ref (obj);
test_case (s_object_get_refcount (obj) == 2, "Manual get of refcount. == 2");
test_case (s_object_ref (obj) == 3, "Get refcount from ref function. == 3");
s_print ("running ref 10 000 times on object\n");
for (size_t i = 0; i < 10000; i++) {
s_object_ref (obj);
}
s_print ("running unref 10 000 times on object\n");
for (size_t i = 0; i < 10000; i++) {
s_object_unref (obj);
}
test_case (s_object_get_refcount (obj) == 3, "refcount == 3");
test_case (s_object_unref (obj) == 2, "Get refcount from unref function. == 2");
s_print ("Skipping unref test.\n");
s_object_unref (obj);
test_case (s_object_unref (obj) == 0, "refcount == 0");
end_unit();
}
|