static void test_log_proto_text_server_multi_read_not_allowed(void) { /* FIXME: */ #if 0 LogProtoServer *proto; proto = construct_test_proto( log_transport_mock_records_new( "foobar\n", -1, /* no EOL, proto implementation would read another chunk */ "foobaz", -1, LTM_INJECT_ERROR(EIO), LTM_EOF)); ((LogProtoBufferedServer *) proto)->no_multi_read = TRUE; assert_proto_server_fetch_single_read(proto, "foobar", -1); /* because of EAGAIN */ assert_proto_server_fetch_single_read(proto, NULL, -1); /* because of NOMREAD, partial lines are returned as empty */ assert_proto_server_fetch_single_read(proto, NULL, -1); /* because of EAGAIN */ assert_proto_server_fetch_single_read(proto, NULL, -1); /* error was detected by this time, partial line is returned before the error */ assert_proto_server_fetch_single_read(proto, "foobaz", -1); /* finally the error is returned too */ assert_proto_server_fetch_failure(proto, LPS_ERROR, NULL); log_proto_server_free(proto); #endif }
static void test_log_proto_text_server_is_not_fetching_input_as_long_as_there_is_an_eol_in_buffer(void) { LogProtoServer *proto; accumulate_seq = 0; proto = construct_test_proto_with_accumulator( accumulator_delay_lines, log_transport_mock_records_new( /* should the LogProto instance read ahead, it gets an * EIO error */ "foo\n" "bar\n" "baz\n" "booz\n", -1, LTM_INJECT_ERROR(EIO), LTM_EOF)); assert_proto_server_fetch(proto, "foo", -1); assert_proto_server_fetch(proto, "bar", -1); assert_proto_server_fetch(proto, "baz", -1); assert_proto_server_fetch(proto, "booz", -1); assert_proto_server_fetch_failure(proto, LPS_ERROR, NULL); log_proto_server_free(proto); }
static void test_log_proto_base(void) { LogProtoServer *proto; assert_gint(log_proto_get_char_size_for_fixed_encoding("iso-8859-2"), 1, NULL); assert_gint(log_proto_get_char_size_for_fixed_encoding("ucs-4"), 4, NULL); log_proto_server_options_set_encoding(&proto_server_options, "ucs-4"); proto = log_proto_binary_record_server_new( log_transport_mock_records_new( /* ucs4, terminated by record size */ "\x00\x00\x00\xe1\x00\x00\x00\x72\x00\x00\x00\x76\x00\x00\x00\xed" /* |...á...r...v...í| */ "\x00\x00\x00\x7a\x00\x00\x00\x74\x00\x00\x01\x71\x00\x00\x00\x72", 32, /* |...z...t...ű...r| */ LTM_EOF), get_inited_proto_server_options(), 32); /* check if error state is not forgotten unless reset_error is called */ proto->status = LPS_ERROR; assert_proto_server_status(proto, proto->status , LPS_ERROR); assert_proto_server_fetch_failure(proto, LPS_ERROR, NULL); log_proto_server_reset_error(proto); assert_proto_server_fetch(proto, "árvíztűr", -1); assert_proto_server_status(proto, proto->status, LPS_SUCCESS); log_proto_server_free(proto); log_proto_server_options_destroy(&proto_server_options); }
Test(log_proto, test_log_proto_framed_server_too_long_line_trimmed_frame_at_the_end) { LogProtoServer *proto; /* - accepting one normal sized message, which fills the buffer partially * - receiving a message which has to be trimmed * -> despite we have one part of the message in the buffer, * we had to memmove it so we can read one 'max_msg_size' message * - consume the end of the trimmed message, but the trimming will already read the * first character of the next 'frame length'. * -> need to memmove the partial data, so we can read the 'frame length' properly * - checking with a normal message, that the buffer is still handled correctly */ proto_server_options.max_msg_size = 8; proto_server_options.trim_large_messages = TRUE; proto = log_proto_framed_server_new( log_transport_mock_records_new( "3 01\n15 ", -1, "1abcdefg", -1, "12345674", -1, " 2abc", -1, LTM_EOF), get_inited_proto_server_options()); assert_proto_server_fetch(proto, "01\n", 3); assert_proto_server_fetch(proto, "1abcdefg", 8); // dropping: 1234567 assert_proto_server_fetch(proto, "2abc", 4); assert_proto_server_fetch_failure(proto, LPS_EOF, NULL); log_proto_server_free(proto); }
Test(log_proto, test_log_proto_framed_server_message_exceeds_buffer) { LogProtoServer *proto; /* should cause the buffer to be extended, shifted, as the first message * resizes the buffer to 16+10 == 26 bytes. */ proto_server_options.max_msg_size = 32; proto = log_proto_framed_server_new( log_transport_mock_records_new( "16 0123456789ABCDE\n16 0123456789ABCDE\n", -1, LTM_EOF), get_inited_proto_server_options()); assert_proto_server_fetch(proto, "0123456789ABCDE\n", -1); assert_proto_server_fetch(proto, "0123456789ABCDE\n", -1); log_proto_server_free(proto); }
static void test_log_proto_text_server_eol_before_eof(void) { LogProtoServer *proto; proto = construct_test_proto( log_transport_mock_records_new( /* eol before EOF */ "01234\n567\n890\n", -1, LTM_INJECT_ERROR(EIO), LTM_EOF)); assert_proto_server_fetch(proto, "01234", -1); assert_proto_server_fetch(proto, "567", -1); assert_proto_server_fetch(proto, "890", -1); assert_proto_server_fetch_failure(proto, LPS_ERROR, NULL); log_proto_server_free(proto); }
static void test_log_proto_text_server_multi_read(void) { LogProtoServer *proto; proto = construct_test_proto( log_transport_mock_records_new( "foobar\n", -1, /* no EOL, proto implementation would read another chunk */ "foobaz", -1, LTM_INJECT_ERROR(EIO), LTM_EOF)); assert_proto_server_fetch(proto, "foobar", -1); assert_proto_server_fetch(proto, "foobaz", -1); assert_proto_server_fetch_failure(proto, LPS_ERROR, NULL); log_proto_server_free(proto); }
Test(log_proto, test_log_proto_framed_server_buffer_shift_to_make_space_for_a_frame) { LogProtoServer *proto; /* this testcase fills the initially 10 byte buffer with data, which * causes a shift in log_proto_framed_server_fetch() */ proto_server_options.max_msg_size = 32; proto_server_options.init_buffer_size = 10; proto_server_options.max_buffer_size = 10; proto = log_proto_framed_server_new( log_transport_mock_records_new( "6 01234\n4 ", 10, "123\n", -1, LTM_EOF), get_inited_proto_server_options()); assert_proto_server_fetch(proto, "01234\n", -1); assert_proto_server_fetch(proto, "123\n", -1); log_proto_server_free(proto); }
Test(log_proto, test_log_proto_framed_server_multi_read) { LogProtoServer *proto; proto_server_options.max_msg_size = 32; proto = log_proto_framed_server_new( log_transport_mock_records_new( "7 foobar\n", -1, /* no EOL, proto implementation would read another chunk */ "6 fooba", -1, LTM_INJECT_ERROR(EIO), LTM_EOF), get_inited_proto_server_options()); assert_proto_server_fetch(proto, "foobar\n", -1); /* with multi-read, we get the injected failure at the 2nd fetch */ assert_proto_server_fetch_failure(proto, LPS_ERROR, "Error reading RFC6587 style framed data"); log_proto_server_free(proto); /* NOTE: LPBS_NOMREAD is not implemented for framed protocol */ }
Test(log_proto, test_log_proto_framed_server_too_long_line_trimmed_multiple_cycles) { LogProtoServer *proto; /* - accepting one normal sized message * - trimming a "multi buffer size" message * - checking with a normal message, that the buffer is still handled correctly. */ proto_server_options.max_msg_size = 2; proto_server_options.trim_large_messages = TRUE; proto = log_proto_framed_server_new( log_transport_mock_records_new( "1 0", -1, "7 1abcdef", -1, "1 2", -1, LTM_EOF), get_inited_proto_server_options()); assert_proto_server_fetch(proto, "0", 1); assert_proto_server_fetch(proto, "1a", 2); assert_proto_server_fetch(proto, "2", 1); assert_proto_server_fetch_failure(proto, LPS_EOF, NULL); log_proto_server_free(proto); }