X-Git-Url: https://git.openssl.org/gitweb/?a=blobdiff_plain;f=test%2Ftestutil%2Ftests.c;h=a60af0764f62f160348635e68ba3a13973acd9e7;hb=681e8cacdbdc44ac00af29b6656fc52745a9baa2;hp=b2d95db8593b08472e74344e558eeef5bf8c4492;hpb=a69de3f2014ab55329f43633714c9c153cb5cb30;p=openssl.git diff --git a/test/testutil/tests.c b/test/testutil/tests.c index b2d95db859..a60af0764f 100644 --- a/test/testutil/tests.c +++ b/test/testutil/tests.c @@ -14,7 +14,8 @@ #include #include #include -#include "../../e_os.h" +#include "internal/nelem.h" +#include /* * Output a failed test first line. @@ -416,3 +417,32 @@ int test_BN_abs_eq_word(const char *file, int line, const char *bns, BN_free(aa); return 0; } + +static const char *print_time(const ASN1_TIME *t) +{ + return t == NULL ? "" : (char *)ASN1_STRING_get0_data(t); +} + +#define DEFINE_TIME_T_COMPARISON(opname, op) \ + int test_time_t_ ## opname(const char *file, int line, \ + const char *s1, const char *s2, \ + const time_t t1, const time_t t2) \ + { \ + ASN1_TIME *at1 = ASN1_TIME_set(NULL, t1); \ + ASN1_TIME *at2 = ASN1_TIME_set(NULL, t2); \ + int r = at1 != NULL && at2 != NULL \ + && ASN1_TIME_compare(at1, at2) op 0; \ + if (!r) \ + test_fail_message(NULL, file, line, "time_t", s1, s2, #op, \ + "[%s] compared to [%s]", \ + print_time(at1), print_time(at2)); \ + ASN1_STRING_free(at1); \ + ASN1_STRING_free(at2); \ + return r; \ + } +DEFINE_TIME_T_COMPARISON(eq, ==) +DEFINE_TIME_T_COMPARISON(ne, !=) +DEFINE_TIME_T_COMPARISON(gt, >) +DEFINE_TIME_T_COMPARISON(ge, >=) +DEFINE_TIME_T_COMPARISON(lt, <) +DEFINE_TIME_T_COMPARISON(le, <=)