
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/resource.h>

#include <gst/gst.h>

/* Expect this to core something with a stack like this

Program received signal SIGSEGV, Segmentation fault.
g_source_attach (source=source@entry=0x0, context=0x0) at /build/glib2.0-MuyBSS/glib2.0-2.46.2/./glib/gmain.c:1163
1163	/build/glib2.0-MuyBSS/glib2.0-2.46.2/./glib/gmain.c: No such file or directory.
(gdb) bt
#0  0x00007ffff6da6b24 in g_source_attach (source=source@entry=0x0, context=0x0) at /build/glib2.0-MuyBSS/glib2.0-2.46.2/./glib/gmain.c:1163
#1  0x00007ffff7aee728 in gst_bus_add_watch_full_unlocked (bus=<optimised out>, priority=<optimised out>, func=0x400936 <callback>, user_data=0x0, notify=0x0) at gstbus.c:902
#2  0x00007ffff7aee850 in gst_bus_add_watch_full (bus=0x630060 [GstBus], priority=0, func=0x400936 <callback>, user_data=0x0, notify=0x0)
    at gstbus.c:953
#3  0x00000000004009fb in main (argc=1, argv=0x7fffffffbb48) at test-gstbus.c:34

*/


static gboolean callback(GstBus *bus, GstMessage *message, gpointer user_data)
{
	printf("Callback\n");
}

int main(int argc, char **argv)
{
	struct rlimit limit = {3, 3};
	gst_init(&argc, &argv);
	
	if (setrlimit(RLIMIT_NOFILE, &limit) < 0)
	{
		perror("setrlimit");
		exit(EXIT_FAILURE);
	}
	
	GstBus *bus = gst_bus_new();
	if (bus == NULL)
	{
		printf("gst_bus_new failed\n");
		exit(EXIT_SUCCESS);
	}

	//Expect core on the gst_bus_add_watch
	if (gst_bus_add_watch(bus, callback, NULL) == 0)
	{
		printf("gst_bus_add_watch failed\n");
		exit(EXIT_SUCCESS);
	}
	else
	{
		printf("gst_bus_add_watch worked\n"); //Test Failed to detect problem
	}

	gst_object_unref(bus);
	return 0;
}

