diff options
author | Valentin Bartenev <vbart@nginx.com> | 2017-10-05 16:46:18 +0300 |
---|---|---|
committer | Valentin Bartenev <vbart@nginx.com> | 2017-10-05 16:46:18 +0300 |
commit | 096562c0b14656354fcb0eb7b7c6d524f5fb1f1d (patch) | |
tree | efd6dd7b94951778e132d84591d77ae8d7ecf469 /test | |
parent | 653e9854637e129cd6a92adaff96784220165eea (diff) | |
download | unit-096562c0b14656354fcb0eb7b7c6d524f5fb1f1d.tar.gz unit-096562c0b14656354fcb0eb7b7c6d524f5fb1f1d.tar.bz2 |
Improved applications versions handling.
Diffstat (limited to 'test')
-rw-r--r-- | test/nxt_strverscmp_test.c | 94 | ||||
-rw-r--r-- | test/nxt_tests.c | 4 | ||||
-rw-r--r-- | test/nxt_tests.h | 1 |
3 files changed, 99 insertions, 0 deletions
diff --git a/test/nxt_strverscmp_test.c b/test/nxt_strverscmp_test.c new file mode 100644 index 00000000..40adbfb2 --- /dev/null +++ b/test/nxt_strverscmp_test.c @@ -0,0 +1,94 @@ + +/* + * Copyright (C) NGINX, Inc. + * Copyright (C) Valentin V. Bartenev + */ + +#include <nxt_main.h> +#include "nxt_tests.h" + + +typedef struct { + const char *v1; + const char res; + const char *v2; +} nxt_strverscmp_test_t; + + +nxt_int_t +nxt_strverscmp_test(nxt_thread_t *thr) +{ + nxt_int_t ret; + nxt_uint_t i; + + static const nxt_strverscmp_test_t tests[] = { + { "word", '=', "word" }, + { "42", '=', "42" }, + { "000", '=', "000" }, + { "2", '>', "1" }, + { "2", '<', "10" }, + { "rc2", '>', "rc" }, + { "rc2", '<', "rc3" }, + { "1.13.8", '>', "1.1.9" }, + { "1.9", '<', "1.13.8" }, + { "9.9", '<', "10.0" }, + { "1", '>', "007" }, + { "2b01", '<', "2b013" }, + { "011", '>', "01" }, + { "011", '>', "01.1" }, + { "011", '>', "01+1" }, + { "011", '<', "01:1" }, + { "011", '<', "01b" }, + { "020", '>', "01b" }, + { "a0", '>', "a01" }, + { "b00", '<', "b01" }, + { "c000", '<', "c01" }, + { "000", '<', "00" }, + { "000", '<', "00a" }, + { "00.", '>', "000" }, + { "a.0", '<', "a0" }, + { "b11", '>', "b0" }, + }; + + nxt_thread_time_update(thr); + + for (i = 0; i < nxt_nitems(tests); i++) { + + ret = nxt_strverscmp((u_char *) tests[i].v1, (u_char *) tests[i].v2); + + switch (tests[i].res) { + + case '<': + if (ret < 0) { + continue; + } + + break; + + case '=': + if (ret == 0) { + continue; + } + + break; + + case '>': + if (ret > 0) { + continue; + } + + break; + } + + nxt_log_alert(thr->log, + "nxt_strverscmp() test \"%s\" %c \"%s\" failed: %i", + tests[i].v1, tests[i].res, tests[i].v2, ret); + + return NXT_ERROR; + } + + nxt_log_error(NXT_LOG_NOTICE, thr->log, + "nxt_strverscmp() test passed"); + + return NXT_OK; +} diff --git a/test/nxt_tests.c b/test/nxt_tests.c index 655192ab..7cba0f69 100644 --- a/test/nxt_tests.c +++ b/test/nxt_tests.c @@ -158,5 +158,9 @@ main(int argc, char **argv) return 1; } + if (nxt_strverscmp_test(thr) != NXT_OK) { + return 1; + } + return 0; } diff --git a/test/nxt_tests.h b/test/nxt_tests.h index 508ddbe4..be4168cf 100644 --- a/test/nxt_tests.h +++ b/test/nxt_tests.h @@ -63,6 +63,7 @@ nxt_int_t nxt_sprintf_test(nxt_thread_t *thr); nxt_int_t nxt_malloc_test(nxt_thread_t *thr); nxt_int_t nxt_utf8_test(nxt_thread_t *thr); nxt_int_t nxt_http_parse_test(nxt_thread_t *thr); +nxt_int_t nxt_strverscmp_test(nxt_thread_t *thr); #endif /* _NXT_TESTS_H_INCLUDED_ */ |