diff options
author | Pauli <paul.dale@oracle.com> | 2017-11-27 13:27:35 +1000 |
---|---|---|
committer | Pauli <paul.dale@oracle.com> | 2017-11-28 08:56:45 +1000 |
commit | b7af3f1433cc0d8d5f88c0b8dcd55c0c2261281a (patch) | |
tree | a9abf4c057b60e86aa1579336ba668771f04ad8f /test/testutil | |
parent | 92738d7d7321ab8b7e6b467dded9bd2d587b980c (diff) | |
download | openssl-b7af3f1433cc0d8d5f88c0b8dcd55c0c2261281a.tar.gz |
Test support for time_t comparisons.
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Andy Polyakov <appro@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/4797)
Diffstat (limited to 'test/testutil')
-rw-r--r-- | test/testutil/tests.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/test/testutil/tests.c b/test/testutil/tests.c index eb0a3938d1..a60af0764f 100644 --- a/test/testutil/tests.c +++ b/test/testutil/tests.c @@ -15,6 +15,7 @@ #include <string.h> #include <ctype.h> #include "internal/nelem.h" +#include <openssl/asn1.h> /* * 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 ? "<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, <=) |