TEST_F( ExceptionTest, MessageOnly ) { ActiveRecordException e( "foo" ); assert_string( "foo", e.to_string() ); }
TEST_F( ExceptionTest, MessageAndFile ) { ActiveRecordException e( "foo", "/path/to/file.cpp" ); assert_string( "/path/to/file.cpp: foo", e.to_string() ); }
GString * test_command(GString *command) { assert_string(command->str,"test command", "Bad command handling"); return g_string_new("OK"); }
void testcase(gchar *msg, gint parse_flags, gchar *bad_hostname_re, gint expected_pri, unsigned long expected_stamp_sec, unsigned long expected_stamp_usec, unsigned long expected_stamp_ofs, const gchar *expected_host, const gchar *expected_program, const gchar *expected_msg, const gchar *expected_sd_str, const gchar *expected_pid, const gchar *expected_msgid, const gchar *expected_sd_pairs[][2]) { LogMessage *parsed_message; LogStamp *parsed_timestamp; time_t now; GString *sd_str; testcase_begin("Testing log message parsing; parse_flags='%x', bad_hostname_re='%s', msg='%s'", parse_flags, bad_hostname_re ? : "(null)", msg); parsed_message = parse_log_message(msg, parse_flags, bad_hostname_re); parsed_timestamp = &(parsed_message->timestamps[LM_TS_STAMP]); if (expected_stamp_sec) { if (expected_stamp_sec != 1) assert_guint(parsed_timestamp->tv_sec, expected_stamp_sec, "Unexpected timestamp"); assert_guint32(parsed_timestamp->tv_usec, expected_stamp_usec, "Unexpected microseconds"); assert_guint32(parsed_timestamp->zone_offset, expected_stamp_ofs, "Unexpected timezone offset"); } else { time(&now); assert_true(absolute_value(parsed_timestamp->tv_sec - now) <= 5, "Expected parsed message timestamp to be set to now; now='%d', timestamp->tv_sec='%d'", (gint)now, (gint)parsed_timestamp->tv_sec, NULL); } assert_guint16(parsed_message->pri, expected_pri, "Unexpected message priority"); assert_log_message_value(parsed_message, LM_V_HOST, expected_host); assert_log_message_value(parsed_message, LM_V_PROGRAM, expected_program); assert_log_message_value(parsed_message, LM_V_MESSAGE, expected_msg); if (expected_pid) assert_log_message_value(parsed_message, LM_V_PID, expected_pid); if (expected_msgid) assert_log_message_value(parsed_message, LM_V_MSGID, expected_msgid); if (expected_sd_str) { sd_str = g_string_sized_new(0); log_msg_format_sdata(parsed_message, sd_str, 0); assert_string(sd_str->str, expected_sd_str, "Unexpected formatted SData"); g_string_free(sd_str, TRUE); } assert_log_message_sdata_pairs(parsed_message, expected_sd_pairs); log_msg_unref(parsed_message); testcase_end(); }
void assert_ip6 (char *expected, struct sockaddr_storage *reality, char *msg) { char dst[255]; inet_ntop(AF_INET6, &((struct sockaddr_in6 *) reality)->sin6_addr, &dst[0], 255); assert_string(expected, dst, msg); }