]> Kevux Git Server - kevux-tools/commitdiff
Progress: Continue working on completing the remove program.
authorKevin Day <Kevin@kevux.org>
Sun, 23 Mar 2025 04:05:42 +0000 (23:05 -0500)
committerKevin Day <Kevin@kevux.org>
Sun, 23 Mar 2025 04:07:42 +0000 (23:07 -0500)
Update the `fakefile` to allow for choosing only just `remove` or just `tacocat`.

Begin adding the date tests.
Fix problems as encountered.
Make the start and end dates initially the same when populated from the clock.

24 files changed:
data/build/fakefile
data/build/remove/settings-mocks.remove
data/build/remove/settings-tests.remove
sources/c/program/kevux/tools/remove/main/common.c
sources/c/program/kevux/tools/remove/main/convert.c
sources/c/program/kevux/tools/remove/main/convert.h
sources/c/program/kevux/tools/remove/main/preprocess.c
tests/unit/remove/c/mock-remove.c
tests/unit/remove/c/mock-remove.h
tests/unit/remove/c/test-remove-date_changed.c [new file with mode: 0644]
tests/unit/remove/c/test-remove-date_changed.h [new file with mode: 0644]
tests/unit/remove/c/test-remove-directory_no_args.c
tests/unit/remove/c/test-remove-directory_recurse_simple.c
tests/unit/remove/c/test-remove-directory_tree_simple.c
tests/unit/remove/c/test-remove-file_mode.c
tests/unit/remove/c/test-remove-file_type.c
tests/unit/remove/c/test-remove-force.c
tests/unit/remove/c/test-remove-group.c
tests/unit/remove/c/test-remove-print_help.c
tests/unit/remove/c/test-remove-print_version.c
tests/unit/remove/c/test-remove-regular_no_args.c
tests/unit/remove/c/test-remove-user.c
tests/unit/remove/c/test-remove.c
tests/unit/remove/c/test-remove.h

index 1f8c1846350b0b0782be4a69147e978d80e7418e..255b8faf95511118a17ee4dd26cb569d4ac6cd76 100644 (file)
@@ -8,8 +8,14 @@ settings:
   environment LANG LC_ALL LC_COLLATE LC_CTYPE LC_FASTMSG LC_MESSAGES LC_MONETARY LC_NUMERIC LC_TIME LOCPATH NLSPATH
 
 main:
+  operate remove
+  operate tacocat
+
+remove:
   build remove/settings
   build remove/settings.remove
+
+tacocat:
   build tacocat/settings
   build tacocat/settings.tacocat
 
index 15e4dec5cc3ff22ae289ee95720d971f41a41cdb..dab8034a89455499320ae3a31bf599ec140ed73f 100644 (file)
@@ -93,6 +93,7 @@ flags -Wl,--wrap=f_file_exists
 flags -Wl,--wrap=f_file_is
 flags -Wl,--wrap=f_file_remove
 flags -Wl,--wrap=f_file_stat
+flags -Wl,--wrap=f_time_clock_get
 flags -Wl,--wrap=fl_directory_do
 flags -Wl,--wrap=fll_program_print_version
 flags -Wl,--wrap=geteuid
index 5d23b85764310037e7ca18b6e4947088eff1b19e..a2d78847ac2ccadc0e530ad5b48666ea5ee8a19f 100644 (file)
@@ -32,9 +32,10 @@ build_libraries-individual_thread -lf_thread
 build_sources_program test-remove.c
 build_sources_program test-remove-print_help.c test-remove-print_version.c
 build_sources_program test-remove-file_mode.c test-remove-file_type.c
+build_sources_program test-remove-date_changed.c
+build_sources_program test-remove-directory_no_args.c test-remove-directory_recurse_simple.c test-remove-directory_tree_simple.c
 build_sources_program test-remove-force.c
 build_sources_program test-remove-group.c
-build_sources_program test-remove-directory_no_args.c test-remove-directory_recurse_simple.c test-remove-directory_tree_simple.c
 build_sources_program test-remove-regular_no_args.c
 build_sources_program test-remove-user.c
 
index 058a40eac9c488048051a5e3ad07f5d8619f3c92..68976d241317b0646947dc95dd58f935bfa02468 100644 (file)
@@ -181,6 +181,12 @@ extern "C" {
         kt_remove_long_updated_s,
       };
 
+      const uint64_t flags[] = {
+        kt_remove_main_flag_accessed_d,
+        kt_remove_main_flag_changed_d,
+        kt_remove_main_flag_updated_d,
+      };
+
       for (uint8_t p = 0; p < 3; ++p) {
 
         if (!(parameters[p]->result & f_console_result_found_e)) continue;
@@ -239,39 +245,41 @@ extern "C" {
 
           main->setting.state.status = F_known_not;
 
-          {
-            for (i = 0; i < total_arguments; i += 2) {
+          for (i = 0; i < total_arguments; i += 2) {
 
-              index = parameters[p]->values.array[i];
-              dates[p]->array[dates[p]->used].operation = 0;
-              dates[p]->array[dates[p]->used].type = 0;
+            index = parameters[p]->values.array[i];
+            dates[p]->array[dates[p]->used].operation = 0;
+            dates[p]->array[dates[p]->used].type = 0;
 
-              for (j = 0; j < 12; ++j) {
+            for (j = 0; j < 12; ++j) {
 
-                if (f_compare_dynamic(main->program.parameters.arguments.array[index], strings[j]) == F_equal_to) {
-                  dates[p]->array[dates[p]->used].operation = enumerations[j];
+              if (f_compare_dynamic(main->program.parameters.arguments.array[index], strings[j]) == F_equal_to) {
+                dates[p]->array[dates[p]->used].operation = enumerations[j];
 
-                  index2 = parameters[p]->values.array[i + 1];
+                index2 = parameters[p]->values.array[i + 1];
 
-                  kt_remove_convert_date(main, main->program.parameters.arguments.array[index2], &dates[p]->array[dates[p]->used]);
-                  if (F_status_is_error(main->setting.state.status)) return;
+                kt_remove_convert_date(main, main->program.parameters.arguments.array[index2], &dates[p]->array[dates[p]->used]);
+                if (F_status_is_error(main->setting.state.status)) return;
 
-                  ++dates[p]->used;
+                ++dates[p]->used;
 
-                  break;
-                }
+                break;
+              }
 
-                if (kt_remove_signal_check(main)) return;
-              } // for
+              if (kt_remove_signal_check(main)) return;
+            } // for
 
-              if (j == 12) {
-                main->setting.state.status = F_status_set_error(F_parameter);
+            if (j == 12) {
+              main->setting.state.status = F_status_set_error(F_parameter);
 
-                kt_remove_print_error_parameter_unknown_value(&main->program.error, f_console_symbol_long_normal_s, longs[p], main->program.parameters.arguments.array[index]);
+              kt_remove_print_error_parameter_unknown_value(&main->program.error, f_console_symbol_long_normal_s, longs[p], main->program.parameters.arguments.array[index]);
 
-                return;
-              }
-            } // for
+              return;
+            }
+          } // for
+
+          if (j < 12) {
+            main->setting.flag |= flags[p];
           }
 
           main->setting.flag |= kt_remove_main_flag_option_used_d;
index b137bdf2e5843611ae82b2d6c1c7053c359e439d..36c8e15181a78e7fc86658d8c5fefb0e52ea81e5 100644 (file)
@@ -369,15 +369,12 @@ extern "C" {
     main->setting.state.status = f_time_clock_get(CLOCK_REALTIME, &now);
     if (F_status_is_error(main->setting.state.status)) return;
 
-    date->start_year = kt_remove_time_year_unix_epoch_d;
-    date->start_second = now.tv_sec;
-    date->start_nanosecond = 0;
-    date->stop_year = kt_remove_time_year_unix_epoch_d;
-    date->stop_second = 0;
-    date->stop_nanosecond = 0;
+    date->start_year = date->stop_year = kt_remove_time_year_unix_epoch_d;
+    date->start_second = date->stop_second = now.tv_sec;
+    date->start_nanosecond = date->stop_nanosecond = 0;
 
     if (date->type == kt_remove_flag_date_now_d) {
-      date->start_nanosecond = now.tv_nsec;
+      date->start_nanosecond = date->stop_nanosecond = now.tv_nsec;
 
       if (!(main->setting.flag & kt_remove_main_flag_utc_d)) {
         kt_remove_convert_timezone(main, &date->start_year, &date->start_second);
@@ -407,9 +404,18 @@ extern "C" {
       }
     }
     else if (date->type == kt_remove_flag_date_tomorrow_d) {
-      date->start_second += kt_remove_time_seconds_in_day_d;
+      if (date->start_second > kt_remove_time_seconds_in_year_d) {
+        date->stop_year = ++date->start_year;
+        date->start_second -= kt_remove_time_seconds_in_year_d;
+      }
+
       date->stop_second = date->start_second + kt_remove_time_seconds_in_day_d;
 
+      if (date->stop_second > kt_remove_time_seconds_in_year_d) {
+        ++date->stop_year;
+        date->stop_second -= kt_remove_time_seconds_in_year_d;
+      }
+
       if (date->stop_second < date->start_second) {
         main->setting.state.status = F_status_set_error(F_number_overflow);
 
@@ -417,8 +423,20 @@ extern "C" {
       }
     }
     else if (date->type == kt_remove_flag_date_yesterday_d) {
+      if (kt_remove_time_seconds_in_day_d > date->start_second) {
+        if (date->start_year) {
+          --date->start_year;
+          date->start_second = kt_remove_time_seconds_in_year_d;
+        }
+        else {
+          main->setting.state.status = F_status_set_error(F_number_underflow);
+
+          return;
+        }
+      }
+
       date->start_second -= kt_remove_time_seconds_in_day_d;
-      date->stop_second = date->start_second;
+      date->stop_second = date->start_second + kt_remove_time_seconds_in_day_d;
     }
 
     main->setting.state.status = F_okay;
index 2775b83830cfea65e1a525bdc1798c356ea39bcf..c0de70755c55cc38c62a46b0a480040ebd319938 100644 (file)
@@ -75,12 +75,14 @@ extern "C" {
  * - Relative strings: 'now', 'today', 'tomorrow', and 'yesterday'.
  *
  * For 'now', the current time in seconds is returned.
- * For 'today', the start of the day is returned.
+ * For 'today', the start of the day of 'now' is returned.
  * For 'tomorrow', the start of the day after 'today' is returned.
  * For 'yesterday', the start of the day before 'today' is returned.
  *
  * Only a limited set of 'time' string values are implemented in this project.
- * More 'time' string values will likely be implemented in a not yet existent 'f_time' project in FLL 0.7 or greater (possibly including fl_time and fll_time).
+ *
+ * The stop times are set to start of the next day after the 'today', 'tomorrow', or 'yesterday'.
+ * For 'now', the stop times are set exactly the same as the start times.
  *
  * @param main
  *   The main program and settings data.
@@ -91,22 +93,20 @@ extern "C" {
  *     F_okay on success.
  *     F_data_not on success, but buffer is empty or there is no data to process.
  *
- *     F_buffer (with error bit) if the buffer is invalid.
+ *     F_number_overflow (with error bit) if the number is too large (such as doing 'tomorrow' at max integer year and day).
+ *     F_number_underflow (with error bit) if the number is too small (such as doing 'yesterday' at year 0, day 0).
  *     F_parameter (with error bit) if a parameter is invalid.
- *     F_prohibited (with error bit) if the system does not permit accessing the system clock.
- *     F_failure (with error bit) for any other failure.
+ *
+ *     Errors (with error bit) from: f_time_clock_get().
+ *     Errors (with error bit) from: kt_remove_convert_timezone().
  * @param date
  *   The converted date.
  *
  *   Must not be NULL.
  *
- * @see clock_gettime()
- *
- * @see f_utf_is_digit()
- * @see f_utf_is_whitespace()
- * @see fl_conversion_dynamic_partial_to_unsigned_detect()
+ * @see f_time_clock_get()
  *
- * @see kt_remove_get_date_relative()
+ * @see kt_remove_convert_timezone()
  */
 #ifndef _di_kt_remove_convert_date_relative_
   extern void kt_remove_convert_date_relative(kt_remove_main_t * const main, kt_remove_date_t * const date);
index eb6dc8bc6647873fd06410a917476e73d41665db..6b0b3251fb7bc4601fbb6ed8c60222b11b28cdfd 100644 (file)
@@ -44,7 +44,6 @@ extern "C" {
     kt_remove_print_simulate_operate_file_exists(&main->program.output, path, flag_out);
 
     if (main->setting.state.status == F_false) {
-
       if (main->setting.flag & kt_remove_main_flag_force_d) {
         kt_remove_print_simulate_operate_boolean(&main->program.output, kt_remove_force_s, F_true);
       }
@@ -471,6 +470,12 @@ extern "C" {
       statistics.st_mtim,
     };
 
+    const uint8_t skips[] = {
+      !(main->setting.flag & kt_remove_main_flag_accessed_d),
+      !(main->setting.flag & kt_remove_main_flag_changed_d),
+      !(main->setting.flag & kt_remove_main_flag_updated_d),
+    };
+
     const f_string_static_t names[] = {
       kt_remove_long_accessed_s,
       kt_remove_long_changed_s,
@@ -479,14 +484,18 @@ extern "C" {
 
     f_status_t result = F_false;
     f_string_static_t name_type = f_string_empty_s;
-    f_number_unsigned_t match_year = 0;
     f_number_unsigned_t match_second = 0;
-    f_number_unsigned_t start_year = 0;
+    f_number_unsigned_t match_year = 0;
     f_number_unsigned_t start_second = 0;
+    f_number_unsigned_t start_year = 0;
     f_number_unsigned_t stop_second = 0;
+    f_number_unsigned_t stop_year = 0;
+    uint8_t start_is_stop = F_false;
 
     for (i = 0; i < 3; ++i) {
 
+      if (skips[i]) continue;
+
       for (j = 0; j < dates[i]->used; ++j) {
 
         if (kt_remove_signal_check(main)) return;
@@ -497,10 +506,13 @@ extern "C" {
         start_year = dates[i]->array[j].start_year + (dates[i]->array[j].start_second / kt_remove_time_seconds_in_year_d);
         start_second = dates[i]->array[j].start_second % kt_remove_time_seconds_in_year_d;
 
+        start_is_stop = dates[i]->array[j].start_year == dates[i]->array[j].stop_year && dates[i]->array[j].start_second == dates[i]->array[j].stop_second && dates[i]->array[j].start_nanosecond == dates[i]->array[j].stop_nanosecond;
+
         name_type = f_string_empty_s;
         result = F_okay;
 
         if (dates[i]->array[j].type == kt_remove_flag_date_today_d || dates[i]->array[j].type == kt_remove_flag_date_tomorrow_d || dates[i]->array[j].type == kt_remove_flag_date_yesterday_d) {
+          stop_year = dates[i]->array[j].stop_year + (dates[i]->array[j].stop_second / kt_remove_time_seconds_in_year_d);
           stop_second = dates[i]->array[j].stop_second % kt_remove_time_seconds_in_year_d;
 
           if (dates[i]->array[j].operation == kt_remove_flag_date_equal_d) {
@@ -511,7 +523,7 @@ extern "C" {
               if (match_second > start_second && match_second < stop_second) {
                 result = F_true;
               }
-              else if (match_second == start_second && times[i].tv_nsec >= dates[i]->array[j].start_nanosecond && times[i].tv_nsec < dates[i]->array[j].stop_nanosecond) {
+              else if (match_second == start_second && times[i].tv_nsec >= dates[i]->array[j].start_nanosecond && (start_is_stop || times[i].tv_nsec < dates[i]->array[j].stop_nanosecond)) {
                 result = F_true;
               }
             }
@@ -543,7 +555,7 @@ extern "C" {
               if (match_second < stop_second) {
                 result = F_true;
               }
-              else if (match_second == stop_second && times[i].tv_nsec < dates[i]->array[j].stop_nanosecond) {
+              else if (match_second == stop_second && times[i].tv_nsec <= dates[i]->array[j].start_nanosecond && (start_is_stop || times[i].tv_nsec < dates[i]->array[j].stop_nanosecond)) {
                 result = F_true;
               }
             }
@@ -552,14 +564,14 @@ extern "C" {
             name_type = kt_remove_date_symbol_more_s;
             result = F_false;
 
-            if (match_year > start_year) {
+            if (match_year > stop_year) {
               result = F_true;
             }
-            else if (match_year == start_year) {
+            else if (match_year == stop_year) {
               if (match_second > stop_second) {
                 result = F_true;
               }
-              else if (match_second == stop_second && times[i].tv_nsec >= dates[i]->array[j].stop_nanosecond) {
+              else if (match_second == stop_second && times[i].tv_nsec > dates[i]->array[j].stop_nanosecond) {
                 result = F_true;
               }
             }
@@ -596,13 +608,7 @@ extern "C" {
         }
         else if (dates[i]->array[j].operation == kt_remove_flag_date_equal_d) {
           name_type = kt_remove_date_symbol_equal_s;
-
-          if (match_year == start_year && match_second == start_second && times[i].tv_nsec == dates[i]->array[j].start_nanosecond) {
-            result = F_true;
-          }
-          else {
-            result = F_false;
-          }
+          result = match_year == start_year && match_second == start_second && times[i].tv_nsec == dates[i]->array[j].start_nanosecond;
         }
         else if (dates[i]->array[j].operation == kt_remove_flag_date_less_d) {
           name_type = kt_remove_date_symbol_less_s;
@@ -624,14 +630,14 @@ extern "C" {
           name_type = kt_remove_date_symbol_less_equal_s;
           result = F_false;
 
-          if (match_year < start_year) {
+          if (match_year < stop_year) {
             result = F_true;
           }
-          else if (match_year == start_year) {
-            if (match_second < start_second) {
+          else if (match_year == stop_year) {
+            if (match_second < stop_second) {
               result = F_true;
             }
-            else if (match_second == start_second && times[i].tv_nsec <= dates[i]->array[j].start_nanosecond) {
+            else if (match_second == stop_second && times[i].tv_nsec <= dates[i]->array[j].stop_nanosecond) {
               result = F_true;
             }
           }
@@ -670,13 +676,7 @@ extern "C" {
         }
         else if (dates[i]->array[j].operation == kt_remove_flag_date_not_d) {
           name_type = kt_remove_date_symbol_not_s;
-
-          if (match_year != start_year || match_second != start_second || times[i].tv_nsec != dates[i]->array[j].start_nanosecond) {
-            result = F_true;
-          }
-          else {
-            result = F_false;
-          }
+          result = match_year != start_year || match_second != start_second || times[i].tv_nsec != dates[i]->array[j].start_nanosecond;
         }
 
         if (name_type.used) {
index becce9c6f5052bb9470a503b2242636b94599adc..b3cb053112d28fd8b72f04c4de0b85fee3899ee9 100644 (file)
@@ -5,7 +5,7 @@ extern "C" {
 #endif
 
 int mock_unwrap = 0;
-int mock_unwrap_fl_directory_do = 0;
+int mock_unwrap_f_time_clock_get = 0;
 
 f_status_t mock_status = 0;
 
@@ -60,6 +60,19 @@ f_status_t __wrap_f_file_stat(const f_string_static_t path, const bool dereferen
   return mock_type(f_status_t);
 }
 
+f_status_t __wrap_f_time_clock_get(const clockid_t code, f_time_spec_t * const time) {
+
+  if (mock_unwrap_f_time_clock_get) {
+    return __real_f_time_clock_get(code, time);
+  }
+
+  f_time_spec_t * const mocked_time = mock_ptr_type(f_time_spec_t *);
+
+  *time = *mocked_time;
+
+  return mock_type(f_status_t);
+}
+
 void __wrap_fl_directory_do(const f_string_static_t path, f_directory_recurse_do_t * const recurse) {
 
   if (!recurse) return;
index e3cb847b8165b3d1c13789cd125fe36c4c01fa86..2ee899a146866c46f6baae72bd8bc32d0f3ef7eb 100644 (file)
@@ -30,9 +30,12 @@ extern "C" {
 const static int mock_errno_generic = 32767;
 
 extern int mock_unwrap;
+extern int mock_unwrap_f_time_clock_get;
 
 extern f_status_t mock_status;
 
+extern f_status_t __real_f_time_clock_get(const clockid_t code, f_time_spec_t * const time);
+
 extern void __real_fl_directory_do(const f_string_static_t path, f_directory_recurse_do_t * const recurse);
 
 extern f_status_t __wrap_f_account_group_id_by_name(const f_string_static_t name, f_gid_t * const id);
@@ -46,6 +49,8 @@ extern f_status_t __wrap_f_file_is(const f_string_static_t path, const int type,
 extern f_status_t __wrap_f_file_remove(const f_string_static_t path);
 extern f_status_t __wrap_f_file_stat(const f_string_static_t path, const bool dereference, struct stat * const stat_file);
 
+extern f_status_t __wrap_f_time_clock_get(const clockid_t code, f_time_spec_t * const time);
+
 extern void __wrap_fl_directory_do(const f_string_static_t path, f_directory_recurse_do_t * const recurse);
 
 extern f_status_t __wrap_fll_program_print_version(fl_print_t * const print, const f_string_static_t version);
diff --git a/tests/unit/remove/c/test-remove-date_changed.c b/tests/unit/remove/c/test-remove-date_changed.c
new file mode 100644 (file)
index 0000000..6867e36
--- /dev/null
@@ -0,0 +1,323 @@
+#include "test-remove.h"
+#include "test-remove-date_changed.h"
+
+#include <program/kevux/tools/remove/remove/main.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void test__kt_remove__date_changed__now_works(void **state) {
+
+  mock_unwrap = 0;
+  mock_unwrap_f_time_clock_get = 0;
+
+  const f_string_static_t target = macro_f_string_static_t_initialize_1("to_remove", 0, 9);
+
+  const uint8_t types_total = 8;
+  const uint8_t dates_total = 24;
+
+  struct stat stats[types_total];
+
+  memset(stats, 0, sizeof(struct stat) * types_total);
+
+  stats[0].st_mode = F_file_mode_all_d | F_file_type_block_d;
+  stats[1].st_mode = F_file_mode_all_d | F_file_type_character_d;
+  stats[2].st_mode = F_file_mode_all_d | F_file_type_directory_d;
+  stats[3].st_mode = F_file_mode_all_d | F_file_type_fifo_d;
+  stats[4].st_mode = F_file_mode_all_d | F_file_type_link_d;
+  stats[5].st_mode = F_file_mode_all_d | F_file_type_regular_d;
+  stats[6].st_mode = F_file_mode_all_d | F_file_type_socket_d;
+  stats[7].st_mode = F_file_mode_all_d & ~S_IFMT;
+
+  const f_string_static_t parameter = macro_f_string_static_t_initialize_1("now", 0, 3);
+
+  const f_string_static_t operators[] = {
+    kt_remove_date_symbol_equal_s,
+    kt_remove_date_symbol_equal_s,
+    kt_remove_date_symbol_equal_s,
+    kt_remove_date_symbol_equal_s,
+    kt_remove_date_symbol_less_s,
+    kt_remove_date_symbol_less_s,
+    kt_remove_date_symbol_less_s,
+    kt_remove_date_symbol_less_s,
+    kt_remove_date_symbol_less_equal_s,
+    kt_remove_date_symbol_less_equal_s,
+    kt_remove_date_symbol_less_equal_s,
+    kt_remove_date_symbol_less_equal_s,
+    kt_remove_date_symbol_more_s,
+    kt_remove_date_symbol_more_s,
+    kt_remove_date_symbol_more_s,
+    kt_remove_date_symbol_more_s,
+    kt_remove_date_symbol_more_equal_s,
+    kt_remove_date_symbol_more_equal_s,
+    kt_remove_date_symbol_more_equal_s,
+    kt_remove_date_symbol_more_equal_s,
+    kt_remove_date_symbol_not_s,
+    kt_remove_date_symbol_not_s,
+    kt_remove_date_symbol_not_s,
+    kt_remove_date_symbol_not_s,
+  };
+
+  const f_time_spec_t time_spec_dates[] = {
+    macro_f_time_spec_t_initialize_1(2 * 86400, 345), // Equal
+    macro_f_time_spec_t_initialize_1(2 * 86400, 0),
+    macro_f_time_spec_t_initialize_1(3 * 86400, 10),
+    macro_f_time_spec_t_initialize_1(1 * 86400, 4000),
+    macro_f_time_spec_t_initialize_1(2 * 86400, 345), // Less
+    macro_f_time_spec_t_initialize_1(2 * 86400, 0),
+    macro_f_time_spec_t_initialize_1(3 * 86400, 10),
+    macro_f_time_spec_t_initialize_1(1 * 86400, 4000),
+    macro_f_time_spec_t_initialize_1(2 * 86400, 345), // Less Equal
+    macro_f_time_spec_t_initialize_1(2 * 86400, 0),
+    macro_f_time_spec_t_initialize_1(3 * 86400, 10),
+    macro_f_time_spec_t_initialize_1(1 * 86400, 4000),
+    macro_f_time_spec_t_initialize_1(2 * 86400, 345), // More
+    macro_f_time_spec_t_initialize_1(2 * 86400, 0),
+    macro_f_time_spec_t_initialize_1(3 * 86400, 10),
+    macro_f_time_spec_t_initialize_1(1 * 86400, 4000),
+    macro_f_time_spec_t_initialize_1(2 * 86400, 345), // More Equal
+    macro_f_time_spec_t_initialize_1(2 * 86400, 0),
+    macro_f_time_spec_t_initialize_1(3 * 86400, 10),
+    macro_f_time_spec_t_initialize_1(1 * 86400, 4000),
+    macro_f_time_spec_t_initialize_1(2 * 86400, 345), // Not
+    macro_f_time_spec_t_initialize_1(2 * 86400, 0),
+    macro_f_time_spec_t_initialize_1(3 * 86400, 10),
+    macro_f_time_spec_t_initialize_1(1 * 86400, 4000),
+  };
+
+  const f_time_spec_t time_spec_clocks = macro_f_time_spec_t_initialize_1(2 * 86400, 234);
+
+  bool time_spec_removes[] = {
+    F_true, // Equal
+    F_false,
+    F_false,
+    F_false,
+    F_false, // Less
+    F_true,
+    F_false,
+    F_true,
+    F_true, // Less Equal
+    F_true,
+    F_false,
+    F_true,
+    F_false, // More
+    F_false,
+    F_true,
+    F_false,
+    F_true, // More Equal
+    F_false,
+    F_true,
+    F_false,
+    F_false, // Not
+    F_true,
+    F_true,
+    F_true,
+  };
+
+  {
+    uint8_t type = 0;
+    uint8_t date = 0;
+
+    for (; type < types_total; ++type) {
+
+      for (date = 0; date < dates_total; ++date) {
+
+        const f_string_t argv[] = { "mocked_main", target.string, "-" KT_REMOVE_short_changed_s, operators[date].string, parameter.string, 0 };
+
+        stats[type].st_ctim = time_spec_dates[date];
+
+        // Pre-process file.
+        will_return(__wrap_f_file_exists, F_true);
+        will_return(__wrap_f_file_is, macro_f_file_type_is_link(stats[type].st_mode));
+        will_return(__wrap_f_file_stat, &stats[type]);
+        will_return(__wrap_f_file_stat, F_okay);
+
+        if (macro_f_file_type_is_directory(stats[type].st_mode)) {
+          will_return(__wrap_f_directory_empty, F_true);
+        }
+
+        will_return(__wrap_f_time_clock_get, &time_spec_clocks);
+        will_return(__wrap_f_time_clock_get, F_okay);
+
+        if (time_spec_removes[date]) {
+          if (macro_f_file_type_is_directory(stats[type].st_mode)) {
+            will_return(__wrap_fl_directory_do, 1);
+            will_return(__wrap_fl_directory_do, &target);
+            will_return(__wrap_fl_directory_do, &target);
+            will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_e | f_directory_recurse_do_flag_directory_e | f_directory_recurse_do_flag_top_after_e);
+            will_return(__wrap_f_directory_remove, F_okay);
+          }
+          else {
+            will_return(__wrap_f_file_remove, F_okay);
+          }
+        }
+
+        const int result = kt_main_test__remove(5, argv, 0);
+
+        assert_int_equal(result, 0);
+      } // for
+    } // for
+  }
+}
+
+void test__kt_remove__date_changed__tomorrow_works(void **state) {
+
+  mock_unwrap = 0;
+  mock_unwrap_f_time_clock_get = 0;
+
+  const f_string_static_t target = macro_f_string_static_t_initialize_1("to_remove", 0, 9);
+
+  const uint8_t types_total = 8;
+  const uint8_t dates_total = 24;
+
+  struct stat stats[types_total];
+
+  memset(stats, 0, sizeof(struct stat) * types_total);
+
+  stats[0].st_mode = F_file_mode_all_d | F_file_type_block_d;
+  stats[1].st_mode = F_file_mode_all_d | F_file_type_character_d;
+  stats[2].st_mode = F_file_mode_all_d | F_file_type_directory_d;
+  stats[3].st_mode = F_file_mode_all_d | F_file_type_fifo_d;
+  stats[4].st_mode = F_file_mode_all_d | F_file_type_link_d;
+  stats[5].st_mode = F_file_mode_all_d | F_file_type_regular_d;
+  stats[6].st_mode = F_file_mode_all_d | F_file_type_socket_d;
+  stats[7].st_mode = F_file_mode_all_d & ~S_IFMT;
+
+  const f_string_static_t parameter = macro_f_string_static_t_initialize_1("tomorrow", 0, 8);
+
+  const f_string_static_t operators[] = {
+    kt_remove_date_symbol_equal_s,
+    kt_remove_date_symbol_equal_s,
+    kt_remove_date_symbol_equal_s,
+    kt_remove_date_symbol_equal_s,
+    kt_remove_date_symbol_less_s,
+    kt_remove_date_symbol_less_s,
+    kt_remove_date_symbol_less_s,
+    kt_remove_date_symbol_less_s,
+    kt_remove_date_symbol_less_equal_s,
+    kt_remove_date_symbol_less_equal_s,
+    kt_remove_date_symbol_less_equal_s,
+    kt_remove_date_symbol_less_equal_s,
+    kt_remove_date_symbol_more_s,
+    kt_remove_date_symbol_more_s,
+    kt_remove_date_symbol_more_s,
+    kt_remove_date_symbol_more_s,
+    kt_remove_date_symbol_more_equal_s,
+    kt_remove_date_symbol_more_equal_s,
+    kt_remove_date_symbol_more_equal_s,
+    kt_remove_date_symbol_more_equal_s,
+    kt_remove_date_symbol_not_s,
+    kt_remove_date_symbol_not_s,
+    kt_remove_date_symbol_not_s,
+    kt_remove_date_symbol_not_s,
+  };
+
+  const f_time_spec_t time_spec_dates[] = {
+    macro_f_time_spec_t_initialize_1(2 * 86400, 345), // Equal
+    macro_f_time_spec_t_initialize_1(2 * 86400, 0),
+    macro_f_time_spec_t_initialize_1(3 * 86400, 10),
+    macro_f_time_spec_t_initialize_1(1 * 86400, 4000),
+    macro_f_time_spec_t_initialize_1(2 * 86400, 345), // Less
+    macro_f_time_spec_t_initialize_1(2 * 86400, 0),
+    macro_f_time_spec_t_initialize_1(3 * 86400, 10),
+    macro_f_time_spec_t_initialize_1(1 * 86400, 4000),
+    macro_f_time_spec_t_initialize_1(2 * 86400, 345), // Less Equal
+    macro_f_time_spec_t_initialize_1(2 * 86400, 0),
+    macro_f_time_spec_t_initialize_1(3 * 86400, 10),
+    macro_f_time_spec_t_initialize_1(1 * 86400, 4000),
+    macro_f_time_spec_t_initialize_1(2 * 86400, 345), // More
+    macro_f_time_spec_t_initialize_1(2 * 86400, 0),
+    macro_f_time_spec_t_initialize_1(3 * 86400, 10),
+    macro_f_time_spec_t_initialize_1(1 * 86400, 4000),
+    macro_f_time_spec_t_initialize_1(2 * 86400, 345), // More Equal
+    macro_f_time_spec_t_initialize_1(2 * 86400, 0),
+    macro_f_time_spec_t_initialize_1(3 * 86400, 10),
+    macro_f_time_spec_t_initialize_1(1 * 86400, 4000),
+    macro_f_time_spec_t_initialize_1(2 * 86400, 345), // Not
+    macro_f_time_spec_t_initialize_1(2 * 86400, 0),
+    macro_f_time_spec_t_initialize_1(3 * 86400, 10),
+    macro_f_time_spec_t_initialize_1(1 * 86400, 4000),
+  };
+
+  const f_time_spec_t time_spec_clocks = macro_f_time_spec_t_initialize_1(2 * 86400, 345);
+
+  bool time_spec_removes[] = {
+    F_false, // Equal
+    F_false,
+    F_true,
+    F_false,
+    F_true, // Less
+    F_true,
+    F_false,
+    F_true,
+    F_true, // Less Equal
+    F_true,
+    F_false,
+    F_true,
+    F_false, // More
+    F_false,
+    F_true,
+    F_false,
+    F_false, // More Equal
+    F_false,
+    F_true,
+    F_false,
+    F_true, // Not
+    F_true,
+    F_true,
+    F_true,
+  };
+
+  {
+    uint8_t type = 0;
+    uint8_t date = 0;
+
+    for (; type < types_total; ++type) {
+
+      for (date = 0; date < dates_total; ++date) {
+
+        const f_string_t argv[] = { "mocked_main", target.string, "-" KT_REMOVE_short_changed_s, operators[date].string, parameter.string, 0 };
+
+        stats[type].st_ctim = time_spec_dates[date];
+
+        // Pre-process file.
+        will_return(__wrap_f_file_exists, F_true);
+        will_return(__wrap_f_file_is, macro_f_file_type_is_link(stats[type].st_mode));
+        will_return(__wrap_f_file_stat, &stats[type]);
+        will_return(__wrap_f_file_stat, F_okay);
+
+        if (macro_f_file_type_is_directory(stats[type].st_mode)) {
+          will_return(__wrap_f_directory_empty, F_true);
+        }
+
+        will_return(__wrap_f_time_clock_get, &time_spec_clocks);
+        will_return(__wrap_f_time_clock_get, F_okay);
+
+        if (time_spec_removes[date]) {
+          if (macro_f_file_type_is_directory(stats[type].st_mode)) {
+            will_return(__wrap_fl_directory_do, 1);
+            will_return(__wrap_fl_directory_do, &target);
+            will_return(__wrap_fl_directory_do, &target);
+            will_return(__wrap_fl_directory_do, f_directory_recurse_do_flag_action_e | f_directory_recurse_do_flag_directory_e | f_directory_recurse_do_flag_top_after_e);
+            will_return(__wrap_f_directory_remove, F_okay);
+          }
+          else {
+            will_return(__wrap_f_file_remove, F_okay);
+          }
+        }
+
+        const int result = kt_main_test__remove(5, argv, 0);
+
+        assert_int_equal(result, 0);
+      } // for
+    } // for
+  }
+}
+
+//@todo macro_f_string_static_t_initialize_1("today", 0, 5),
+//@todo macro_f_string_static_t_initialize_1("yesterday", 0, 9),
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
diff --git a/tests/unit/remove/c/test-remove-date_changed.h b/tests/unit/remove/c/test-remove-date_changed.h
new file mode 100644 (file)
index 0000000..c0621cd
--- /dev/null
@@ -0,0 +1,23 @@
+/**
+ * Kevux Tools - Remove
+ *
+ * Project: Kevux Tools
+ * API Version: 0.5
+ * Licenses: lgpl-2.1-or-later
+ *
+ * Test the remove.
+ */
+#ifndef _TEST__KT_remove__date_changed
+#define _TEST__KT_remove__date_changed
+
+/**
+ * Test that the remove works when the --changed parameter with "now" parameter are passed.
+ */
+extern void test__kt_remove__date_changed__now_works(void **state);
+
+/**
+ * Test that the remove works when the --changed parameter with "tomorrow" parameter are passed.
+ */
+extern void test__kt_remove__date_changed__tomorrow_works(void **state);
+
+#endif // _TEST__KT_remove__date_changed
index cc1790a9141303c0e4a88db2ea5d44a1bd014cbb..e76ea6c34ac9fbe4c4a7b008fca5655a22bd211b 100644 (file)
@@ -10,6 +10,7 @@ extern "C" {
 void test__kt_remove__directory_no_args__one_empty_exists_link(void **state) {
 
   mock_unwrap = 0;
+  mock_unwrap_f_time_clock_get = 1;
 
   const f_string_static_t file = macro_f_string_static_t_initialize_1("to_remove", 0, 9);
 
@@ -100,6 +101,7 @@ void test__kt_remove__directory_no_args__one_empty_exists_link(void **state) {
 void test__kt_remove__directory_no_args__one_empty_exists_link_not(void **state) {
 
   mock_unwrap = 0;
+  mock_unwrap_f_time_clock_get = 1;
 
   const f_string_static_t file = macro_f_string_static_t_initialize_1("to_remove", 0, 9);
 
@@ -190,6 +192,7 @@ void test__kt_remove__directory_no_args__one_empty_exists_link_not(void **state)
 void test__kt_remove__directory_no_args__one_empty_exists_not(void **state) {
 
   mock_unwrap = 0;
+  mock_unwrap_f_time_clock_get = 1;
 
   const f_string_static_t file = macro_f_string_static_t_initialize_1("to_remove", 0, 9);
 
@@ -227,6 +230,7 @@ void test__kt_remove__directory_no_args__one_empty_exists_not(void **state) {
 void test__kt_remove__directory_no_args__one_empty_not_exists_link(void **state) {
 
   mock_unwrap = 0;
+  mock_unwrap_f_time_clock_get = 1;
 
   const f_string_static_t file = macro_f_string_static_t_initialize_1("to_remove", 0, 9);
 
@@ -327,6 +331,7 @@ void test__kt_remove__directory_no_args__one_empty_not_exists_link(void **state)
 void test__kt_remove__directory_no_args__one_empty_not_exists_link_not(void **state) {
 
   mock_unwrap = 0;
+  mock_unwrap_f_time_clock_get = 1;
 
   const f_string_static_t file = macro_f_string_static_t_initialize_1("to_remove", 0, 9);
 
@@ -427,6 +432,7 @@ void test__kt_remove__directory_no_args__one_empty_not_exists_link_not(void **st
 void test__kt_remove__directory_no_args__two_empty_exists_and_not(void **state) {
 
   mock_unwrap = 0;
+  mock_unwrap_f_time_clock_get = 1;
 
   const f_string_static_t file = macro_f_string_static_t_initialize_1("to_remove", 0, 9);
 
@@ -526,6 +532,7 @@ void test__kt_remove__directory_no_args__two_empty_exists_and_not(void **state)
 void test__kt_remove__directory_no_args__two_empty_exists_link(void **state) {
 
   mock_unwrap = 0;
+  mock_unwrap_f_time_clock_get = 1;
 
   const f_string_static_t file = macro_f_string_static_t_initialize_1("to_remove", 0, 9);
 
@@ -664,6 +671,7 @@ void test__kt_remove__directory_no_args__two_empty_exists_link(void **state) {
 void test__kt_remove__directory_no_args__two_empty_exists_link_not(void **state) {
 
   mock_unwrap = 0;
+  mock_unwrap_f_time_clock_get = 1;
 
   const f_string_static_t file = macro_f_string_static_t_initialize_1("to_remove", 0, 9);
 
@@ -802,6 +810,7 @@ void test__kt_remove__directory_no_args__two_empty_exists_link_not(void **state)
 void test__kt_remove__directory_no_args__two_empty_exists_not(void **state) {
 
   mock_unwrap = 0;
+  mock_unwrap_f_time_clock_get = 1;
 
   const f_string_static_t file = macro_f_string_static_t_initialize_1("to_remove", 0, 9);
 
index 21bfc68c15021f69571a835f7f4c2b5d013c4704..04bbef439179a038372d06489b883fadc9b2e9f0 100644 (file)
@@ -10,6 +10,7 @@ extern "C" {
 void test__kt_remove__directory_recurse_simple__one_child_one_exists_link(void **state) {
 
   mock_unwrap = 0;
+  mock_unwrap_f_time_clock_get = 1;
 
   const f_string_static_t target = macro_f_string_static_t_initialize_1("to_remove", 0, 9);
   const f_string_static_t child_1 = macro_f_string_static_t_initialize_1("child_1", 0, 7);
@@ -69,6 +70,7 @@ void test__kt_remove__directory_recurse_simple__one_child_one_exists_link(void *
 void test__kt_remove__directory_recurse_simple__one_child_one_exists_link_not(void **state) {
 
   mock_unwrap = 0;
+  mock_unwrap_f_time_clock_get = 1;
 
   const f_string_static_t target = macro_f_string_static_t_initialize_1("to_remove", 0, 9);
   const f_string_static_t child_1 = macro_f_string_static_t_initialize_1("child_1", 0, 7);
@@ -128,6 +130,7 @@ void test__kt_remove__directory_recurse_simple__one_child_one_exists_link_not(vo
 void test__kt_remove__directory_recurse_simple__one_child_two_exists_link(void **state) {
 
   mock_unwrap = 0;
+  mock_unwrap_f_time_clock_get = 1;
 
   const f_string_static_t target = macro_f_string_static_t_initialize_1("to_remove", 0, 9);
   const f_string_static_t child_1 = macro_f_string_static_t_initialize_1("child_1", 0, 7);
@@ -203,6 +206,7 @@ void test__kt_remove__directory_recurse_simple__one_child_two_exists_link(void *
 void test__kt_remove__directory_recurse_simple__one_child_two_exists_link_not(void **state) {
 
   mock_unwrap = 0;
+  mock_unwrap_f_time_clock_get = 1;
 
   const f_string_static_t target = macro_f_string_static_t_initialize_1("to_remove", 0, 9);
   const f_string_static_t child_1 = macro_f_string_static_t_initialize_1("child_1", 0, 7);
index c5cdb18b67de7759135134a8b463865e9c5b9b31..359d68cb9a1f33b8a4d7f0da8d938d057643991a 100644 (file)
@@ -10,6 +10,7 @@ extern "C" {
 void test__kt_remove__directory_tree_simple__one_child_none_parent_one_exists_link(void **state) {
 
   mock_unwrap = 0;
+  mock_unwrap_f_time_clock_get = 1;
 
   const f_string_static_t target_full = macro_f_string_static_t_initialize_1("parent_1/to_remove", 0, 18);
 
@@ -53,6 +54,7 @@ void test__kt_remove__directory_tree_simple__one_child_none_parent_one_exists_li
 void test__kt_remove__directory_tree_simple__one_child_none_parent_one_exists_link_not(void **state) {
 
   mock_unwrap = 0;
+  mock_unwrap_f_time_clock_get = 1;
 
   const f_string_static_t target_full = macro_f_string_static_t_initialize_1("parent_1/to_remove", 0, 18);
 
@@ -96,6 +98,7 @@ void test__kt_remove__directory_tree_simple__one_child_none_parent_one_exists_li
 void test__kt_remove__directory_tree_simple__one_child_none_parent_two_exists_link(void **state) {
 
   mock_unwrap = 0;
+  mock_unwrap_f_time_clock_get = 1;
 
   const f_string_static_t target_full = macro_f_string_static_t_initialize_1("parent_2/parent_1/to_remove", 0, 18);
 
@@ -149,6 +152,7 @@ void test__kt_remove__directory_tree_simple__one_child_none_parent_two_exists_li
 void test__kt_remove__directory_tree_simple__one_child_none_parent_two_exists_link_not(void **state) {
 
   mock_unwrap = 0;
+  mock_unwrap_f_time_clock_get = 1;
 
   const f_string_static_t target_full = macro_f_string_static_t_initialize_1("parent_2/parent_1/to_remove", 0, 18);
 
index fe4a726124929dd174486e4f2a1db5f97e96c9f7..b37c549023c0c32335978311a1dbc8f21a6b8e6d 100644 (file)
@@ -10,6 +10,7 @@ extern "C" {
 void test__kt_remove__file_mode__different_works(void **state) {
 
   mock_unwrap = 0;
+  mock_unwrap_f_time_clock_get = 1;
 
   const f_string_static_t target = macro_f_string_static_t_initialize_1("to_remove", 0, 9);
 
@@ -115,6 +116,7 @@ void test__kt_remove__file_mode__different_works(void **state) {
 void test__kt_remove__file_mode__same_works(void **state) {
 
   mock_unwrap = 0;
+  mock_unwrap_f_time_clock_get = 1;
 
   const f_string_static_t target = macro_f_string_static_t_initialize_1("to_remove", 0, 9);
 
@@ -220,6 +222,7 @@ void test__kt_remove__file_mode__same_works(void **state) {
 void test__kt_remove__file_mode__similar_works(void **state) {
 
   mock_unwrap = 0;
+  mock_unwrap_f_time_clock_get = 1;
 
   const f_string_static_t target = macro_f_string_static_t_initialize_1("to_remove", 0, 9);
 
@@ -325,6 +328,7 @@ void test__kt_remove__file_mode__similar_works(void **state) {
 void test__kt_remove__file_mode__not_works(void **state) {
 
   mock_unwrap = 0;
+  mock_unwrap_f_time_clock_get = 1;
 
   const f_string_static_t target = macro_f_string_static_t_initialize_1("to_remove", 0, 9);
 
index a1748d589916c1cce3f89263cc58f63673ac9a4b..b15f6f70497447c9f74bc91322cda9584f24a4f7 100644 (file)
@@ -10,6 +10,7 @@ extern "C" {
 void test__kt_remove__file_type__works(void **state) {
 
   mock_unwrap = 0;
+  mock_unwrap_f_time_clock_get = 1;
 
   const f_string_static_t target = macro_f_string_static_t_initialize_1("to_remove", 0, 9);
 
index b5388b89d42437d70cd1a3828f432f3a842c68a4..d68a763ebc43c85843ed0fc066e91fab7abdc9f6 100644 (file)
@@ -10,6 +10,7 @@ extern "C" {
 void test__kt_remove__force__works(void **state) {
 
   mock_unwrap = 0;
+  mock_unwrap_f_time_clock_get = 1;
 
   const f_string_static_t target = macro_f_string_static_t_initialize_1("to_remove", 0, 9);
 
index c1a5aab87bb65f01c4cd1bfa8c2a86a0f90f5172..f452aac24a85e9d272e2973c9990cc68262f6783 100644 (file)
@@ -10,6 +10,7 @@ extern "C" {
 void test__kt_remove__group__name_works(void **state) {
 
   mock_unwrap = 0;
+  mock_unwrap_f_time_clock_get = 1;
 
   const f_string_static_t target = macro_f_string_static_t_initialize_1("to_remove", 0, 9);
   const f_string_t argv[] = { "mocked_main", target.string, "-" KT_REMOVE_short_group_s, "some_name", 0 };
index 6c66c907acbc2fa7ba18e632fc0654f03ea90935..5845067298a6dd245ceb40c05ace8221edfa8608 100644 (file)
@@ -10,6 +10,7 @@ extern "C" {
 void test__kt_remove__print_help__works(void **state) {
 
   mock_unwrap = 0;
+  mock_unwrap_f_time_clock_get = 1;
 
   {
     const f_string_t argv[] = { "mocked_main", "--" F_console_standard_long_help_s, 0 };
index 92d6d35553c56e4e57cce5f00c1a08c283db788f..1dd8ccb013bc15ccf14caa4345b90a2d6b429885 100644 (file)
@@ -10,6 +10,7 @@ extern "C" {
 void test__kt_remove__print_version__works(void **state) {
 
   mock_unwrap = 0;
+  mock_unwrap_f_time_clock_get = 1;
 
   {
     const f_string_t argv[] = { "mocked_main", "++" F_console_standard_long_version_s, 0 };
index ce0b4859f25f2d1830cc85d11fe69779600115e0..013d9f499482d6ae51174265a24e7d6d53582957 100644 (file)
@@ -10,6 +10,7 @@ extern "C" {
 void test__kt_remove__regular_no_args__one_exists_link(void **state) {
 
   mock_unwrap = 0;
+  mock_unwrap_f_time_clock_get = 1;
 
   struct stat statistics;
 
@@ -77,6 +78,7 @@ void test__kt_remove__regular_no_args__one_exists_link(void **state) {
 void test__kt_remove__regular_no_args__one_exists_link_not(void **state) {
 
   mock_unwrap = 0;
+  mock_unwrap_f_time_clock_get = 1;
 
   struct stat statistics;
 
@@ -144,6 +146,7 @@ void test__kt_remove__regular_no_args__one_exists_link_not(void **state) {
 void test__kt_remove__regular_no_args__one_exists_not(void **state) {
 
   mock_unwrap = 0;
+  mock_unwrap_f_time_clock_get = 1;
 
   {
     const f_string_t argv[] = { "mocked_main", "to_remove", 0 };
@@ -179,6 +182,7 @@ void test__kt_remove__regular_no_args__one_exists_not(void **state) {
 void test__kt_remove__regular_no_args__two_exists_and_not(void **state) {
 
   mock_unwrap = 0;
+  mock_unwrap_f_time_clock_get = 1;
 
   struct stat statistics;
 
@@ -255,6 +259,7 @@ void test__kt_remove__regular_no_args__two_exists_and_not(void **state) {
 void test__kt_remove__regular_no_args__two_exists_link(void **state) {
 
   mock_unwrap = 0;
+  mock_unwrap_f_time_clock_get = 1;
 
   struct stat statistics;
 
@@ -349,6 +354,7 @@ void test__kt_remove__regular_no_args__two_exists_link(void **state) {
 void test__kt_remove__regular_no_args__two_exists_link_not(void **state) {
 
   mock_unwrap = 0;
+  mock_unwrap_f_time_clock_get = 1;
 
   struct stat statistics;
 
@@ -443,6 +449,7 @@ void test__kt_remove__regular_no_args__two_exists_link_not(void **state) {
 void test__kt_remove__regular_no_args__two_exists_not(void **state) {
 
   mock_unwrap = 0;
+  mock_unwrap_f_time_clock_get = 1;
 
   {
     const f_string_t argv[] = { "mocked_main", "to_remove", "also/remove", 0 };
index 6809448d8b90ae3c4b086b69bd6b8995f2f4c207..96ce65bf74acdd60eb905b7cefc7a0aac11070db 100644 (file)
@@ -10,6 +10,7 @@ extern "C" {
 void test__kt_remove__user__different_works(void **state) {
 
   mock_unwrap = 0;
+  mock_unwrap_f_time_clock_get = 1;
 
   const f_string_static_t target = macro_f_string_static_t_initialize_1("to_remove", 0, 9);
   const f_string_t argv[] = { "mocked_main", target.string, "-" KT_REMOVE_short_different_s, 0 };
@@ -71,6 +72,7 @@ void test__kt_remove__user__different_works(void **state) {
 void test__kt_remove__user__name_works(void **state) {
 
   mock_unwrap = 0;
+  mock_unwrap_f_time_clock_get = 1;
 
   const f_string_static_t target = macro_f_string_static_t_initialize_1("to_remove", 0, 9);
   const f_string_t argv[] = { "mocked_main", target.string, "-" KT_REMOVE_short_user_s, "some_name", 0 };
@@ -132,6 +134,7 @@ void test__kt_remove__user__name_works(void **state) {
 void test__kt_remove__user__same_works(void **state) {
 
   mock_unwrap = 0;
+  mock_unwrap_f_time_clock_get = 1;
 
   const f_string_static_t target = macro_f_string_static_t_initialize_1("to_remove", 0, 9);
   const f_string_t argv[] = { "mocked_main", target.string, "-" KT_REMOVE_short_same_s, 0 };
index 0ecf8b44a41c3d56595f72fa25aff52c2b5906fc..d35e7e0d481c7eec98abe7ac0693fd235c34437d 100644 (file)
@@ -22,6 +22,9 @@ int main(void) {
     cmocka_unit_test(test__kt_remove__print_help__works),
     cmocka_unit_test(test__kt_remove__print_version__works),
 
+    cmocka_unit_test(test__kt_remove__date_changed__now_works),
+    cmocka_unit_test(test__kt_remove__date_changed__tomorrow_works),
+
     cmocka_unit_test(test__kt_remove__directory_no_args__one_empty_exists_link),
     cmocka_unit_test(test__kt_remove__directory_no_args__one_empty_exists_link_not),
     cmocka_unit_test(test__kt_remove__directory_no_args__one_empty_exists_not),
index f35fb4ffe0bbd58d87a593a047de0815854cdfd7..f882a81f5ed7632c8632c9c7a214d5eb45e96f4d 100644 (file)
@@ -30,6 +30,7 @@
 #include "main-test-remove.h"
 
 // Test includes.
+#include "test-remove-date_changed.h"
 #include "test-remove-directory_no_args.h"
 #include "test-remove-directory_recurse_simple.h"
 #include "test-remove-directory_tree_simple.h"