Esempio n. 1
0
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
}
Esempio n. 2
0
LogProtoServer *
construct_test_proto_with_accumulator(gint (*accumulator)(LogProtoTextServer *, const guchar *, gsize, gssize), LogTransport *transport)
{
  LogProtoServer *proto = construct_test_proto(transport);

  ((LogProtoTextServer *) proto)->accumulate_line = accumulator;
  return proto;
}
Esempio n. 3
0
static void
test_log_proto_text_server_no_encoding(gboolean input_is_stream)
{
    LogProtoServer *proto;

    proto = construct_test_proto(
                /* 32 bytes max line length */
                (input_is_stream ? log_transport_mock_stream_new : log_transport_mock_records_new)(
                    "01234567\n"
                    /* line too long */
                    "0123456789ABCDEF0123456789ABCDEF01234567\n"
                    /* utf8 */
                    "árvíztűrőtükörfúrógép\n"
                    /* iso-8859-2 */
                    "\xe1\x72\x76\xed\x7a\x74\xfb\x72\xf5\x74\xfc\x6b\xf6\x72\x66\xfa"      /*  |árvíztűrőtükörfú| */
                    "\x72\xf3\x67\xe9\x70\n",                                               /*  |rógép|            */
                    -1,

                    /* NUL terminated line */
                    "01234567\0"
                    "01234567\0\n"
                    "01234567\n\0"
                    "01234567\r\n\0", 40,

                    "01234567\r\n"
                    /* no eol before EOF */
                    "01234567", -1,

                    LTM_EOF));

    assert_proto_server_fetch(proto, "01234567", -1);

    /* input split due to an oversized input line */
    assert_proto_server_fetch(proto, "0123456789ABCDEF0123456789ABCDEF", -1);
    assert_proto_server_fetch(proto, "01234567", -1);

    assert_proto_server_fetch(proto, "árvíztűrőtükörfúrógép", -1);
    assert_proto_server_fetch(proto,
                              "\xe1\x72\x76\xed\x7a\x74\xfb\x72\xf5\x74\xfc\x6b\xf6\x72\x66\xfa"    /*  |árvíztűrőtükörfú| */
                              "\x72\xf3\x67\xe9\x70",                                               /*  |rógép|            */
                              -1);
    assert_proto_server_fetch(proto, "01234567", -1);

    assert_proto_server_fetch(proto, "01234567", -1);
    assert_proto_server_fetch(proto, "", -1);

    assert_proto_server_fetch(proto, "01234567", -1);
    assert_proto_server_fetch(proto, "", -1);

    assert_proto_server_fetch(proto, "01234567", -1);
    assert_proto_server_fetch(proto, "", -1);

    assert_proto_server_fetch(proto, "01234567", -1);
    assert_proto_server_fetch(proto, "01234567", -1);
    log_proto_server_free(proto);
}
Esempio n. 4
0
static void
test_log_proto_text_server_io_error_before_eof(void)
{
  LogProtoServer *proto;

  proto = construct_test_proto(
            log_transport_mock_stream_new(
              "01234567", -1,
              LTM_INJECT_ERROR(EIO),
              LTM_EOF));

  assert_proto_server_fetch(proto, "01234567", -1);
  assert_proto_server_fetch_failure(proto, LPS_ERROR, NULL);
  log_proto_server_free(proto);
}
Esempio n. 5
0
static void
test_log_proto_text_server_partial_chars_before_eof(void)
{
  LogProtoServer *proto;

  log_proto_server_options_set_encoding(&proto_server_options, "utf-8");
  proto = construct_test_proto(
            log_transport_mock_stream_new(
              /* utf8 */
              "\xc3", -1,
              LTM_EOF));

  assert_true(log_proto_server_validate_options(proto), "validate_options() returned failure but it should have succeeded");
  assert_proto_server_fetch_failure(proto, LPS_EOF, "EOF read on a channel with leftovers from previous character conversion, dropping input");
  log_proto_server_free(proto);
}
Esempio n. 6
0
static void
test_log_proto_text_server_no_eol_before_eof(void)
{
  LogProtoServer *proto;

  proto = construct_test_proto(
            log_transport_mock_stream_new(
              /* no eol before EOF */
              "01234567", -1,

              LTM_EOF));

  assert_proto_server_fetch(proto, "01234567", -1);
  assert_proto_server_fetch_failure(proto, LPS_EOF, NULL);
  log_proto_server_free(proto);

}
Esempio n. 7
0
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);
}
Esempio n. 8
0
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);
}
Esempio n. 9
0
static void
test_log_proto_text_server_invalid_encoding(void)
{
  LogProtoServer *proto;
  gboolean success;

  log_proto_server_options_set_encoding(&proto_server_options, "never-ever-is-going-to-be-such-an-encoding");
  proto = construct_test_proto(
            log_transport_mock_stream_new(
              "", -1,
              LTM_EOF));

  start_grabbing_messages();
  success = log_proto_server_validate_options(proto);
  assert_grabbed_messages_contain("Unknown character set name specified; encoding='never-ever-is-going-to-be-such-an-encoding'", "message about unknown charset missing");
  assert_false(success, "validate_options() returned success but it should have failed");
  log_proto_server_free(proto);
}
Esempio n. 10
0
static void
test_log_proto_text_server_iso8859_2(void)
{
  LogProtoServer *proto;

  log_proto_server_options_set_encoding(&proto_server_options, "iso-8859-2");
  proto = construct_test_proto(
            log_transport_mock_stream_new(
              /* iso-8859-2 */
              "\xe1\x72\x76\xed\x7a\x74\xfb\x72\xf5\x74\xfc\x6b\xf6\x72\x66\xfa"      /*  |árvíztűrőtükörfú| */
              "\x72\xf3\x67\xe9\x70\n", -1,                                           /*  |rógép|            */
              LTM_EOF));

  assert_true(log_proto_server_validate_options(proto), "validate_options() returned failure but it should have succeeded");
  assert_proto_server_fetch(proto, "árvíztűrőtükörfúrógép", -1);
  assert_proto_server_fetch_failure(proto, LPS_EOF, NULL);
  log_proto_server_free(proto);
}
Esempio n. 11
0
static void
test_log_proto_text_server_not_fixed_encoding(void)
{
  LogProtoServer *proto;

  log_proto_server_options_set_encoding(&proto_server_options, "utf-8");

  /* to test whether a non-easily-reversable charset works too */
  proto = construct_test_proto(
            log_transport_mock_stream_new(
              /* utf8 */
              "árvíztűrőtükörfúrógép\n", -1,
              LTM_EOF));
  assert_true(log_proto_server_validate_options(proto), "validate_options() returned failure but it should have succeeded");
  assert_proto_server_fetch(proto, "árvíztűrőtükörfúrógép", -1);
  assert_proto_server_fetch_failure(proto, LPS_EOF, NULL);
  log_proto_server_free(proto);
}
Esempio n. 12
0
static void
test_log_proto_text_server_ucs4(void)
{
  LogProtoServer *proto;

  log_proto_server_options_set_encoding(&proto_server_options, "ucs-4");
  proto = construct_test_proto(
            log_transport_mock_stream_new(
              /* ucs4 */
              "\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"      /* |...z...t...ű...r| */
              "\x00\x00\x01\x51\x00\x00\x00\x74\x00\x00\x00\xfc\x00\x00\x00\x6b"      /* |...Q...t.......k| */
              "\x00\x00\x00\xf6\x00\x00\x00\x72\x00\x00\x00\x66\x00\x00\x00\xfa"      /* |.......r...f....| */
              "\x00\x00\x00\x72\x00\x00\x00\xf3\x00\x00\x00\x67\x00\x00\x00\xe9"      /* |...r.......g....| */
              "\x00\x00\x00\x70\x00\x00\x00\x0a", 88,                                 /* |...p....|         */
              LTM_EOF));

  assert_true(log_proto_server_validate_options(proto), "validate_options() returned failure but it should have succeeded");
  assert_proto_server_fetch(proto, "árvíztűrőtükörfúrógép", -1);
  assert_proto_server_fetch_failure(proto, LPS_EOF, NULL);
  log_proto_server_free(proto);
}