From: Joel Rosdahl Date: Sun, 24 Jul 2011 12:13:15 +0000 (+0200) Subject: test: Use an int64_t variant of CHECK_INT_EQ for all integer types X-Git-Tag: v3.2~196 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=39fb5fef33b831c79954ae34710ad11160e718a1;p=thirdparty%2Fccache.git test: Use an int64_t variant of CHECK_INT_EQ for all integer types --- diff --git a/configure.ac b/configure.ac index 2b9278292..64ba35ebd 100644 --- a/configure.ac +++ b/configure.ac @@ -35,6 +35,8 @@ AC_HEADER_TIME AC_HEADER_STDBOOL AC_HEADER_SYS_WAIT +AC_CHECK_TYPES(long long) + AC_CHECK_HEADERS(ctype.h pwd.h stdlib.h string.h strings.h sys/time.h sys/mman.h) AC_CHECK_HEADERS(termios.h) diff --git a/test/framework.c b/test/framework.c index 85b4bd4b1..8169fa525 100644 --- a/test/framework.c +++ b/test/framework.c @@ -168,31 +168,19 @@ cct_check_failed(const char *file, int line, const char *what, int cct_check_int_eq(const char *file, int line, const char *expression, - int expected, int actual) + int64_t expected, int64_t actual) { if (expected == actual) { cct_check_passed(file, line, expression); return 1; } else { - char *exp_str = format("%i", expected); - char *act_str = format("%i", actual); - cct_check_failed(file, line, expression, exp_str, act_str); - free(exp_str); - free(act_str); - return 0; - } -} - -int -cct_check_uns_eq(const char *file, int line, const char *expression, - unsigned expected, unsigned actual) -{ - if (expected == actual) { - cct_check_passed(file, line, expression); - return 1; - } else { - char *exp_str = format("%i", expected); - char *act_str = format("%i", actual); +#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); diff --git a/test/framework.h b/test/framework.h index ec108c255..5f1a77083 100644 --- a/test/framework.h +++ b/test/framework.h @@ -73,16 +73,8 @@ #define CHECK_INT_EQ(expected, actual) \ do { \ - if (!cct_check_int_eq(__FILE__, __LINE__, #actual, (expected), (actual))) { \ - cct_test_end(); \ - cct_suite_end(); \ - return _test_counter; \ - } \ - } while (0) - -#define CHECK_UNS_EQ(expected, actual) \ - do { \ - if (!cct_check_uns_eq(__FILE__, __LINE__, #actual, (expected), (actual))) { \ + if (!cct_check_int_eq(__FILE__, __LINE__, #actual, (expected), \ + (actual))) { \ cct_test_end(); \ cct_suite_end(); \ return _test_counter; \ @@ -130,9 +122,7 @@ void cct_check_passed(const char *file, int line, const char *assertion); void cct_check_failed(const char *file, int line, const char *assertion, const char *expected, const char *actual); int cct_check_int_eq(const char *file, int line, const char *expression, - int expected, int actual); -int cct_check_uns_eq(const char *file, int line, const char *expression, - unsigned expected, unsigned actual); + int64_t expected, int64_t actual); int cct_check_str_eq(const char *file, int line, const char *expression, const char *expected, const char *actual, int free1, int free2); diff --git a/test/test_argument_processing.c b/test/test_argument_processing.c index 0d8bd491c..8a0ecbdfc 100644 --- a/test/test_argument_processing.c +++ b/test/test_argument_processing.c @@ -36,7 +36,7 @@ TEST(dash_E_should_result_in_called_for_preprocessing) create_file("foo.c", ""); CHECK(!cc_process_args(orig, &preprocessed, &compiler)); - CHECK_UNS_EQ(1, stats_get_pending(STATS_PREPROCESSING)); + CHECK_INT_EQ(1, stats_get_pending(STATS_PREPROCESSING)); args_free(orig); } @@ -48,7 +48,7 @@ TEST(dash_M_should_be_unsupported) create_file("foo.c", ""); CHECK(!cc_process_args(orig, &preprocessed, &compiler)); - CHECK_UNS_EQ(1, stats_get_pending(STATS_UNSUPPORTED)); + CHECK_INT_EQ(1, stats_get_pending(STATS_UNSUPPORTED)); args_free(orig); } diff --git a/test/test_conf.c b/test/test_conf.c index 4b6c09f87..2ee60012d 100644 --- a/test/test_conf.c +++ b/test/test_conf.c @@ -40,7 +40,7 @@ TEST(conf_create) CHECK_STR_EQ("", conf->base_dir); CHECK_STR_EQ_FREE1(format("%s/.ccache", get_home_directory()), conf->cache_dir); - CHECK_UNS_EQ(2, conf->cache_dir_levels); + CHECK_INT_EQ(2, conf->cache_dir_levels); CHECK_STR_EQ("", conf->compiler); CHECK_STR_EQ("mtime", conf->compiler_check); CHECK(!conf->compression); @@ -52,17 +52,17 @@ TEST(conf_create) CHECK(!conf->hard_link); CHECK(!conf->hash_dir); CHECK_STR_EQ("", conf->log_file); - CHECK_UNS_EQ(0, conf->max_files); - CHECK_UNS_EQ(1024*1024, conf->max_size); + CHECK_INT_EQ(0, conf->max_files); + CHECK_INT_EQ(1024*1024, conf->max_size); CHECK_STR_EQ("", conf->path); CHECK_STR_EQ("", conf->prefix_command); CHECK(!conf->read_only); CHECK(!conf->recache); CHECK(!conf->run_second_cpp); - CHECK_UNS_EQ(0, conf->sloppiness); + CHECK_INT_EQ(0, conf->sloppiness); CHECK(conf->stats); CHECK_STR_EQ("", conf->temporary_dir); - CHECK_UNS_EQ(UINT_MAX, conf->umask); + CHECK_INT_EQ(UINT_MAX, conf->umask); CHECK(!conf->unify); conf_free(conf); } @@ -110,7 +110,7 @@ TEST(conf_read_valid_config) CHECK_STR_EQ_FREE1(format("/%s/foo/%s", user, user), conf->base_dir); CHECK_STR_EQ_FREE1(format("%s$/%s/.ccache", user, user), conf->cache_dir); - CHECK_UNS_EQ(4, conf->cache_dir_levels); + CHECK_INT_EQ(4, conf->cache_dir_levels); CHECK_STR_EQ("foo", conf->compiler); CHECK_STR_EQ("none", conf->compiler_check); CHECK(conf->compression); @@ -122,18 +122,18 @@ TEST(conf_read_valid_config) CHECK(conf->hard_link); CHECK(conf->hash_dir); CHECK_STR_EQ_FREE1(format("%s%s", user, user), conf->log_file); - CHECK_UNS_EQ(17, conf->max_files); - CHECK_UNS_EQ(123 * 1024, conf->max_size); + CHECK_INT_EQ(17, conf->max_files); + CHECK_INT_EQ(123 * 1024, conf->max_size); CHECK_STR_EQ_FREE1(format("%s.x", user), conf->path); CHECK_STR_EQ_FREE1(format("x%s", user), conf->prefix_command); CHECK(conf->read_only); CHECK(conf->recache); CHECK(conf->run_second_cpp); - CHECK_UNS_EQ(SLOPPY_INCLUDE_FILE_MTIME|SLOPPY_FILE_MACRO|SLOPPY_TIME_MACROS, + CHECK_INT_EQ(SLOPPY_INCLUDE_FILE_MTIME|SLOPPY_FILE_MACRO|SLOPPY_TIME_MACROS, conf->sloppiness); CHECK(!conf->stats); CHECK_STR_EQ_FREE1(format("%s_foo", user), conf->temporary_dir); - CHECK_UNS_EQ(0777, conf->umask); + CHECK_INT_EQ(0777, conf->umask); CHECK(conf->unify); conf_free(conf); diff --git a/test/test_counters.c b/test/test_counters.c index a00d1ee8f..df12a8b59 100644 --- a/test/test_counters.c +++ b/test/test_counters.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010 Joel Rosdahl + * Copyright (C) 2010-2011 Joel Rosdahl * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free @@ -27,8 +27,8 @@ TEST(counters_init_0_should_allocate_0) { struct counters *counters = counters_init(0); - CHECK_UNS_EQ(0, counters->allocated); - CHECK_UNS_EQ(0, counters->size); + CHECK_INT_EQ(0, counters->allocated); + CHECK_INT_EQ(0, counters->size); counters_free(counters); } @@ -38,10 +38,10 @@ TEST(counters_init_7_should_allocate_32) int i; struct counters *counters = counters_init(7); - CHECK_UNS_EQ(32, counters->allocated); - CHECK_UNS_EQ(7, counters->size); + CHECK_INT_EQ(32, counters->allocated); + CHECK_INT_EQ(7, counters->size); for (i = 0; i < 7; i++) { - CHECK_UNS_EQ(0, counters->data[i]); + CHECK_INT_EQ(0, counters->data[i]); } counters_free(counters); @@ -51,10 +51,10 @@ TEST(counters_resize_50_should_allocate_96) { struct counters *counters = counters_init(0); - CHECK_UNS_EQ(0, counters->allocated); + CHECK_INT_EQ(0, counters->allocated); counters_resize(counters, 50); - CHECK_UNS_EQ(50, counters->size); - CHECK_UNS_EQ(96, counters->allocated); + CHECK_INT_EQ(50, counters->size); + CHECK_INT_EQ(96, counters->allocated); counters_free(counters); } diff --git a/test/test_stats.c b/test/test_stats.c index acf6a3423..79482d104 100644 --- a/test/test_stats.c +++ b/test/test_stats.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010 Joel Rosdahl + * Copyright (C) 2010-2011 Joel Rosdahl * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free @@ -40,12 +40,12 @@ TEST(forward_compatibility) fclose(f); stats_read("stats", counters); - CHECK_UNS_EQ(100, counters->size); - CHECK_UNS_EQ(73, counters->data[73]); + CHECK_INT_EQ(100, counters->size); + CHECK_INT_EQ(73, counters->data[73]); stats_write("stats", counters); - CHECK_UNS_EQ(100, counters->size); - CHECK_UNS_EQ(99, counters->data[99]); + CHECK_INT_EQ(100, counters->size); + CHECK_INT_EQ(99, counters->data[99]); counters_free(counters); } diff --git a/test/test_util.c b/test/test_util.c index 50fc75610..f00c03664 100644 --- a/test/test_util.c +++ b/test/test_util.c @@ -124,19 +124,19 @@ TEST(parse_size_with_suffix) { size_t size; CHECK(parse_size_with_suffix("0", &size)); - CHECK_UNS_EQ(0, size); + CHECK_INT_EQ(0, size); CHECK(parse_size_with_suffix("42K", &size)); - CHECK_UNS_EQ(42, size); + CHECK_INT_EQ(42, size); CHECK(parse_size_with_suffix("1.0M", &size)); - CHECK_UNS_EQ(1024, size); + CHECK_INT_EQ(1024, size); CHECK(parse_size_with_suffix("1.1M", &size)); - CHECK_UNS_EQ(1.1 * 1024, size); + CHECK_INT_EQ(1.1 * 1024, size); CHECK(parse_size_with_suffix("438.5M", &size)); - CHECK_UNS_EQ(438.5 * 1024, size); + CHECK_INT_EQ(438.5 * 1024, size); CHECK(parse_size_with_suffix("1.0G", &size)); - CHECK_UNS_EQ(1024 * 1024, size); + CHECK_INT_EQ(1024 * 1024, size); CHECK(parse_size_with_suffix("17.1G", &size)); - CHECK_UNS_EQ(17.1 * 1024 * 1024, size); + CHECK_INT_EQ(17.1 * 1024 * 1024, size); } TEST_SUITE_END