]>
git.saurik.com Git - apple/hfs.git/blob - tests/cases/test-dateadded.c
1e58d1af07a742dfd499e8b02b9de3ea60a65cc6
5 // Created by csuter on 8/28/15.
14 #include "hfs-tests.h"
15 #include "test-utils.h"
16 #include "../core/hfs_fsctl.h"
17 #include "disk-image.h"
21 #define TIME_TO_SET 1440807730
23 int run_dateadded(__unused test_ctx_t
*ctx
)
25 disk_image_t
*di
= disk_image_get();
26 char *file
, *file2
, *file3
, *dir
;
28 asprintf(&file
, "%s/test-dateadded.file", di
->mount_point
);
29 asprintf(&file2
, "%s/test-dateadded.file2", di
->mount_point
);
30 asprintf(&dir
, "%s/test-dateadded.dir", di
->mount_point
);
31 asprintf(&file3
, "%s/file3", dir
);
33 int fd
= open(file
, O_RDWR
| O_CREAT
, 0666);
34 assert_with_errno(fd
>= 0);
36 struct attrlist al
= {
37 .bitmapcount
= ATTR_BIT_MAP_COUNT
,
38 .commonattr
= ATTR_CMN_ADDEDTIME
44 struct timespec added_time
;
48 assert_no_err(fgetattrlist(fd
, &al
, &attrs
, sizeof(attrs
), 0));
50 struct timespec orig
= attrs
.added_time
;
52 // Make sure rename doesn’t change it
55 attrs
.added_time
.tv_sec
= 0;
56 assert_no_err(getattrlist(file2
, &al
, &attrs
, sizeof(attrs
), 0));
58 assert_equal(attrs
.added_time
.tv_sec
, orig
.tv_sec
, "%ld");
62 // Rename to a different directory should change it
66 assert_no_err(rename(file2
, file3
));
68 attrs
.added_time
.tv_sec
= 0;
69 assert_no_err(getattrlist(file3
, &al
, &attrs
, sizeof(attrs
), 0));
71 assert(attrs
.added_time
.tv_sec
>= orig
.tv_sec
72 && attrs
.added_time
.tv_sec
< orig
.tv_sec
+ 10);
74 #if 0 // Not supported until VFS work is done
75 attrs
.added_time
.tv_sec
= TIME_TO_SET
;
77 assert_no_err(fsetattrlist(fd
, &al
, (void *)&attrs
+ 4,
78 sizeof(attrs
) - 4, 0));
80 attrs
.added_time
.tv_sec
= 0;
81 assert_no_err(fgetattrlist(fd
, &al
, &attrs
, sizeof(attrs
), 0));
83 assert_equal(attrs
.added_time
.tv_sec
, TIME_TO_SET
, "%ld");
86 assert_no_err(unlink(file3
));
87 assert_no_err(rmdir(dir
));