Example #1
0
END_TEST

START_TEST(test_send_with_error_teardown)
{
  TestResult *tr;
  setup_messaging();
  send_ctx_info(CK_CTX_SETUP);
  send_loc_info("abc123.c", 10);
  send_ctx_info(CK_CTX_TEST);
  send_loc_info("abc124.c", 22);
  send_loc_info("abc125.c", 25);
  send_ctx_info(CK_CTX_TEARDOWN);
  send_loc_info("abc126.c", 54);
  tr = receive_test_result(1);
  teardown_messaging();

  ck_assert_msg (tr != NULL,
	       "No test result received");
  ck_assert_msg (tr_ctx(tr) == CK_CTX_TEARDOWN,
	       "Bad CTX received");
  ck_assert_msg (tr_msg(tr) == NULL,
	       "Bad failure msg received");
  ck_assert_msg (strcmp(tr_lfile(tr), "abc126.c") == 0,
	       "Bad loc file received");
  ck_assert_msg (tr_lno(tr) == 54,
	       "Bad loc line received");
  if (tr != NULL)
    tr_free(tr);
}
Example #2
0
END_TEST

START_TEST(test_check_failure_msgs)
{
    int i;
    int passed = 0;
    const char *got_msg;
    const char *expected_msg;
    TestResult *tr;

    for (i = 0; i < sub_ntests; i++) {
        if (master_tests[i].failure_type == CK_PASS) {
            passed++;
            continue;
        }

        fail_if(i - passed > sub_nfailed, NULL);
        tr = tr_fail_array[i - passed];
        fail_unless(tr != NULL, NULL);
        got_msg = tr_msg(tr);
        expected_msg = master_tests[i].msg;
        if (strcmp(got_msg, expected_msg) != 0) {
            char *emsg = malloc(MAXSTR);
            snprintf(emsg, MAXSTR,"For test %d: Expected %s, got %s",
                     i, expected_msg, got_msg);
            fail(emsg);
            free(emsg);
        }
    }
}
Example #3
0
END_TEST


START_TEST(test_check_all_msgs)
{
  const char *msg;
  msg = tr_msg(tr_all_array[_i]);
  if (strcmp(msg, master_tests[_i].msg) != 0) {
    char *emsg;
    char *tmp = (char *)malloc (MAXSTR);
    snprintf(tmp, MAXSTR,"Expected %s, got %s",
             master_tests[_i].msg, msg);

   /*
    * NOTE: ck_abort_msg() will take the passed string
    * and feed it to printf. We need to escape any
    * '%' found, else they will result in odd formatting
    * in ck_abort_msg().
    */
    emsg = escape_percent(tmp, MAXSTR);
    free(tmp);

    ck_abort_msg(emsg);
    free(emsg);
  }
}
END_TEST
  
START_TEST(test_check_failure_lnos)
{
  int i;
  int line_no;
  int passed = 0;
  int failed;
  TestResult *tr;
  
  /* Create list of line numbers where failures occurred */
  rewind(line_num_failures);

  for (i = 0; i < sub_ntests; i++) {
    if (master_tests[i].failure_type == CK_PASS) {
      passed++;
      continue;
    }

    failed = i - passed;

    ck_assert_msg(i - passed <= sub_nfailed, NULL);
    tr = tr_fail_array[failed];
    ck_assert_msg(tr != NULL, NULL);
    line_no = get_next_failure_line_num(line_num_failures);

    if(line_no == -1)
    {
      ck_abort_msg("Did not find the %dth failure line number for suite %s, msg %s",
        (failed+1), tr_tcname(tr), tr_msg(tr));
    }

    if (line_no > 0 && tr_lno(tr) != line_no) {
      ck_abort_msg("For test %d (failure %d): Expected lno %d, got %d for suite %s, msg %s",
               i, failed, line_no, tr_lno(tr), tr_tcname(tr), tr_msg(tr));
    }    
  }

  /* At this point, there should be no remaining failures */
  line_no = get_next_failure_line_num(line_num_failures);
  ck_assert_msg(line_no == -1,
    "No more failure line numbers expected, but found %d", line_no);
}
Example #5
0
END_TEST


START_TEST(test_check_all_msgs)
{
    const char *msg;
    msg = tr_msg(tr_all_array[_i]);
    if (strcmp(msg, master_tests[_i].msg) != 0) {
        char *emsg = malloc (MAXSTR);
        snprintf(emsg, MAXSTR,"Expected %s, got %s",
                 master_tests[_i].msg, msg);
        fail(emsg);
        free(emsg);
    }
}