예제 #1
0
파일: sf_assert.c 프로젝트: ifzz/libsf
bool
sf_assert_c_string_equals(char const *file, int line, char const *actual_expression, char const *actual_value, char const *expected_expression, char const *expected_value, sf_list_t *_sf_test_failures)
{
  if (actual_value == expected_value) return true;
  
  if (not actual_value) {
    add_failure(_sf_test_failures, file, line, "%s expected to equal %s",
                expression_value_description(actual_expression, "NULL"),
                expression_value_description(expected_expression, "\"%s\"", expected_value));
    return false;
  }
  
  if (not expected_value) {
    add_failure(_sf_test_failures, file, line, "%s expected to equal %s",
                expression_value_description(actual_expression, "\"%s\"", actual_value),
                expression_value_description(expected_expression, "NULL"));
    return false;
  }
  
  if (0 == strcmp(actual_value, expected_value)) return true;

  add_failure(_sf_test_failures, file, line, "%s expected to equal %s",
              expression_value_description(actual_expression, "\"%s\"", actual_value),
              expression_value_description(expected_expression, "\"%s\"", expected_value));
  return false;
}
예제 #2
0
파일: sf_assert.c 프로젝트: ifzz/libsf
bool
sf_assert_null(char const *file, int line, char const *expression, void const *actual, sf_list_t *_sf_test_failures)
{
  if (actual == NULL) return true;
  add_failure(_sf_test_failures, file, line, "expected (%s) to be NULL but was (%p)", expression, actual);
  return false;
}
예제 #3
0
void
srunner_run_all(SRunner *runner, int verbosity)
{
    Suite *suite;
    TCase *tc;
    assert(runner != NULL);
    suite = runner->suite;
    tc = suite->tests;
    while (tc != NULL) {
        int i;
        for (i = 0; i < tc->ntests; ++i) {
            runner->nchecks++;

            if (tc->setup != NULL) {
                /* setup */
                if (setjmp(env)) {
                    add_failure(runner, verbosity);
                    continue;
                }
                tc->setup();
            }
            /* test */
            if (setjmp(env)) {
                add_failure(runner, verbosity);
                continue;
            }
            (tc->tests[i])();

            /* teardown */
            if (tc->teardown != NULL) {
                if (setjmp(env)) {
                    add_failure(runner, verbosity);
                    continue;
                }
                tc->teardown();
            }
        }
        tc = tc->next_tcase;
    }
    if (verbosity) {
        int passed = runner->nchecks - runner->nfailures;
        double percentage = ((double) passed) / runner->nchecks;
        int display = (int) (percentage * 100);
        printf("%d%%: Checks: %d, Failed: %d\n",
               display, runner->nchecks, runner->nfailures);
    }
}
예제 #4
0
파일: sf_assert.c 프로젝트: ifzz/libsf
bool
sf_assert_bool(char const *file, int line, char const *expression, bool actual, bool expected, sf_list_t *_sf_test_failures)
{
  if (actual == expected) return true;
  char const *format = expected ? "(%s) expected to be true" : "(%s) expected to be false";
  add_failure(_sf_test_failures, file, line, format, expression);
  return false;
}
예제 #5
0
파일: sf_assert.c 프로젝트: ifzz/libsf
bool
sf_assert_size_t_not_equals(char const *file, int line, char const *actual_expression, size_t actual_value, char const *unexpected_expression, size_t unexpected_value, sf_list_t *_sf_test_failures)
{
  if (actual_value != unexpected_value) return true;
  add_failure(_sf_test_failures, file, line, "expected %s to NOT equal %s",
      expression_value_description(actual_expression, "%zi", actual_value),
      expression_value_description(unexpected_expression, "%zi", unexpected_value));
  return false;
}
예제 #6
0
파일: sf_assert.c 프로젝트: ifzz/libsf
bool
sf_assert_ptr_not_equals(char const *file, int line, char const *actual_expression, void const *actual_value, char const *expected_expression, void const *expected_value, sf_list_t *_sf_test_failures)
{
  if (actual_value != expected_value) return true;
  add_failure(_sf_test_failures, file, line, "expected %s to not equal %s",
              expression_value_description(actual_expression, "%p", actual_value),
              expression_value_description(expected_expression, "%p", expected_value));
  return false;
}
예제 #7
0
파일: sf_assert.c 프로젝트: ifzz/libsf
bool
sf_assert_long_equals(char const *file, int line, char const *actual_expression, long actual_value, char const *expected_expression, long expected_value, sf_list_t *_sf_test_failures)
{
  if (actual_value == expected_value) return true;
  add_failure(_sf_test_failures, file, line, "expected %s to equal %s",
              expression_value_description(actual_expression, "%li", actual_value),
              expression_value_description(expected_expression, "%li", expected_value));
  return false;
}
예제 #8
0
파일: sf_assert.c 프로젝트: ifzz/libsf
bool
sf_assert_is_not_equal(char const *file, int line, char const *actual_expression, sf_any_t actual_value, char const *unexpected_expression, sf_any_t unexpected_value, sf_list_t *_sf_test_failures)
{
  if (not sf_is_equal(actual_value, unexpected_value)) return true;
  add_failure(_sf_test_failures, file, line, "%s expected to NOT equal %s",
              expression_value_description(actual_expression, "%s", sf_c_string_from(actual_value)),
              expression_value_description(unexpected_expression, "%s", sf_c_string_from(unexpected_value)));
  return false;
}
예제 #9
0
파일: sf_assert.c 프로젝트: ifzz/libsf
bool
sf_assert_c_string_not_equals(char const *file, int line, char const *actual_expression, char const *actual_value, char const *unexpected_expression, char const *unexpected_value, sf_list_t *_sf_test_failures)
{
  if (not actual_value or not unexpected_value) {
    if (not actual_value and not unexpected_value) {
      add_failure(_sf_test_failures, file, line, "expected NULL to NOT equal NULL");
      return false;
    }

    return true;
  }

  if (0 == strcmp(actual_value, unexpected_value)) {
    add_failure(_sf_test_failures, file, line, "expected %s to NOT equal %s",
        expression_value_description(actual_expression, "\"%s\"", actual_value),
        expression_value_description(unexpected_expression, "\"%s\"", unexpected_value));
    return false;
  }

  return true;
}