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.
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
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
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
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;
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;
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);
}
}
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);
}
}
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;
* - 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.
* 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);
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);
}
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,
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;
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) {
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;
}
}
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;
}
}
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;
}
}
}
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;
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;
}
}
}
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) {
#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;
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;
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);
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);
--- /dev/null
+#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
--- /dev/null
+/**
+ * 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
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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 };
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 };
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 };
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;
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;
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 };
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;
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;
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;
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 };
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 };
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 };
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 };
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),
#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"