bool cct_check_args_eq(const char *file, int line, const char *expression, struct args *expected, struct args *actual, bool free1, bool free2) { bool result; if (expected && actual && args_equal(actual, expected)) { cct_check_passed(file, line, expression); result = true; } else { char *exp_str = expected ? args_to_string(expected) : x_strdup("(null)"); char *act_str = actual ? args_to_string(actual) : x_strdup("(null)"); cct_check_failed(file, line, expression, exp_str, act_str); free(exp_str); free(act_str); result = false; } if (free1) { args_free(expected); } if (free2) { args_free(actual); } return result; }
bool cct_check_str_eq(const char *file, int line, const char *expression, const char *expected, const char *actual, bool free1, bool free2) { bool result; if (expected && actual && str_eq(actual, expected)) { cct_check_passed(file, line, expression); result = true; } else { char *exp_str = expected ? format("\"%s\"", expected) : x_strdup("(null)"); char *act_str = actual ? format("\"%s\"", actual) : x_strdup("(null)"); cct_check_failed(file, line, expression, exp_str, act_str); free(exp_str); free(act_str); result = false; } if (free1) { free((char *)expected); } if (free2) { free((char *)actual); } return result; }
bool cct_check_float_eq(const char *file, int line, const char *expression, double expected, double actual) { if (fabs(expected - actual) < DBL_EPSILON) { cct_check_passed(file, line, expression); return true; } else { char *exp_str = format("%.1f", (double)expected); char *act_str = format("%.1f", (double)actual); cct_check_failed(file, line, expression, exp_str, act_str); free(exp_str); free(act_str); return false; } }
bool cct_check_int_eq(const char *file, int line, const char *expression, int64_t expected, int64_t actual) { if (expected == actual) { cct_check_passed(file, line, expression); return true; } else { #ifdef HAVE_LONG_LONG char *exp_str = format("%lld", (long long)expected); char *act_str = format("%lld", (long long)actual); #else char *exp_str = format("%ld", (long)expected); char *act_str = format("%ld", (long)actual); #endif cct_check_failed(file, line, expression, exp_str, act_str); free(exp_str); free(act_str); return false; } }