libs-base/Tests/base/NSProgress/basic.m

57 lines
2 KiB
Mathematica
Raw Normal View History

2019-08-10 05:40:09 +00:00
#import <Foundation/NSProgress.h>
#import <Foundation/NSThread.h>
#import <Foundation/NSAutoreleasePool.h>
#import "ObjectTesting.h"
int main()
{
2024-11-16 21:11:56 +00:00
ENTER_POOL
2022-04-29 12:38:35 +00:00
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
2024-11-16 21:11:56 +00:00
2022-04-29 12:38:35 +00:00
[dict setObject:@"value" forKey:@"key"];
2024-11-16 21:11:56 +00:00
NSProgress *progress = AUTORELEASE([[NSProgress alloc] initWithParent: nil
userInfo: dict]);
PASS(progress != nil,
"[NSProgress initWithParent:userInfo:] returns instance");
2019-08-10 05:40:09 +00:00
PASS_EQUAL([progress userInfo], dict,
"[NSProgress userInfo] returns correct user info");
2022-04-29 12:38:35 +00:00
[progress setUserInfoObject:@"new value" forKey:@"key"];
PASS_EQUAL([[progress userInfo] objectForKey:@"key"], @"new value",
"[NSProgress setUserInfoObject:forKey:] updates user info");
2022-04-29 12:38:35 +00:00
2019-08-10 05:40:09 +00:00
progress = [NSProgress discreteProgressWithTotalUnitCount:100];
PASS(progress != nil,
"[NSProgress discreteProgressWithTotalUnitCount:] returns instance");
2019-08-10 05:40:09 +00:00
progress = [NSProgress progressWithTotalUnitCount:100];
PASS(progress != nil,
"[NSProgress progressWithTotalUnitCount:] returns instance");
2019-08-10 05:40:09 +00:00
progress = [NSProgress progressWithTotalUnitCount:100
parent:progress
pendingUnitCount:50];
PASS(progress != nil,
"[NSProgress progressWithTotalUnitCount:] returns instance");
2019-08-10 05:40:09 +00:00
[progress becomeCurrentWithPendingUnitCount:50];
NSProgress *currentProgress = [NSProgress currentProgress];
PASS(currentProgress == progress,
"Correct progress object associated with current thread");
2019-08-10 05:40:09 +00:00
NSProgress *new_progress = [NSProgress progressWithTotalUnitCount:100
parent:progress
pendingUnitCount:50];
2024-11-16 21:11:56 +00:00
[new_progress addChild: AUTORELEASE([[NSProgress alloc]
initWithParent: nil userInfo: nil]) withPendingUnitCount:50];
2019-08-10 05:40:09 +00:00
[currentProgress resignCurrent];
PASS([NSProgress currentProgress] == nil,
"Current progress is nil after resign current");
2019-08-10 05:40:09 +00:00
2024-11-16 21:11:56 +00:00
LEAVE_POOL
2019-08-10 05:40:09 +00:00
return 0;
}