Changeset 14658


Ignore:
Timestamp:
Jan 4, 2016, 5:04:55 AM (6 years ago)
Author:
mikedld
Message:

Improve file test modification time checks

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/file-test.c

    r14586 r14658  
    9494clear_path_info (tr_sys_path_info * info)
    9595{
    96   info->type = (tr_sys_path_type_t)-1;
    97   info->size = (uint64_t)-1;
    98   info->last_modified_at = (time_t)-1;
     96  info->type = (tr_sys_path_type_t) -1;
     97  info->size = (uint64_t) -1;
     98  info->last_modified_at = (time_t) -1;
    9999}
    100100
     
    166166  tr_error * err = NULL;
    167167  char * path1, * path2;
     168  time_t t;
    168169
    169170  path1 = tr_buildPath (test_dir, "a", NULL);
     
    175176  tr_error_clear (&err);
    176177
     178  t = time (NULL);
    177179  libtest_create_file_with_string_contents (path1, "test");
    178180
     
    183185  check_int_eq (TR_SYS_PATH_IS_FILE, info.type);
    184186  check_int_eq (4, info.size);
    185   check (info.last_modified_at >= time(0) - 1 && info.last_modified_at <= time(0));
     187  check (info.last_modified_at >= t && info.last_modified_at <= time (NULL));
    186188
    187189  /* Good file info (by handle) */
     
    192194  check_int_eq (TR_SYS_PATH_IS_FILE, info.type);
    193195  check_int_eq (4, info.size);
    194   check (info.last_modified_at >= time(0) - 1 && info.last_modified_at <= time(0));
     196  check (info.last_modified_at >= t && info.last_modified_at <= time (NULL));
    195197  tr_sys_file_close (fd, NULL);
    196198
     
    198200
    199201  /* Good directory info */
     202  t = time (NULL);
    200203  tr_sys_dir_create (path1, 0, 0777, NULL);
    201204  clear_path_info (&info);
     
    203206  check (err == NULL);
    204207  check_int_eq (TR_SYS_PATH_IS_DIRECTORY, info.type);
    205   check (info.size != (uint64_t)-1);
    206   check (info.last_modified_at >= time(0) - 1 && info.last_modified_at <= time(0));
     208  check (info.size != (uint64_t) -1);
     209  check (info.last_modified_at >= t && info.last_modified_at <= time (NULL));
    207210  tr_sys_path_remove (path1, NULL);
    208211
     
    214217      tr_error_clear (&err);
    215218
     219      t = time (NULL);
    216220      libtest_create_file_with_string_contents (path2, "test");
    217221
     
    222226      check_int_eq (TR_SYS_PATH_IS_FILE, info.type);
    223227      check_int_eq (4, info.size);
    224       check (info.last_modified_at >= time(0) - 1 && info.last_modified_at <= time(0));
     228      check (info.last_modified_at >= t && info.last_modified_at <= time (NULL));
    225229
    226230      /* Good file info (by handle) */
     
    231235      check_int_eq (TR_SYS_PATH_IS_FILE, info.type);
    232236      check_int_eq (4, info.size);
    233       check (info.last_modified_at >= time(0) - 1 && info.last_modified_at <= time(0));
     237      check (info.last_modified_at >= t && info.last_modified_at <= time (NULL));
    234238      tr_sys_file_close (fd, NULL);
    235239
     
    237241
    238242      /* Good directory info */
     243      t = time (NULL);
    239244      tr_sys_dir_create (path2, 0, 0777, NULL);
    240245      clear_path_info (&info);
     
    242247      check (err == NULL);
    243248      check_int_eq (TR_SYS_PATH_IS_DIRECTORY, info.type);
    244       check (info.size != (uint64_t)-1);
    245       check (info.last_modified_at >= time(0) - 1 && info.last_modified_at <= time(0));
     249      check (info.size != (uint64_t) -1);
     250      check (info.last_modified_at >= t && info.last_modified_at <= time (NULL));
    246251
    247252      tr_sys_path_remove (path2, NULL);
Note: See TracChangeset for help on using the changeset viewer.