mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 00:41:02 +00:00
add checks for rewriting a file
This commit is contained in:
parent
15749a312d
commit
689932aa10
1 changed files with 20 additions and 20 deletions
|
@ -9,17 +9,11 @@
|
|||
#import <Foundation/NSThread.h>
|
||||
#import <Foundation/NSURL.h>
|
||||
|
||||
@implementation NSDate (Testing)
|
||||
- (BOOL) isEqualForTestcase: (id)otherObject
|
||||
{
|
||||
if (NO == [otherObject isKindOfClass: [NSDate class]])
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
return EQ([self timeIntervalSinceReferenceDate],
|
||||
[(NSDate*)otherObject timeIntervalSinceReferenceDate]) ? YES: NO;
|
||||
}
|
||||
@end
|
||||
#ifdef EQ
|
||||
#undef EQ
|
||||
#endif
|
||||
#define EPSILON (FLT_EPSILON*100)
|
||||
#define EQ(x,y) ((x >= y - EPSILON) && (x <= y + EPSILON))
|
||||
|
||||
@interface MyHandler : NSObject
|
||||
{
|
||||
|
@ -167,10 +161,13 @@ int main()
|
|||
}
|
||||
NSDictionary *oa = [mgr fileAttributesAtPath: @"NSFMFile" traverseLink: NO];
|
||||
NSDictionary *na = [mgr fileAttributesAtPath: @"NSFMCopy" traverseLink: NO];
|
||||
PASS_EQUAL([oa fileCreationDate], [na fileCreationDate],
|
||||
"copy creation date equals original")
|
||||
PASS_EQUAL([oa fileModificationDate], [na fileModificationDate],
|
||||
"copy modification date equals original")
|
||||
NSTimeInterval ot, nt;
|
||||
ot = [[oa fileCreationDate] timeIntervalSinceReferenceDate];
|
||||
nt = [[na fileCreationDate] timeIntervalSinceReferenceDate];
|
||||
PASS(EQ(ot, nt), "copy creation date equals original")
|
||||
ot = [[oa fileModificationDate] timeIntervalSinceReferenceDate];
|
||||
nt = [[na fileModificationDate] timeIntervalSinceReferenceDate];
|
||||
PASS(EQ(ot, nt), "copy modification date equals original")
|
||||
{
|
||||
NSData *dat1 = [mgr contentsAtPath: @"NSFMFile"];
|
||||
NSError *err;
|
||||
|
@ -181,11 +178,14 @@ int main()
|
|||
error: &err];
|
||||
PASS(ok, "can rewrite data file")
|
||||
if (NO == ok) NSLog(@"Problem: %@ with %@", err, dat1);
|
||||
na = [mgr fileAttributesAtPath: @"NSFMMove" traverseLink: NO];
|
||||
PASS(![[oa fileCreationDate] isEqualForTestcase: [na fileCreationDate]],
|
||||
"rewritten file creation date changed")
|
||||
PASS(![[oa fileModificationDate] isEqualForTestcase:
|
||||
[na fileModificationDate]], "rewritten file modification date changed")
|
||||
na = [mgr fileAttributesAtPath: @"NSFMFile" traverseLink: NO];
|
||||
NSLog(@"%@\n%@", oa, na);
|
||||
ot = [[oa fileCreationDate] timeIntervalSinceReferenceDate];
|
||||
nt = [[na fileCreationDate] timeIntervalSinceReferenceDate];
|
||||
PASS(!EQ(ot, nt), "rewritten file creation date changed")
|
||||
ot = [[oa fileModificationDate] timeIntervalSinceReferenceDate];
|
||||
nt = [[na fileModificationDate] timeIntervalSinceReferenceDate];
|
||||
PASS(!EQ(ot, nt), "rewritten file modification date changed")
|
||||
}
|
||||
|
||||
PASS([mgr movePath: @"NSFMFile"
|
||||
|
|
Loading…
Reference in a new issue