]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Add test case for check_for_temporal_macros
authorJoel Rosdahl <joel@rosdahl.net>
Sun, 4 Nov 2012 21:04:25 +0000 (22:04 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Mon, 5 Nov 2012 20:26:47 +0000 (21:26 +0100)
hashutil.c
hashutil.h
test/test_hashutil.c

index a15f2511421ae8445ad07d8703bfad459a0082b1..82b73675c88aa3761adf7b9c36ba03fd7278c5db 100644 (file)
@@ -52,7 +52,7 @@ file_hashes_equal(struct file_hash *fh1, struct file_hash *fh2)
  * Returns a bitmask with HASH_SOURCE_CODE_FOUND_DATE and
  * HASH_SOURCE_CODE_FOUND_TIME set appropriately.
  */
-static int
+int
 check_for_temporal_macros(const char *str, size_t len)
 {
        int result = 0;
index dbbc10d5da6e410cc9c1eedc3b13fe0a3fdc3404..ae9abf19f190a974a08cd54211c3e2a1338317e0 100644 (file)
@@ -21,6 +21,7 @@ int file_hashes_equal(struct file_hash *fh1, struct file_hash *fh2);
 #define        HASH_SOURCE_CODE_FOUND_DATE 2
 #define        HASH_SOURCE_CODE_FOUND_TIME 4
 
+int check_for_temporal_macros(const char *str, size_t len);
 int hash_source_code_string(
        struct conf *conf, struct mdfour *hash, const char *str, size_t len,
        const char *path);
index 225841a5ad847ce6c38abcf737e39f90d4bec7a4..98316f014936d84e58f9cc324bb45bb8cac99f91 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010 Joel Rosdahl
+ * Copyright (C) 2010, 2012 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
@@ -99,4 +99,82 @@ TEST(hash_multicommand_output_error_handling)
        CHECK(!hash_multicommand_output(&h2, "false; true", "not used"));
 }
 
+TEST(check_for_temporal_macros)
+{
+       const char time_start[] =
+               "__TIME__\n"
+               "int a;\n";
+       const char time_middle[] =
+               "#define a __TIME__\n"
+               "int a;\n";
+       const char time_end[] =
+               "#define a __TIME__";
+
+       const char date_start[] =
+               "__DATE__\n"
+               "int ab;\n";
+       const char date_middle[] =
+               "#define ab __DATE__\n"
+               "int ab;\n";
+       const char date_end[] =
+               "#define ab __DATE__";
+
+       const char no_temporal[] =
+               "#define ab _ _DATE__\n"
+               "#define ab __ DATE__\n"
+               "#define ab __D ATE__\n"
+               "#define ab __DA TE__\n"
+               "#define ab __DAT E__\n"
+               "#define ab __DATE __\n"
+               "#define ab __DATE_ _\n"
+               "#define ab _ _TIME__\n"
+               "#define ab __ TIME__\n"
+               "#define ab __T IME__\n"
+               "#define ab __TI ME__\n"
+               "#define ab __TIM E__\n"
+               "#define ab __TIME __\n"
+               "#define ab __TIME_ _\n";
+
+       CHECK(check_for_temporal_macros(time_start + 0, sizeof(time_start) - 0));
+       CHECK(!check_for_temporal_macros(time_start + 1, sizeof(time_start) - 1));
+
+       CHECK(check_for_temporal_macros(time_middle + 0, sizeof(time_middle) - 0));
+       CHECK(check_for_temporal_macros(time_middle + 1, sizeof(time_middle) - 1));
+       CHECK(check_for_temporal_macros(time_middle + 2, sizeof(time_middle) - 2));
+       CHECK(check_for_temporal_macros(time_middle + 3, sizeof(time_middle) - 3));
+       CHECK(check_for_temporal_macros(time_middle + 4, sizeof(time_middle) - 4));
+       CHECK(check_for_temporal_macros(time_middle + 5, sizeof(time_middle) - 5));
+       CHECK(check_for_temporal_macros(time_middle + 6, sizeof(time_middle) - 6));
+       CHECK(check_for_temporal_macros(time_middle + 7, sizeof(time_middle) - 7));
+
+       CHECK(check_for_temporal_macros(time_end + 0, sizeof(time_end) - 0));
+       CHECK(check_for_temporal_macros(time_end + sizeof(time_end) - 9, 9));
+       CHECK(!check_for_temporal_macros(time_end + sizeof(time_end) - 8, 8));
+
+       CHECK(check_for_temporal_macros(date_start + 0, sizeof(date_start) - 0));
+       CHECK(!check_for_temporal_macros(date_start + 1, sizeof(date_start) - 1));
+
+       CHECK(check_for_temporal_macros(date_middle + 0, sizeof(date_middle) - 0));
+       CHECK(check_for_temporal_macros(date_middle + 1, sizeof(date_middle) - 1));
+       CHECK(check_for_temporal_macros(date_middle + 2, sizeof(date_middle) - 2));
+       CHECK(check_for_temporal_macros(date_middle + 3, sizeof(date_middle) - 3));
+       CHECK(check_for_temporal_macros(date_middle + 4, sizeof(date_middle) - 4));
+       CHECK(check_for_temporal_macros(date_middle + 5, sizeof(date_middle) - 5));
+       CHECK(check_for_temporal_macros(date_middle + 6, sizeof(date_middle) - 6));
+       CHECK(check_for_temporal_macros(date_middle + 7, sizeof(date_middle) - 7));
+
+       CHECK(check_for_temporal_macros(date_end + 0, sizeof(date_end) - 0));
+       CHECK(check_for_temporal_macros(date_end + sizeof(date_end) - 9, 9));
+       CHECK(!check_for_temporal_macros(date_end + sizeof(date_end) - 8, 8));
+
+       CHECK(!check_for_temporal_macros(no_temporal + 0, sizeof(no_temporal) - 0));
+       CHECK(!check_for_temporal_macros(no_temporal + 1, sizeof(no_temporal) - 1));
+       CHECK(!check_for_temporal_macros(no_temporal + 2, sizeof(no_temporal) - 2));
+       CHECK(!check_for_temporal_macros(no_temporal + 3, sizeof(no_temporal) - 3));
+       CHECK(!check_for_temporal_macros(no_temporal + 4, sizeof(no_temporal) - 4));
+       CHECK(!check_for_temporal_macros(no_temporal + 5, sizeof(no_temporal) - 5));
+       CHECK(!check_for_temporal_macros(no_temporal + 6, sizeof(no_temporal) - 6));
+       CHECK(!check_for_temporal_macros(no_temporal + 7, sizeof(no_temporal) - 7));
+}
+
 TEST_SUITE_END