예제 #1
0
파일: ndc-test.c 프로젝트: yixiaoyang/log4g
void
test_001(gpointer *fixture, gconstpointer data)
{
	log4g_ndc_push("foo");
	g_assert_cmpstr(log4g_ndc_peek(), == , "foo");
	g_assert_cmpstr(log4g_ndc_get(), ==, "foo");
	log4g_ndc_push("bar");
	g_assert_cmpstr(log4g_ndc_peek(), == , "bar");
	g_assert_cmpstr(log4g_ndc_get(), ==, "foo bar");
	log4g_ndc_push("baz");
	g_assert_cmpstr(log4g_ndc_peek(), == , "baz");
	g_assert_cmpstr(log4g_ndc_get(), ==, "foo bar baz");
	const gchar *string = log4g_ndc_pop();
	g_assert(string);
	g_assert_cmpstr(string, ==, "baz");
	g_assert_cmpstr(log4g_ndc_get(), ==, "foo bar");
	string = log4g_ndc_pop();
	g_assert(string);
	g_assert_cmpstr(string, ==, "bar");
	g_assert_cmpstr(log4g_ndc_get(), ==, "foo");
	string = log4g_ndc_pop();
	g_assert(string);
	g_assert_cmpstr(string, ==, "foo");
	g_assert(log4g_ndc_get() == NULL);
}
예제 #2
0
파일: ndc-test.c 프로젝트: yixiaoyang/log4g
void
test_003(gpointer *fixture, gconstpointer data)
{
	log4g_ndc_push("foo");
	log4g_ndc_push("bar");
	log4g_ndc_push("baz");
	g_assert(log4g_ndc_size() == 3);
	g_assert_cmpstr(log4g_ndc_get(), ==, "foo bar baz");
	log4g_ndc_set_max_depth(1);
	g_assert(log4g_ndc_size() == 1);
	g_assert_cmpstr(log4g_ndc_get(), ==, "foo");
}
예제 #3
0
파일: ndc-test.c 프로젝트: yixiaoyang/log4g
void
test_002(gpointer *fixture, gconstpointer data)
{
	log4g_ndc_push("foo");
	log4g_ndc_push("bar");
	log4g_ndc_push("baz");
	g_assert(log4g_ndc_size() == 3);
	g_assert_cmpstr(log4g_ndc_get(), ==, "foo bar baz");
	log4g_ndc_clear();
	g_assert(log4g_ndc_size() == 0);
	g_assert(log4g_ndc_get() == NULL);
}
예제 #4
0
파일: ndc-test.c 프로젝트: yixiaoyang/log4g
void
test_004(gpointer *fixture, gconstpointer data)
{
	log4g_ndc_push("foo");
	log4g_ndc_push("bar");
	log4g_ndc_push("baz");
	g_assert(log4g_ndc_size() == 3);
	g_assert_cmpstr(log4g_ndc_get(), ==, "foo bar baz");
	GArray *ndc = log4g_ndc_clone();
	g_assert(ndc);
	log4g_ndc_remove();
	log4g_ndc_inherit(ndc);
	g_assert(log4g_ndc_size() == 3);
	g_assert_cmpstr(log4g_ndc_get(), ==, "foo bar baz");
}
예제 #5
0
void
test_001(gpointer *fixture, gconstpointer data)
{
	GType type = g_type_from_name("Log4gCouchdbAppender");
	g_assert(type);
	Log4gAppender *appender = g_object_new(type, "database-name",
			"couchdb_appender_test", NULL);
	g_assert(appender);
	log4g_appender_activate_options(appender);
	va_list ap;
	memset(&ap, 0, sizeof ap);
	for (gint i = 0; i < 5; ++i) {
		log4g_mdc_put("couchdb-appender-test", "test in loop %d", i);
		log4g_ndc_push("LOOP %d", i);
		Log4gLoggingEvent *event = log4g_logging_event_new(
				"org.gnome.test", log4g_level_DEBUG(),
				__func__, __FILE__, G_STRINGIFY(__LINE__),
				"test message", ap);
		g_assert(event);
		log4g_appender_do_append(appender, event);
		g_object_unref(event);
		usleep(20);
	}
	g_object_unref(appender);
}
예제 #6
0
void
test_001(gpointer *fixture, gconstpointer data)
{
	GType type = g_type_from_name("Log4gSimpleLayout");
	g_assert(type);
	Log4gLayout *layout = g_object_new(type, NULL);
	g_assert(layout);
	log4g_layout_activate_options(layout);
	type = g_type_from_name("Log4gSyslogAppender");
	g_assert(type);
	Log4gAppender *appender = g_object_new(type,
			"ident", "syslog-appender-test",
			"option", LOG_USER,
			"facility", LOG_CONS,
			NULL);
	g_assert(appender);
	log4g_appender_set_layout(appender, layout);
	log4g_appender_activate_options(appender);
	g_object_unref(layout);
	for (gint i = 0; i < 5; ++i) {
		log4g_ndc_push("LOOP %d", i);
		va_list ap;
		memset(&ap, 0, sizeof ap);
		Log4gLoggingEvent *event = log4g_logging_event_new(
				"org.gnome.test", log4g_level_INFO(),
				__func__, __FILE__, G_STRINGIFY(__LINE__),
				"test message", ap);
		g_assert(event);
		log4g_appender_do_append(appender, event);
		g_object_unref(event);
		usleep(20);
	}
	g_object_unref(appender);
}
예제 #7
0
void
setup(Fixture *fixture, G_GNUC_UNUSED gconstpointer data)
{
	log4g_mdc_put("foo", "bar");
	log4g_ndc_push("baz");
	va_list ap;
	memset(&ap, 0, sizeof ap);
	fixture->event = log4g_logging_event_new("org.gnome.test",
			log4g_level_DEBUG(), __func__, __FILE__,
			G_STRINGIFY(__LINE__), "foo bar baz", ap);
	g_assert(fixture->event);
}
예제 #8
0
void
test_001(G_GNUC_UNUSED gpointer *fixture, G_GNUC_UNUSED gconstpointer data)
{
	GType type = g_type_from_name("Log4gHTMLLayout");
	g_assert(type);
	Log4gLayout *layout = g_object_new(type,
			"title", "Hello, World!",
			"location-info", TRUE,
			NULL);
	g_assert(layout);
	log4g_layout_activate_options(layout);
	type = g_type_from_name("Log4gFileAppender");
	g_assert(type);
	Log4gAppender *appender = g_object_new(type,
			"file", "tests/file-appender-test.html",
			"append", FALSE,
			"buffered-io", TRUE,
			NULL);
	g_assert(appender);
	log4g_appender_set_layout(appender, layout);
	log4g_appender_activate_options(appender);
	g_object_unref(layout);
	va_list ap;
	memset(&ap, 0, sizeof ap);
	for (gint i = 0; i < 5; ++i) {
		log4g_ndc_push("LOOP %d", i);
		Log4gLoggingEvent *event = log4g_logging_event_new(
				"org.gnome.test", log4g_level_DEBUG(),
				__func__, __FILE__, G_STRINGIFY(__LINE__),
				"test message", ap);
		g_assert(event);
		log4g_appender_do_append(appender, event);
		g_object_unref(event);
		usleep(20);
	}
	g_object_unref(appender);
}