Merge pull request #65 from gnustep/NSProgress_fixes_branch

NSProgress fixes branch
This commit is contained in:
Gregory Casamento 2019-08-14 05:17:08 -04:00 committed by GitHub
commit 61b2cbe527
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 104 additions and 17 deletions

View file

@ -104,6 +104,7 @@
#import <Foundation/NSPortNameServer.h>
#import <Foundation/NSPredicate.h>
#import <Foundation/NSProcessInfo.h>
#import <Foundation/NSProgress.h>
#import <Foundation/NSProtocolChecker.h>
#import <Foundation/NSProxy.h>
#import <Foundation/NSRange.h>

View file

@ -90,17 +90,9 @@ NSAttributedString:
- enumerateAttribute:inRange:options:usingBlock:
-------------------------------------------------------------
NSBundle:
- bundleURL
- resourceURL
- executableURL
- URLForAuxiliaryExecutable:
- privateFrameworksURL
- sharedFrameworksURL
- sharedSupportURL
- builtInPlugInsURL
- appStoreReceiptURL
- pathForAuxiliaryExecutable:
- privateFrameworksPath
- sharedFrameworksPath
- sharedSupportPath
+ URLsForResourcesWithExtension:subdirectory:inBundleWithURL:

View file

@ -33,7 +33,7 @@
extern "C" {
#endif
@class NSString, NSDictionary, NSArray, NSNumber, NSProgress;
@class NSString, NSDictionary, NSArray, NSNumber, NSURL, NSProgress;
#if OS_API_VERSION(MAC_OS_X_VERSION_10_9, GS_API_LATEST)
@ -91,7 +91,7 @@ GS_NSProgress_IVARS;
- (void) setCompletedUnitCount: (int64_t)unitCount;
- (NSString *) localizedDescription;
- (NSString *) localizedAddtionalDescription;
- (NSString *) localizedAdditionalDescription;
// Observing progress
- (double) fractionCompleted;

View file

@ -47,6 +47,8 @@
NSProgressUnpublishingHandler _unpublishingHandler; \
GSProgressPendingUnitCountBlock _pendingUnitCountHandler; \
GSProgressResumingHandler _resumingHandler; \
NSString *_localizedDescription; \
NSString *_localizedAdditionalDescription; \
NSProgress *_parent;
#define EXPOSE_NSProgress_IVARS
@ -58,6 +60,7 @@
#import <Foundation/NSURL.h>
#import <Foundation/NSString.h>
#import <Foundation/NSProgress.h>
#import <Foundation/NSKeyValueObserving.h>
#define GSInternal NSProgressInternal
#include "GSInternal.h"
@ -96,15 +99,16 @@ static NSMutableDictionary *__subscribers = nil;
internal->_throughput = nil;
internal->_totalUnitCount = 0;
internal->_completedUnitCount = 0;
internal->_userInfo = [userInfo mutableCopy];
internal->_userInfo = RETAIN([userInfo mutableCopy]);
internal->_cancelled = NO;
internal->_cancellable = NO;
internal->_paused = NO;
internal->_pausable = NO;
internal->_indeterminate = NO;
internal->_finished = NO;
internal->_localizedDescription = nil;
internal->_localizedAdditionalDescription = nil;
internal->_parent = parent; // this is a weak reference and not retained.
internal->_userInfo = [[NSMutableDictionary alloc] initWithCapacity: 10];
}
return self;
}
@ -119,6 +123,8 @@ static NSMutableDictionary *__subscribers = nil;
RELEASE(internal->_fileTotalCount);
RELEASE(internal->_throughput);
RELEASE(internal->_userInfo);
RELEASE(internal->_localizedDescription);
RELEASE(internal->_localizedAdditionalDescription);
[super dealloc];
}
@ -209,14 +215,22 @@ static NSMutableDictionary *__subscribers = nil;
- (NSString *) localizedDescription
{
return [NSString stringWithFormat: @"%f percent complete",
[self fractionCompleted]];
return internal->_localizedDescription;
}
- (NSString *) localizedAddtionalDescription
- (void) setLocalizedDescription: (NSString *)localDescription
{
return [NSString stringWithFormat: @"%@ minute(s) remaining",
[self estimatedTimeRemaining]];
ASSIGNCOPY(internal->_localizedDescription, localDescription);
}
- (NSString *) localizedAdditionalDescription
{
return internal->_localizedAdditionalDescription;
}
- (void) setLocalizedAdditionalDescription: (NSString *)localDescription
{
ASSIGNCOPY(internal->_localizedAdditionalDescription, localDescription);
}
// Observing progress
@ -237,9 +251,17 @@ static NSMutableDictionary *__subscribers = nil;
return internal->_cancelled;
}
- (BOOL) cancelled
{
return internal->_cancelled;
}
- (void) cancel
{
[self willChangeValueForKey: @"cancelled"];
CALL_BLOCK_NO_ARGS(internal->_cancellationHandler);
internal->_cancelled = YES;
[self didChangeValueForKey: @"cancelled"];
}
- (void) setCancellationHandler: (GSProgressCancellationHandler) handler
@ -259,8 +281,10 @@ static NSMutableDictionary *__subscribers = nil;
- (void) pause
{
[self willChangeValueForKey: @"paused"];
CALL_BLOCK_NO_ARGS(internal->_pausingHandler);
internal->_paused = YES;
[self didChangeValueForKey: @"paused"];
}
- (void) setPausingHandler: (GSProgressPausingHandler) handler
@ -284,9 +308,16 @@ static NSMutableDictionary *__subscribers = nil;
return internal->_indeterminate;
}
- (BOOL) indeterminate
{
return internal->_indeterminate;
}
- (void) setIndeterminate: (BOOL)flag
{
[self willChangeValueForKey: @"indeterminate"];
internal->_indeterminate = flag;
[self didChangeValueForKey: @"indeterminate"];
}
- (NSProgressKind) kind
@ -296,7 +327,9 @@ static NSMutableDictionary *__subscribers = nil;
- (void) setKind: (NSProgressKind)k
{
[self willChangeValueForKey: @"kind"];
ASSIGN(internal->_kind, k);
[self didChangeValueForKey: @"kind"];
}
- (void)setUserInfoObject: (id)obj
@ -308,7 +341,9 @@ static NSMutableDictionary *__subscribers = nil;
// Instance property accessors...
- (void) setFileOperationKind: (NSProgressFileOperationKind)k;
{
[self willChangeValueForKey: @"fileOperationKind"];
ASSIGN(internal->_fileOperationKind, k);
[self didChangeValueForKey: @"fileOperationKind"];
}
- (NSProgressFileOperationKind) fileOperationKind
@ -318,7 +353,9 @@ static NSMutableDictionary *__subscribers = nil;
- (void) setFileUrl: (NSURL *)u
{
[self willChangeValueForKey: @"fileUrl"];
ASSIGN(internal->_fileUrl, u);
[self didChangeValueForKey: @"fileUrl"];
}
- (NSURL*) fileUrl
@ -331,14 +368,26 @@ static NSMutableDictionary *__subscribers = nil;
return internal->_finished;
}
- (BOOL) finished
{
return internal->_finished;
}
- (BOOL) isOld
{
return internal->_old;
}
- (BOOL) old
{
return internal->_old;
}
- (void) setEstimatedTimeRemaining: (NSNumber *)n
{
[self willChangeValueForKey: @"estimatedTimeRemaining"];
ASSIGNCOPY(internal->_estimatedTimeRemaining, n);
[self didChangeValueForKey: @"estimatedTimeRemaining"];
}
- (NSNumber *) estimatedTimeRemaining
@ -358,7 +407,9 @@ static NSMutableDictionary *__subscribers = nil;
- (void) setFileTotalCount: (NSNumber *)n
{
[self willChangeValueForKey: @"fileTotalCount"];
ASSIGNCOPY(internal->_fileTotalCount, n);
[self didChangeValueForKey: @"fileTotalCount"];
}
- (NSNumber *) fileTotalCount
@ -368,7 +419,9 @@ static NSMutableDictionary *__subscribers = nil;
- (void) setThroughput: (NSNumber *)n
{
[self willChangeValueForKey: @"throughput"];
ASSIGNCOPY(internal->_throughput, n);
[self didChangeValueForKey: @"throughput"];
}
- (NSNumber *) throughtput

View file

View file

@ -0,0 +1,41 @@
#import <Foundation/NSProgress.h>
#import <Foundation/NSThread.h>
#import <Foundation/NSAutoreleasePool.h>
#import "ObjectTesting.h"
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSDictionary *dict = [NSDictionary dictionary];
NSProgress *progress = [[NSProgress alloc] initWithParent: nil
userInfo: dict];
PASS(progress != nil, "[NSProgress initWithParent:userInfo:] returns instance");
progress = [NSProgress discreteProgressWithTotalUnitCount:100];
PASS(progress != nil, "[NSProgress discreteProgressWithTotalUnitCount:] returns instance");
progress = [NSProgress progressWithTotalUnitCount:100];
PASS(progress != nil, "[NSProgress progressWithTotalUnitCount:] returns instance");
progress = [NSProgress progressWithTotalUnitCount:100
parent:progress
pendingUnitCount:50];
PASS(progress != nil, "[NSProgress progressWithTotalUnitCount:] returns instance");
[progress becomeCurrentWithPendingUnitCount:50];
NSProgress *currentProgress = [NSProgress currentProgress];
PASS(currentProgress == progress, "Correct progress object associated with current thread");
NSProgress *new_progress = [NSProgress progressWithTotalUnitCount:100
parent:progress
pendingUnitCount:50];
[new_progress addChild:[[NSProgress alloc] initWithParent: nil userInfo: nil]
withPendingUnitCount:50];
[currentProgress resignCurrent];
PASS([NSProgress currentProgress] == nil, "Current progress is nil after resign current");
[arp release]; arp = nil;
return 0;
}