mirror of
https://github.com/cryb-to/cryb-to.git
synced 2025-02-06 19:11:11 +00:00
Add two utility functions which check if a string contains something that
can be interpreted as either true or false. Use this instead of a basic non-NULL test for the CRYB_PERFTEST check.
This commit is contained in:
parent
559f6c24f7
commit
56eccb99fe
10 changed files with 49 additions and 8 deletions
3
t/t.h
3
t/t.h
|
@ -105,6 +105,9 @@ t_compare_num(x64, uint64_t);
|
|||
t_compare_num(ptr, void *);
|
||||
#undef t_compare_num
|
||||
|
||||
int t_str_is_true(const char *);
|
||||
int t_str_is_false(const char *);
|
||||
|
||||
/*
|
||||
* Useful constants
|
||||
*/
|
||||
|
|
|
@ -224,7 +224,7 @@ t_prepare(int argc, char *argv[])
|
|||
t_add_test(t_md2_short_updates, &t_md2_vectors[6],
|
||||
"multiple short updates");
|
||||
#endif
|
||||
if (getenv("CRYB_PERFTEST")) {
|
||||
if (t_str_is_true(getenv("CRYB_PERFTEST"))) {
|
||||
static size_t one = 1, thousand = 1000, million = 1000000;
|
||||
t_add_test(t_md2_perf, &one,
|
||||
"performance test (1 byte)");
|
||||
|
|
|
@ -240,7 +240,7 @@ t_prepare(int argc, char *argv[])
|
|||
t_add_test(t_md4_short_updates, &t_md4_vectors[6],
|
||||
"multiple short updates");
|
||||
#endif
|
||||
if (getenv("CRYB_PERFTEST")) {
|
||||
if (t_str_is_true(getenv("CRYB_PERFTEST"))) {
|
||||
static size_t one = 1, thousand = 1000, million = 1000000;
|
||||
t_add_test(t_md4_perf, &one,
|
||||
"performance test (1 byte)");
|
||||
|
|
|
@ -240,7 +240,7 @@ t_prepare(int argc, char *argv[])
|
|||
t_add_test(t_md5_short_updates, &t_md5_vectors[6],
|
||||
"multiple short updates");
|
||||
#endif
|
||||
if (getenv("CRYB_PERFTEST")) {
|
||||
if (t_str_is_true(getenv("CRYB_PERFTEST"))) {
|
||||
static size_t one = 1, thousand = 1000, million = 1000000;
|
||||
t_add_test(t_md5_perf, &one,
|
||||
"performance test (1 byte)");
|
||||
|
|
|
@ -236,7 +236,7 @@ t_prepare(int argc, char *argv[])
|
|||
t_add_test(t_sha1_short_updates, &t_sha1_vectors[4],
|
||||
"multiple short updates");
|
||||
#endif
|
||||
if (getenv("CRYB_PERFTEST")) {
|
||||
if (t_str_is_true(getenv("CRYB_PERFTEST"))) {
|
||||
static size_t one = 1, thousand = 1000, million = 1000000;
|
||||
t_add_test(t_sha1_perf, &one,
|
||||
"performance test (1 byte)");
|
||||
|
|
|
@ -245,7 +245,7 @@ t_prepare(int argc, char *argv[])
|
|||
t_add_test(t_sha224_short_updates, &t_sha224_vectors[4],
|
||||
"multiple short updates");
|
||||
#endif
|
||||
if (getenv("CRYB_PERFTEST")) {
|
||||
if (t_str_is_true(getenv("CRYB_PERFTEST"))) {
|
||||
static size_t one = 1, thousand = 1000, million = 1000000;
|
||||
t_add_test(t_sha224_perf, &one,
|
||||
"performance test (1 byte)");
|
||||
|
|
|
@ -241,7 +241,7 @@ t_prepare(int argc, char *argv[])
|
|||
t_add_test(t_sha256_short_updates, &t_sha256_vectors[4],
|
||||
"multiple short updates");
|
||||
#endif
|
||||
if (getenv("CRYB_PERFTEST")) {
|
||||
if (t_str_is_true(getenv("CRYB_PERFTEST"))) {
|
||||
static size_t one = 1, thousand = 1000, million = 1000000;
|
||||
t_add_test(t_sha256_perf, &one,
|
||||
"performance test (1 byte)");
|
||||
|
|
|
@ -289,7 +289,7 @@ t_prepare(int argc, char *argv[])
|
|||
t_add_test(t_sha384_short_updates, &t_sha384_vectors[4],
|
||||
"multiple short updates");
|
||||
#endif
|
||||
if (getenv("CRYB_PERFTEST")) {
|
||||
if (t_str_is_true(getenv("CRYB_PERFTEST"))) {
|
||||
static size_t one = 1, thousand = 1000, million = 1000000;
|
||||
t_add_test(t_sha384_perf, &one,
|
||||
"performance test (1 byte)");
|
||||
|
|
|
@ -301,7 +301,7 @@ t_prepare(int argc, char *argv[])
|
|||
t_add_test(t_sha512_short_updates, &t_sha512_vectors[4],
|
||||
"multiple short updates");
|
||||
#endif
|
||||
if (getenv("CRYB_PERFTEST")) {
|
||||
if (t_str_is_true(getenv("CRYB_PERFTEST"))) {
|
||||
static size_t one = 1, thousand = 1000, million = 1000000;
|
||||
t_add_test(t_sha512_perf, &one,
|
||||
"performance test (1 byte)");
|
||||
|
|
38
t/t_util.c
38
t/t_util.c
|
@ -114,3 +114,41 @@ t_compare_num(x64, uint64_t, "0x%" PRIx64);
|
|||
t_compare_num(ptr, void *, "%p");
|
||||
|
||||
#undef t_compare_num
|
||||
|
||||
/*
|
||||
* Return non-zero if str is not NULL and points to a string which
|
||||
* compares equal to something we interpret as "true".
|
||||
*/
|
||||
int
|
||||
t_str_is_true(const char *str)
|
||||
{
|
||||
|
||||
if (str == NULL || *str == '\0')
|
||||
return (0);
|
||||
if (strcmp(str, "1") == 0 ||
|
||||
strcasecmp(str, "y") == 0 ||
|
||||
strcasecmp(str, "yes") == 0 ||
|
||||
strcasecmp(str, "t") == 0 ||
|
||||
strcasecmp(str, "true") == 0)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return non-zero if str is not NULL and points to a string which
|
||||
* compares equal to something we interpret as "false".
|
||||
*/
|
||||
int
|
||||
t_str_is_false(const char *str)
|
||||
{
|
||||
|
||||
if (str == NULL || *str == '\0')
|
||||
return (0);
|
||||
if (strcmp(str, "0") == 0 ||
|
||||
strcasecmp(str, "n") == 0 ||
|
||||
strcasecmp(str, "no") == 0 ||
|
||||
strcasecmp(str, "f") == 0 ||
|
||||
strcasecmp(str, "false") == 0)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue