Example #1
0
void assert_that_double_(const char *file, int line, const char *expression, double actual, Constraint* constraint) {
    BoxedDouble* boxed_actual;
    if (NULL != constraint && is_not_comparing(constraint)) {
        (*get_test_reporter()->assert_true)(
                get_test_reporter(),
                file,
                line,
                false,
                "\tGot constraint of type [%s], but they are not allowed for assertions, only in mock expectations.",
                constraint->name);

        constraint->destroy(constraint);

        return;
    }

    boxed_actual = (BoxedDouble*)box_double(actual);

    (*get_test_reporter()->assert_true)(get_test_reporter(), file, line, (*constraint->compare)(constraint, (intptr_t)boxed_actual),
            "Expected [%s] to [%s] [%s] within [%d] significant figures\n"
            "\t\tactual value:\t%08f\n"
            "\t\texpected value:\t%08f",
            expression,
            constraint->name,
            constraint->expected_value_name,
            get_significant_figures(),
            actual,
            as_double(constraint->expected_value));

    free(boxed_actual);
    constraint->destroy(constraint);
}
Example #2
0
void assert_string_not_equal_(const char *file, int line, const char *tried, const char *expected) {
    (*get_test_reporter()->assert_true)(
            get_test_reporter(),
            file,
            line,
            ! strings_are_equal(tried, expected),
            "[%s] should not match [%s]", show_null_as_the_string_null(tried), show_null_as_the_string_null(expected));
}
Example #3
0
void assert_double_not_equal_(const char *file, int line, double tried, double expected) {
    (*get_test_reporter()->assert_true)(
            get_test_reporter(),
            file,
            line,
            ! doubles_are_equal(tried, expected),
            "[%f] should not match [%f] within %d significant figures", tried, expected, significant_figures);
}
Example #4
0
void assert_not_equal_(const char *file, int line, intptr_t tried, intptr_t expected) {
    (*get_test_reporter()->assert_true)(
            get_test_reporter(),
            file,
            line,
            (tried != expected),
            "[%d] should not match [%d]", tried, expected);
}
Example #5
0
void assert_equal_(const char *file, int line, const char *expression, intptr_t tried, intptr_t expected) {
    (*get_test_reporter()->assert_true)(
            get_test_reporter(),
            file,
            line,
            (tried == expected),
            "[%s] should be [%d] but was [%d]\n", expression, expected, tried);
}
Example #6
0
void assert_string_equal_(const char *file, int line, const char *expression, const char *tried, const char *expected) {
    (*get_test_reporter()->assert_true)(
            get_test_reporter(),
            file,
            line,
            strings_are_equal(tried, expected),
            "[%s] should be [%s] but was [%s]\n", expression, show_null_as_the_string_null(expected), show_null_as_the_string_null(tried));
}
Example #7
0
void assert_double_not_equal_(const char *file, int line, const char *expression, double tried, double expected) {
    (*get_test_reporter()->assert_true)(
            get_test_reporter(),
            file,
            line,
            ! doubles_are_equal(tried, expected),
            "[%s] should not be [%f] within %d significant figures but was [%f]\n", expression, expected, get_significant_figures(), tried);
}
Example #8
0
static void unwanted_check(const char *function) {
    int i;
    for (i = 0; i < cgreen_vector_size(unwanted_calls); i++) {
        UnwantedCall *unwanted = (UnwantedCall *) cgreen_vector_get(unwanted_calls, i);
        if (strcmp(unwanted->function, function) == 0) {
            (*get_test_reporter()->assert_true)(
                    get_test_reporter(),
                    unwanted->test_file,
                    unwanted->test_line,
                    0,
                    "Unexpected call to function [%s]", function);
        }
    }
}
Example #9
0
void apply_any_constraints(RecordedExpectation *expectation, const char *parameter, intptr_t actual) {
    int i;
    for (i = 0; i < cgreen_vector_size(expectation->constraints); i++) {
        Constraint *constraint = (Constraint *)cgreen_vector_get(expectation->constraints, i);
        if (is_constraint_parameter(constraint, parameter)) {
			switch(constraint->constraint_type)
			{
			case CG_CONSTRAINT_WANT:
				test_constraint(
						constraint,
						expectation->function,
						actual,
						expectation->test_file,
						expectation->test_line,
						get_test_reporter());
			break;
			case CG_CONSTRAINT_SET:
				*((int *)actual) = (int)constraint->out_value;
				break;

			case CG_CONSTRAINT_FILL:
				memcpy((void *)actual, (void *)constraint->out_value, constraint->copy_size);
				break;
			}
        }
    }
}
Example #10
0
void apply_any_constraints(RecordedExpectation *expectation, const char *parameter, intptr_t actual) {
    int i;
    for (i = 0; i < vector_size(expectation->constraints); i++) {
        Constraint *constraint = (Constraint *)vector_get(expectation->constraints, i);
        if (is_constraint_parameter(constraint, parameter)) {
            test_constraint(
                    constraint,
                    expectation->function,
                    actual,
                    expectation->test_file,
                    expectation->test_line,
                    get_test_reporter());
        }
    }
}
Example #11
0
void print_learned_mocks(void) {
    int e, c;
    CgreenBreadcrumb *breadcrumb = get_test_reporter()->breadcrumb;
    printf("%s: learned mocks:\n",
           get_current_from_breadcrumb(breadcrumb));

    if (cgreen_vector_size(learned_mock_calls) == 0) {
        printf("\t<none>\n");
        return;
    }

    for (e = 0; e < cgreen_vector_size(learned_mock_calls); e++) {
        RecordedExpectation *expectation = (RecordedExpectation*)cgreen_vector_get(learned_mock_calls, e);
        const char *function_name = expectation->function;
        printf("\texpect(%s", function_name);
        for (c = 0; c < cgreen_vector_size(expectation->constraints); c++) {
            Constraint *constraint = (Constraint *)cgreen_vector_get(expectation->constraints, c);
            printf(", when(%s, is_equal_to(%" PRIdPTR "))", constraint->expected_value_name, constraint->expected_value);
        }
        printf(");\n");
    }
}
Example #12
0
/**
   run()
   
   N.B. Although this is neither an API or public function, it is
   documented as a good place to put a breakpoint. Do not change the
   name or semantics of this function, it should continue to be very
   close to the test code. */
static void run(CgreenTest *spec) {
#ifdef __cplusplus
    std::string message = "an exception was thrown during test: ";
    try {
#endif
        spec->run();
#ifdef __cplusplus
        return;
    } catch(const std::exception& exception) {
        message += '[';
        message += exception.what();
        message += ']';
    } catch(const std::exception* exception) {
        message += '[';
        message += exception->what();
        message += ']';
    } catch(const std::string& exception_message) {
        message += '[';
        message += exception_message;
        message += ']';
    } catch(const std::string *exception_message) {
        message += '[';
        message += *exception_message;
        message += ']';
    } catch(const char *exception_message) {
        message += '[';
        message += exception_message;
        message += ']';
    } catch (...) {
        message += "unknown exception type";
    }
    va_list no_arguments;
    memset(&no_arguments, 0, sizeof(va_list));
    TestReporter *reporter = get_test_reporter();
    reporter->show_incomplete(reporter, spec->filename, spec->line, message.c_str(), no_arguments);
    send_reporter_exception_notification(reporter);
#endif
}
Example #13
0
void assert_that_(const char *file, int line, const char *actual_string, intptr_t actual, Constraint* constraint) {

    char *failure_message;
    if (NULL != constraint && is_not_comparing(constraint)) {
        (*get_test_reporter()->assert_true)(
                get_test_reporter(),
                file,
                line,
                false,
                "\tGot constraint of type [%s], but they are not allowed for assertions, only in mock expectations.",
                constraint->name);

        constraint->destroy(constraint);

        return;
    }

    if (parameters_are_not_valid_for(constraint, actual)) {
        char *validation_message = validation_failure_message_for(constraint, actual);

        (*get_test_reporter()->assert_true)(
                                            get_test_reporter(),
                                            file,
                                            line,
                                            false,
                                            validation_message);

        constraint->destroy(constraint);
        free(validation_message);
        return;
    }

    failure_message = constraint->failure_message(constraint, actual_string, actual);

    (*get_test_reporter()->assert_true)(
                                        get_test_reporter(),
                                        file,
                                        line,
                                        (*constraint->compare)(constraint, actual),
                                        failure_message
                                        );

    constraint->destroy(constraint);
    free(failure_message);
}