]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
test: Use an int64_t variant of CHECK_INT_EQ for all integer types
authorJoel Rosdahl <joel@rosdahl.net>
Sun, 24 Jul 2011 12:13:15 +0000 (14:13 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 26 Jul 2011 20:11:45 +0000 (22:11 +0200)
configure.ac
test/framework.c
test/framework.h
test/test_argument_processing.c
test/test_conf.c
test/test_counters.c
test/test_stats.c
test/test_util.c

index 2b9278292719dcd3c00884d85b5a46b56f7f2418..64ba35ebd15371d73a275308a7c8d4e6e0c3c4bf 100644 (file)
@@ -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)
 
index 85b4bd4b1408ea14a93d5e819fbd56fd62251fd2..8169fa525edba226a191761205315b3e1862fd22 100644 (file)
@@ -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);
index ec108c255d226054d809bcb5118304a53974b1ae..5f1a77083e54769abfb36319ca330343a919021b 100644 (file)
 
 #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);
index 0d8bd491c7f7cd2fad0e6d7b7ea301dc3fc4f41a..8a0ecbdfcf684f7c5c453ec52a89aca7a3f8b174 100644 (file)
@@ -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);
 }
index 4b6c09f8741f1ed125e4c7fb9ec98dbfb294e3cf..2ee60012d005e35d51c9084d010e25cc0dd9b959 100644 (file)
@@ -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);
index a00d1ee8f39c9ae71a958c7a878bdb0da47efd95..df12a8b59817a79afea094b4da3fd64be8c987bb 100644 (file)
@@ -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);
 }
index acf6a3423d4e4814b95b53dc77d2b6b216a1537f..79482d104012d6ca4c1e658c6ffbde8d835921a2 100644 (file)
@@ -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);
 }
index 50fc7561035ea477a8ead043ba6ae2a8e817729a..f00c036649f85543c9fc7d4007f9d5e13afa1669 100644 (file)
@@ -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