void assert_proto_server_fetch_single_read(LogProtoServer *proto, const gchar *expected_msg, gssize expected_msg_len) { const guchar *msg = NULL; gsize msg_len = 0; LogProtoStatus status; LogTransportAuxData aux; Bookmark bookmark; gboolean may_read = TRUE; start_grabbing_messages(); log_transport_aux_data_init(&aux); status = log_proto_server_fetch(proto, &msg, &msg_len, &may_read, &aux, &bookmark); assert_proto_server_status(proto, status, LPS_SUCCESS); if (expected_msg) { assert_nstring((const gchar *) msg, msg_len, expected_msg, expected_msg_len, "LogProtoServer expected message mismatch"); } else { assert_true(msg == NULL, "when single-read finds an incomplete message, msg must be NULL"); assert_true(aux.peer_addr == NULL, "returned saddr must be NULL on success"); } stop_grabbing_messages(); }
void test_format_hex_string_with_delimiter__two_bytes__perfect() { gchar expected_output[6] = "40 41"; gchar output[6]; gchar input[2] = "@A"; //Act format_hex_string_with_delimiter(input, sizeof(input), output, sizeof(output), ' '); //Assert assert_nstring(output, sizeof(output), expected_output, sizeof(expected_output), "format_hex_string_with_delimiter output does not match in case of two bytes!", NULL); }
void test_format_hex_string__single_byte__perfect() { gchar expected_output[3] = "40"; gchar output[3]; gchar input[1] = "@"; //Act format_hex_string(input, sizeof(input), output, sizeof(output)); //Assert assert_nstring(output, sizeof(output), expected_output, sizeof(expected_output), "format_hex_string output does not match!", NULL); }
void test_format_hex_string__two_bytes__perfect() { gchar expected_output[5] = "4041"; gchar output[5]; gchar input[2] = "@A"; //Act format_hex_string(input, sizeof(input), output, sizeof(output)); //Assert assert_nstring(output, sizeof(output), expected_output, sizeof(expected_output), "format_hex_string output does not match with two bytes!", NULL); }
static gboolean test_vp_value(const gchar *name, const gchar *prefix, TypeHint type, const gchar *value, gsize value_len, gpointer *prefix_data, gpointer user_data) { assert_string(prefix, "root.test", "Wrong prefix"); assert_nstring(value, value_len, "value", -1, "Wrong value"); assert_gint(*((gint*)(*prefix_data)), root_test_data, "Wrong prefix data"); return FALSE; }
void assert_proto_server_fetch(LogProtoServer *proto, const gchar *expected_msg, gssize expected_msg_len) { const guchar *msg = NULL; gsize msg_len = 0; LogProtoStatus status; status = proto_server_fetch(proto, &msg, &msg_len); assert_proto_server_status(proto, status, LPS_SUCCESS); assert_nstring((const gchar *) msg, msg_len, expected_msg, expected_msg_len, "LogProtoServer expected message mismatch"); }
static void testcase(gchar *msg, gchar *timezone, gchar *format, gchar *expected) { LogTemplate *templ; LogMessage *logmsg; LogParser *parser; gboolean success; GString *res = g_string_sized_new(128); parser = date_parser_new (configuration); if (format != NULL) date_parser_set_format(parser, format); if (timezone != NULL) date_parser_set_timezone(parser, timezone); log_pipe_init(&parser->super); logmsg = log_msg_new_empty(); logmsg->timestamps[LM_TS_RECVD].tv_sec = 1451473200; /* Dec 30 2015 */ log_msg_set_value(logmsg, log_msg_get_value_handle("MESSAGE"), msg, -1); success = log_parser_process(parser, &logmsg, NULL, log_msg_get_value(logmsg, LM_V_MESSAGE, NULL), -1); if (!success && expected) { fprintf(stderr, "unable to parse format=%s msg=%s\n", format, msg); exit(1); } else if (success && !expected) { fprintf(stderr, "successfully parsed but expected failure, format=%s msg=%s\n", format, msg); exit(1); } else if (expected) { /* Convert to ISODATE */ templ = compile_template("${ISODATE}", FALSE); log_template_format(templ, logmsg, NULL, LTZ_LOCAL, -1, NULL, res); assert_nstring(res->str, res->len, expected, strlen(expected), "incorrect date parsed msg=%s format=%s", msg, format); log_template_unref(templ); } g_string_free(res, TRUE); log_pipe_unref(&parser->super); log_msg_unref(logmsg); return; }
static void testcase(gchar *msg, goffset offset, gchar *timezone, gchar *format, gchar *expected) { LogTemplate *templ; LogMessage *logmsg; NVTable *nvtable; GlobalConfig *cfg = cfg_new (0x302); LogParser *parser = date_parser_new (cfg); gboolean success; const gchar *context_id = "test-context-id"; GString *res = g_string_sized_new(128); date_parser_set_offset(parser, offset); if (format != NULL) date_parser_set_format(parser, format); if (timezone != NULL) date_parser_set_timezone(parser, timezone); parse_options.flags = 0; logmsg = log_msg_new_empty(); logmsg->timestamps[LM_TS_RECVD].tv_sec = 1438793384; /* Wed Aug 5 2015 */ log_msg_set_value(logmsg, log_msg_get_value_handle("MESSAGE"), msg, -1); nvtable = nv_table_ref(logmsg->payload); success = log_parser_process(parser, &logmsg, NULL, log_msg_get_value(logmsg, LM_V_MESSAGE, NULL), -1); nv_table_unref(nvtable); if (!success) { fprintf(stderr, "unable to parse offset=%d format=%s msg=%s\n", offset, format, msg); exit(1); } /* Convert to ISODATE */ templ = compile_template("${ISODATE}", FALSE); log_template_format(templ, logmsg, NULL, LTZ_LOCAL, 999, context_id, res); assert_nstring(res->str, res->len, expected, strlen(expected), "incorrect date parsed msg=%s offset=%d format=%s", msg, offset, format); log_template_unref(templ); g_string_free(res, TRUE); log_pipe_unref(&parser->super); log_msg_unref(logmsg); return; }