From: Kevin Day Date: Mon, 24 Mar 2025 02:16:41 +0000 (-0500) Subject: Progress: Continue working on completing the remove program. X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=47588215159a2ba3a20d1504f30b192ebd568eb6;p=kevux-tools Progress: Continue working on completing the remove program. This adds the yesterday and today program unit tests. Focus on getting the unit tests working and correcting the logic. There is a lot of logic surrounding the relative dates and times that makes this ripe for an error. I will need to add more program unit tests over time to better catch logic mistakes. --- diff --git a/sources/c/program/kevux/tools/remove/main/common/define.h b/sources/c/program/kevux/tools/remove/main/common/define.h index 880ba41..3f0af2e 100644 --- a/sources/c/program/kevux/tools/remove/main/common/define.h +++ b/sources/c/program/kevux/tools/remove/main/common/define.h @@ -107,15 +107,16 @@ extern "C" { * - more_equal: Perform greater than or equal to on date, '>=' or 'more_equal'. * - not: Perform not equal to on date. '<>' or 'not' * - * - year: Date has a year. - * - now: Date is relative to 'now'. - * - string: Date is processed via the string date functions (such as via strftime_r() or getdate_r()). - * - time: Date is based off of Time format. - * - time_epoch: Date is based off of EpochTime format. - * - today: Date is relative to 'today'. - * - tomorrow: Date is relative to 'tomorrow'. - * - unix: Date is based off of Unix Epoch format. - * - yesterday: Date is relative to 'yesterday'. + * - year: Date has a year. + * - now: Date is relative to 'now'. + * - string: Date is processed via the string date functions (such as via strftime_r() or getdate_r()). + * - time: Date is based off of Time format. + * - time_epoch: Date is based off of EpochTime format. + * - today: Date is relative to 'today'. + * - today_tomorrow_yesterday: Helper designating today, tomorrow, or yesterday flag is set. + * - tomorrow: Date is relative to 'tomorrow'. + * - unix: Date is based off of Unix Epoch format. + * - yesterday: Date is relative to 'yesterday'. */ #ifndef _di_kt_remove_flag_date_d_ #define kt_remove_flag_date_none_d 0x0 @@ -129,14 +130,15 @@ extern "C" { #define kt_remove_flag_date_not_d 0x20 // Used for processing and converting. - #define kt_remove_flag_date_now_d 0x1 - #define kt_remove_flag_date_string_d 0x2 - #define kt_remove_flag_date_time_d 0x4 - #define kt_remove_flag_date_time_epoch_d 0x8 - #define kt_remove_flag_date_today_d 0x10 - #define kt_remove_flag_date_tomorrow_d 0x20 - #define kt_remove_flag_date_unix_d 0x40 - #define kt_remove_flag_date_yesterday_d 0x80 + #define kt_remove_flag_date_now_d 0x1 + #define kt_remove_flag_date_string_d 0x2 + #define kt_remove_flag_date_time_d 0x4 + #define kt_remove_flag_date_time_epoch_d 0x8 + #define kt_remove_flag_date_today_d 0x10 + #define kt_remove_flag_date_today_tomorrow_yesterday_d 0xb0 + #define kt_remove_flag_date_tomorrow_d 0x20 + #define kt_remove_flag_date_unix_d 0x40 + #define kt_remove_flag_date_yesterday_d 0x80 #endif // _di_kt_remove_flag_date_d_ /** diff --git a/sources/c/program/kevux/tools/remove/main/convert.c b/sources/c/program/kevux/tools/remove/main/convert.c index b8856d8..8329628 100644 --- a/sources/c/program/kevux/tools/remove/main/convert.c +++ b/sources/c/program/kevux/tools/remove/main/convert.c @@ -13,6 +13,8 @@ extern "C" { return; } + date->type = kt_remove_flag_date_none_d; + { const f_string_static_t strings[] = { kt_remove_now_s, @@ -44,6 +46,12 @@ extern "C" { } // for } + if (date->type) { + main->setting.state.status = F_okay; + + return; + } + uint8_t matches = 0; f_range_t range_first = f_range_t_initialize; f_range_t range_second = f_range_t_initialize; @@ -192,9 +200,9 @@ extern "C" { if (matches & kt_remove_flag_convert_match_d) { fl_conversion_data_t conversion_data = fl_conversion_data_base_10_c; - date->start_nanosecond = date->stop_nanosecond = 0; - date->start_second = date->stop_second = 0; - date->start_year = date->stop_year = 0; + date->start_nanosecond = 0; + date->start_second = 0; + date->start_year = 0; date->type = 0; // Process the first character. @@ -322,8 +330,8 @@ extern "C" { memset(&time, 0, sizeof(struct tm)); if (strptime(buffer.string, formats[i], &time) != 0) { - date->start_nanosecond = date->stop_nanosecond = 0; - date->start_year = date->stop_year = kt_remove_time_year_unix_epoch_d; + date->start_nanosecond = 0; + date->start_year = kt_remove_time_year_unix_epoch_d; date->type = kt_remove_flag_date_string_d; #ifdef _available_timegm_ @@ -335,7 +343,6 @@ extern "C" { date->start_second += time.tm_yday * kt_remove_time_seconds_in_day_d; #endif // _available_timegm_ - date->stop_second = date->start_second; matches = 1; break; diff --git a/sources/c/program/kevux/tools/remove/main/preprocess.c b/sources/c/program/kevux/tools/remove/main/preprocess.c index 35ec594..7f2dc5d 100644 --- a/sources/c/program/kevux/tools/remove/main/preprocess.c +++ b/sources/c/program/kevux/tools/remove/main/preprocess.c @@ -484,13 +484,15 @@ extern "C" { uint8_t result = F_false; f_string_static_t name_type = f_string_empty_s; + f_number_unsigned_t match_nanosecond = 0; f_number_unsigned_t match_second = 0; f_number_unsigned_t match_year = 0; + f_number_unsigned_t start_nanosecond = 0; f_number_unsigned_t start_second = 0; f_number_unsigned_t start_year = 0; + f_number_unsigned_t stop_nanosecond = 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) { @@ -500,30 +502,43 @@ extern "C" { if (kt_remove_signal_check(main)) return; - match_year = kt_remove_time_year_unix_epoch_d + (times[i].tv_sec / kt_remove_time_seconds_in_year_d); + match_nanosecond = times[i].tv_nsec; match_second = times[i].tv_sec % kt_remove_time_seconds_in_year_d; + match_year = kt_remove_time_year_unix_epoch_d + (times[i].tv_sec / kt_remove_time_seconds_in_year_d); - 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; - - 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; + start_nanosecond = dates[i]->array[j].start_nanosecond; + start_second = dates[i]->array[j].start_second; + start_year = dates[i]->array[j].start_year; - 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; + stop_nanosecond = dates[i]->array[j].stop_nanosecond; + stop_second = dates[i]->array[j].stop_second; + stop_year = dates[i]->array[j].stop_year; name_type = f_string_empty_s; result = F_false; - 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) { + // The today, tomorrow, and yesterday ranges are based on a whole day rather than down to an exact nanosecond (which are always 0 for full day ranges). + if (dates[i]->array[j].type & kt_remove_flag_date_today_tomorrow_yesterday_d) { + + // Ensure the ranges are a whole day. + start_second = dates[i]->array[j].start_second % kt_remove_time_seconds_in_year_d; + start_year = dates[i]->array[j].start_year + (dates[i]->array[j].start_second / kt_remove_time_seconds_in_year_d); + + stop_second = start_second + kt_remove_time_seconds_in_day_d; + if (dates[i]->array[j].operation == kt_remove_flag_date_equal_d) { name_type = kt_remove_date_symbol_equal_s; result = F_false; if (match_year == start_year) { - if (match_second > start_second && match_second < stop_second) { + 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 && (start_is_stop || times[i].tv_nsec < dates[i]->array[j].stop_nanosecond)) { + } + + // When stop_year is greater than start_year, then the stop_year represents the first day of the year. + else if (stop_year > start_year && match_year == stop_year) { + if (match_second >= 0 && match_second < kt_remove_time_seconds_in_day_d) { result = F_true; } } @@ -539,9 +554,6 @@ extern "C" { if (match_second < start_second) { result = F_true; } - else if (match_second == start_second && times[i].tv_nsec < dates[i]->array[j].start_nanosecond) { - result = F_true; - } } } else if (dates[i]->array[j].operation == kt_remove_flag_date_less_equal_d) { @@ -555,7 +567,11 @@ extern "C" { if (match_second < stop_second) { result = F_true; } - 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)) { + } + + // When stop_year is greater than start_year, then the stop_year represents the first day of the year. + else if (stop_year > start_year && match_year == stop_year) { + if (match_second >= 0 && match_second < kt_remove_time_seconds_in_day_d) { result = F_true; } } @@ -564,32 +580,36 @@ extern "C" { name_type = kt_remove_date_symbol_more_s; result = F_false; - if (match_year > stop_year) { - result = F_true; - } - else if (match_year == stop_year) { - if (match_second > stop_second) { + // Note that stop times are exclusive rather than inclusive. + // When stop_year is greater than start_year, then the stop_year represents the first day of the year. + if (stop_year > start_year) { + if (match_year >= stop_year) { result = F_true; } - else if (match_second == stop_second && times[i].tv_nsec > dates[i]->array[j].stop_nanosecond) { + } + else { + if (match_year > start_year) { result = F_true; } + else if (match_year == start_year) { + if (match_second >= stop_second) { + result = F_true; + } + } } } else if (dates[i]->array[j].operation == kt_remove_flag_date_more_equal_d) { name_type = kt_remove_date_symbol_more_equal_s; result = F_false; - if (match_year > start_year) { + // Note that stop times are exclusive rather than inclusive. + if (match_year == start_year && match_second >= start_second) { result = F_true; } - else if (match_year == start_year) { - if (match_second > start_second) { - result = F_true; - } - else if (match_second == start_second && times[i].tv_nsec >= dates[i]->array[j].start_nanosecond) { - result = F_true; - } + + // When stop_year is greater than start_year, then the stop_year represents the first day of the year. + else if (stop_year > start_year && match_year >= stop_year) { + result = F_true; } } else if (dates[i]->array[j].operation == kt_remove_flag_date_not_d) { @@ -597,10 +617,7 @@ extern "C" { result = F_true; if (match_year == start_year) { - if (match_second > start_second && match_second < stop_second) { - result = F_false; - } - 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) { + if (match_second >= start_second && match_second < stop_second) { result = F_false; } } @@ -608,7 +625,7 @@ extern "C" { } else if (dates[i]->array[j].operation == kt_remove_flag_date_equal_d) { name_type = kt_remove_date_symbol_equal_s; - result = match_year == start_year && match_second == start_second && times[i].tv_nsec == dates[i]->array[j].start_nanosecond; + result = match_year == start_year && match_second == start_second && match_nanosecond == start_nanosecond; } else if (dates[i]->array[j].operation == kt_remove_flag_date_less_d) { name_type = kt_remove_date_symbol_less_s; @@ -621,7 +638,7 @@ extern "C" { if (match_second < start_second) { result = F_true; } - else if (match_second == start_second && times[i].tv_nsec < dates[i]->array[j].start_nanosecond) { + else if (match_second == start_second && match_nanosecond < start_nanosecond) { result = F_true; } } @@ -637,7 +654,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 && match_nanosecond <= stop_nanosecond) { result = F_true; } } @@ -653,7 +670,7 @@ extern "C" { if (match_second > start_second) { result = F_true; } - else if (match_second == start_second && times[i].tv_nsec > dates[i]->array[j].start_nanosecond) { + else if (match_second == start_second && match_nanosecond > start_nanosecond) { result = F_true; } } @@ -669,14 +686,14 @@ extern "C" { if (match_second > start_second) { result = F_true; } - else if (match_second == start_second && times[i].tv_nsec >= dates[i]->array[j].start_nanosecond) { + else if (match_second == start_second && match_nanosecond >= start_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; - result = match_year != start_year || match_second != start_second || times[i].tv_nsec != dates[i]->array[j].start_nanosecond; + result = match_year != start_year || match_second != start_second || match_nanosecond != start_nanosecond; } if (name_type.used) { diff --git a/tests/unit/remove/c/test-remove-date_changed.c b/tests/unit/remove/c/test-remove-date_changed.c index 0a60aba..b817b7f 100644 --- a/tests/unit/remove/c/test-remove-date_changed.c +++ b/tests/unit/remove/c/test-remove-date_changed.c @@ -86,7 +86,7 @@ void test__kt_remove__date_changed__now_works(void **state) { 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); + const f_time_spec_t time_spec_clocks = macro_f_time_spec_t_initialize_1(2 * 86400, 123); bool time_spec_removes[] = { F_true, // Equal @@ -161,6 +161,160 @@ void test__kt_remove__date_changed__now_works(void **state) { } } +void test__kt_remove__date_changed__today_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("today", 0, 5); + + 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, 123); + + bool time_spec_removes[] = { + F_true, // Equal + F_true, + F_false, + F_false, + F_false, // Less + F_false, + 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_true, + F_true, + F_false, + F_false, // Not + F_false, + 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; @@ -240,7 +394,7 @@ void test__kt_remove__date_changed__tomorrow_works(void **state) { 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); + const f_time_spec_t time_spec_clocks = macro_f_time_spec_t_initialize_1(2 * 86400, 123); bool time_spec_removes[] = { F_false, // Equal @@ -253,7 +407,7 @@ void test__kt_remove__date_changed__tomorrow_works(void **state) { F_true, F_true, // Less Equal F_true, - F_false, + F_true, F_true, F_false, // More F_false, @@ -273,6 +427,160 @@ void test__kt_remove__date_changed__tomorrow_works(void **state) { uint8_t type = 0; uint8_t date = 0; + for (; type < 1/*types_total*/; ++type) { + + for (date = 10; date < 11/*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__yesterday_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("yesterday", 0, 9); + + 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_false, + F_true, + F_false, // Less + F_false, + F_false, + F_false, + F_false, // Less Equal + F_false, + F_false, + F_true, + F_true, // More + F_true, + F_true, + F_false, + F_true, // More Equal + F_true, + F_true, + F_true, + F_true, // Not + F_true, + F_true, + F_false, + }; + + { + uint8_t type = 0; + uint8_t date = 0; + for (; type < types_total; ++type) { for (date = 0; date < dates_total; ++date) { @@ -315,9 +623,6 @@ void test__kt_remove__date_changed__tomorrow_works(void **state) { } } -//@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 index c0621cd..44f86d8 100644 --- a/tests/unit/remove/c/test-remove-date_changed.h +++ b/tests/unit/remove/c/test-remove-date_changed.h @@ -16,8 +16,18 @@ extern void test__kt_remove__date_changed__now_works(void **state); /** + * Test that the remove works when the --changed parameter with "today" parameter are passed. + */ +extern void test__kt_remove__date_changed__today_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); +/** + * Test that the remove works when the --changed parameter with "yesterday" parameter are passed. + */ +extern void test__kt_remove__date_changed__yesterday_works(void **state); + #endif // _TEST__KT_remove__date_changed diff --git a/tests/unit/remove/c/test-remove.c b/tests/unit/remove/c/test-remove.c index d35e7e0..3a1ecf5 100644 --- a/tests/unit/remove/c/test-remove.c +++ b/tests/unit/remove/c/test-remove.c @@ -23,7 +23,9 @@ int main(void) { 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__today_works), cmocka_unit_test(test__kt_remove__date_changed__tomorrow_works), + cmocka_unit_test(test__kt_remove__date_changed__yesterday_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),