-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFBCachedFileTestCase.m
More file actions
130 lines (100 loc) · 3.12 KB
/
Copy pathFBCachedFileTestCase.m
File metadata and controls
130 lines (100 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//
// FBCachedFileTestCase.m
// FBFileCache
//
// Created by Hiroshi Hashiguchi on 11/03/02.
// Copyright 2011 Five-technology Co.,Ltd.. All rights reserved.
//
#import "FBCachedFileTestCase.h"
#import "FBCachedFile.h"
#include <sys/stat.h>
@implementation FBCachedFileTestCase
#pragma mark -
#pragma mark Pre-Post functions
- (void)setUp
{
[super setUp];
// Set-up code here.
}
- (void)tearDown
{
// Tear-down code here.
[super tearDown];
}
#pragma mark -
#pragma mark Utilities
- (NSString*)samplePath
{
NSString* path = [[NSBundle bundleForClass:[self class]] pathForResource:@"sample" ofType:@"jpg"];
return path;
}
- (NSURL*)sampleURL
{
NSURL* url = [NSURL fileURLWithPath:[self samplePath]];
return url;
}
- (FBCachedFile*)sampleCachedFile
{
FBCachedFile* cachedFile = [FBCachedFile cachedFile:[self samplePath]];
return cachedFile;
}
- (NSDictionary*)attributesOfSample
{
NSFileManager* fileManager = [NSFileManager defaultManager];
NSError* error = nil;
return [fileManager attributesOfItemAtPath:[self samplePath] error:&error];
}
#pragma mark -
#pragma mark Test cases
- (void)testProperty_Path
{
FBCachedFile* cachedFile = [self sampleCachedFile];
STAssertEqualObjects(cachedFile.path, [self samplePath], nil);
}
- (void)testProperty_URL
{
FBCachedFile* cachedFile = [self sampleCachedFile];
STAssertEqualObjects(cachedFile.URL, [self sampleURL], nil);
}
- (void)testProperty_CreationDate
{
FBCachedFile* cachedFile = [self sampleCachedFile];
NSDictionary* attributes = [self attributesOfSample];
NSDate* creationDate = [attributes objectForKey:NSFileCreationDate];
STAssertEqualObjects(cachedFile.creationDate, creationDate, nil);
}
- (void)testProperty_lastModifiedDate
{
FBCachedFile* cachedFile = [self sampleCachedFile];
NSLog(@"%@ | %@", cachedFile.creationDate, cachedFile.lastModifiedDate);
NSDate* date = [NSDate date];
cachedFile.lastModifiedDate = date;
STAssertEquals((long)[cachedFile.lastModifiedDate timeIntervalSince1970],
(long)[date timeIntervalSince1970], nil);
}
- (void)testProperty_TimeIntervalSinceNow {
FBCachedFile* cachedFile = [self sampleCachedFile];
NSDictionary* attributes = [self attributesOfSample];
NSDate* creationDate = [attributes objectForKey:NSFileCreationDate];
STAssertEquals((NSInteger)cachedFile.timeIntervalSinceNow,
(NSInteger)[creationDate timeIntervalSinceNow],nil);
}
- (void)testPropery_Data
{
FBCachedFile* cachedFile = [self sampleCachedFile];
NSData* data = [NSData dataWithContentsOfFile:cachedFile.path];
STAssertEqualObjects(cachedFile.data, data, nil);
}
- (void)testUpdateAccessTime
{
FBCachedFile* cachedFile = [self sampleCachedFile];
struct stat buf;
stat([cachedFile.path UTF8String], &buf);
__darwin_time_t atime1 = buf.st_atimespec.tv_sec;
[NSThread sleepForTimeInterval:1.0];
[cachedFile updateAccessTime]; // delay for atime
stat([cachedFile.path UTF8String], &buf);
__darwin_time_t atime2 = buf.st_atimespec.tv_sec;
STAssertTrue(atime1 < atime2, nil);
}
@end