Пример #1
0
END_TEST

START_TEST (response_get_last_test) {
  int res;
  char *resp_code = NULL, *resp_msg = NULL;

  res = pr_response_get_last(NULL, NULL, NULL);
  fail_unless(res == -1, "Failed to handle null pool");
  fail_unless(errno == EINVAL, "Expected errno %d (%s), got %d (%s)",
    EINVAL, strerror(EINVAL), errno, strerror(errno));

  res = pr_response_get_last(p, NULL, NULL);
  fail_unless(res == -1, "Failed to handle null argument");
  fail_unless(errno == EINVAL, "Expected errno %d (%s), got %d (%s)",
    EINVAL, strerror(EINVAL), errno, strerror(errno));

  res = pr_response_get_last(p, &resp_code, &resp_msg);
  fail_unless(res == 0, "Failed to get last values: %d (%s)", errno,
    strerror(errno));

  fail_unless(resp_code == NULL,
    "Last response code not null as expected: %s", resp_code);
  fail_unless(resp_msg == NULL,
    "Last response message not null as expected: %s", resp_msg);
}
Пример #2
0
END_TEST

START_TEST (display_fh_test) {
  pr_fh_t *fh;
  int res;
  const char *path = NULL, *resp_code = NULL;
  char *last_resp_code = NULL, *last_resp_msg = NULL;

  res = pr_display_fh(NULL, NULL, NULL, 0);
  fail_unless(res < 0, "Failed to handle null arguments");
  fail_unless(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
    strerror(errno), errno);

  (void) unlink(display_test_file);
  res = write_file(display_test_file, display_lines, 4);
  fail_unless(res == 0, "Failed to write display file: %s", strerror(errno));

  path = display_test_file;
  fh = pr_fsio_open(path, O_RDONLY);
  fail_unless(fh != NULL, "Failed to open '%s': %s", path, strerror(errno));

  mark_point();
  res = pr_display_fh(fh, NULL, NULL, 0);
  fail_unless(res < 0, "Failed to handle null resp_code argument");
  fail_unless(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
    strerror(errno), errno);

  resp_code = R_200;
  pr_response_set_pool(p);

  mark_point();
  res = pr_display_fh(fh, NULL, resp_code, 0);
  fail_unless(res == 0, "Failed to display file: %s", strerror(errno));

  mark_point();
  res = pr_response_get_last(p, &last_resp_code, &last_resp_msg);
  fail_unless(res == 0, "Failed to get last response values: %s (%d)",
    strerror(errno), errno);

  fail_unless(last_resp_code != NULL,
    "Last response code is unexpectedly null");
  fail_unless(strcmp(last_resp_code, resp_code) == 0,
    "Expected response code '%s', got '%s'", resp_code, last_resp_code);

  fail_unless(last_resp_msg != NULL,
    "Last response message is unexpectedly null");
}
Пример #3
0
END_TEST

START_TEST (response_add_err_test) {
  int res;
  char *last_resp_code = NULL, *last_resp_msg = NULL;
  char *resp_code = R_450, *resp_msg = "Busy";

  pr_response_set_pool(p);
  pr_response_add_err(resp_code, "%s", resp_msg);

  res = pr_response_get_last(p, &last_resp_code, &last_resp_msg);
  fail_unless(res == 0, "Failed to get last values: %d (%s)", errno,
    strerror(errno));

  fail_unless(last_resp_code != NULL, "Last response code unexpectedly null");
  fail_unless(strcmp(last_resp_code, resp_code) == 0,
    "Expected response code '%s', got '%s'", resp_code, last_resp_code);

  fail_unless(last_resp_msg != NULL, "Last response message unexpectedly null");
  fail_unless(strcmp(last_resp_msg, resp_msg) == 0,
    "Expected response message '%s', got '%s'", resp_msg, last_resp_msg);
}