break
[vlc/multisubs.git] / test / native / gc.c
blobf52263ad6c1025d3631d965935e5834a7d909601
1 #include "../pyunit.h"
2 #ifdef HAVE_CONFIG_H
3 # include "config.h"
4 #endif
6 #include <vlc/vlc.h>
8 struct mygc
10 VLC_GC_MEMBERS;
11 int i;
14 typedef struct mygc mygc;
16 static void mygc_destructor( gc_object_t *p_gc )
18 free( p_gc );
19 p_gc = NULL;
22 static PyObject *gc_test( PyObject *self, PyObject *args )
24 mygc *gc = (mygc *)malloc( sizeof( mygc ) );
26 vlc_gc_init( gc, mygc_destructor, NULL );
27 ASSERT( gc->i_gc_refcount == 0, "Refcount should be 0" );
28 vlc_gc_incref( gc );
29 ASSERT( gc->i_gc_refcount == 1, "Refcount should be 1" );
30 vlc_gc_incref( gc );
31 ASSERT( gc->i_gc_refcount == 2, "Refcount should be 2" );
32 gc->i++;
33 vlc_gc_decref( gc );
34 ASSERT( gc->i_gc_refcount == 1, "Refcount should be 1" );
35 vlc_gc_decref( gc );
37 Py_INCREF( Py_None );
38 return Py_None;
41 static PyMethodDef native_gc_test_methods[] = {
42 DEF_METHOD( gc_test, "Test GC" )
43 { NULL, NULL, 0, NULL }
46 asserts = 0;
48 DECLARE_MODULE( native_gc_test )