Merge branch 'master' into NSBundle-msvc-tests

This commit is contained in:
Hugo Melder 2022-08-11 09:16:06 +02:00 committed by GitHub
commit ca9136397d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 142 additions and 39 deletions

3
.gitignore vendored
View file

@ -10,6 +10,7 @@ Tests/base/*/GNUmakefile
*.sum
# Test products
Tests/base/coding/*.type
Tests/base/NSBundle/Resources/TestBundle.bundle/
Tests/base/NSBundle/Resources/TestFramework.framework/
Tests/base/NSBundle/Resources/derived_src/
@ -67,4 +68,4 @@ DerivedData/
### Xcode Patch ###
**/xcshareddata/WorkspaceSettings.xcsettings
# End of https://www.gitignore.io/api/xcode
# End of https://www.gitignore.io/api/xcode

View file

@ -1,3 +1,19 @@
2022-08-05 Hugo Melder <contact@hugomelder.com>
* Tests/base/NSTask/Helpers/GNUmakefile:
Fix compilation of NSTask helper test files on Windows MSVC.
* Tests/base/NSTask/general.m:
* Tests/base/NSTask/launch.m:
* Tests/base/NSTask/notify.m:
Conditionally use .exe suffix in executable paths.
2022-08-04 Hugo Melder <contact@hugomelder.com>
* Tests/base/coding/basictypes.m:
Fetch the generated .type file directly to avoid size mismatches.
* .gitignore:
Ignore .type files in the coding unit test directory.
2022-08-03 Hugo Melder <contact@hugomelder.com>
* Tests/base/NSBundle/GNUmakefile.preamble

View file

@ -1438,9 +1438,19 @@ static NSMapTable *absolutes = 0;
*/
{
TIME_ZONE_INFORMATION tz;
DWORD dst = GetTimeZoneInformation(&tz);
DWORD dst;
wchar_t *tzName;
#if defined(_MSC_VER) && defined(UCAL_H)
// Get time zone name for US locale as expected by ICU method below
LANGID origLangID = GetThreadUILanguage();
SetThreadUILanguage(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US));
dst = GetTimeZoneInformation(&tz);
SetThreadUILanguage(origLangID);
#else
dst = GetTimeZoneInformation(&tz);
#endif
localZoneSource = @"function: 'GetTimeZoneInformation()'";
if (dst == TIME_ZONE_ID_DAYLIGHT)
tzName = tz.DaylightName;
@ -1453,11 +1463,14 @@ static NSMapTable *absolutes = 0;
{
UErrorCode status = U_ZERO_ERROR;
UChar ianaTzName[128];
ucal_getTimeZoneIDForWindowsID(tzName, -1, NULL, ianaTzName, 128,
&status);
if (U_SUCCESS(status)) {
int32_t ianaTzNameLen = ucal_getTimeZoneIDForWindowsID(tzName,
-1, NULL, ianaTzName, 128, &status);
if (U_SUCCESS(status) && ianaTzNameLen > 0) {
localZoneString = [NSString stringWithCharacters: ianaTzName
length: u_strlen(ianaTzName)];
length: ianaTzNameLen];
} else if (U_SUCCESS(status)) {
// this happens when ICU has no mapping for the time zone
NSLog(@"Unable to map timezone '%ls' to IANA format", tzName);
} else {
NSLog(@"Error converting timezone '%ls' to IANA format: %s",
tzName, u_errorName(status));

View file

@ -752,6 +752,19 @@ static NSUInteger urlAlign;
aUrlString = [aUrlString initWithFormat: @"%@://%@%@",
aScheme, aHost, aPath];
}
#if defined(_WIN32)
/* On Windows file systems, an absolute file path can begin with
* a drive letter. The first component in an absolute path
* (e.g. C:) has to be enclosed by a leading slash.
*
* "file:///c:/path/to/file"
*/
else if ([aScheme isEqualToString: @"file"] && [aPath characterAtIndex:1] == ':')
{
aUrlString = [aUrlString initWithFormat: @"%@:///%@%@",
aScheme, aHost, aPath];
}
#endif
else
{
aUrlString = [aUrlString initWithFormat: @"%@://%@/%@",

View file

@ -16,6 +16,8 @@ int main()
GSXMLNode *node;
GSXMLRPC *rpc;
NSString *str;
NSString *testPath;
NSString *absolutePath;
NSData *dat;
TEST_FOR_CLASS(@"GSXMLDocument",[GSXMLDocument alloc],
@ -149,13 +151,16 @@ int main()
"Can parse a method call with a date");
mgr = [NSFileManager defaultManager];
testPath = [[mgr currentDirectoryPath]
stringByAppendingPathComponent: @"GNUmakefile"];
absolutePath = [[NSURL fileURLWithPath: testPath] absoluteString];
str = [NSString stringWithFormat:
@"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
@"<!DOCTYPE foo [\n"
@"<!ENTITY foo SYSTEM \"file://%@/GNUmakefile\">\n"
@"<!ENTITY foo SYSTEM \"%@\">\n"
@"]>\n"
@"<file>&amp;&foo;&#65;</file>", [mgr currentDirectoryPath]];
@"<file>&amp;&foo;&#65;</file>", absolutePath];
parser = [GSXMLParser parserWithData:
[str dataUsingEncoding: NSUTF8StringEncoding]];

View file

@ -10,27 +10,34 @@ int main()
[dict setObject:@"value" forKey:@"key"];
NSProgress *progress = [[NSProgress alloc] initWithParent: nil
userInfo: dict];
PASS(progress != nil, "[NSProgress initWithParent:userInfo:] returns instance");
PASS(progress != nil,
"[NSProgress initWithParent:userInfo:] returns instance");
PASS_EQUAL([progress userInfo], dict, @"[NSProgress userInfo] returns correct user info");
PASS_EQUAL([progress userInfo], dict,
"[NSProgress userInfo] returns correct user info");
[progress setUserInfoObject:@"new value" forKey:@"key"];
PASS_EQUAL([[progress userInfo] objectForKey:@"key"], @"new value", @"[NSProgress setUserInfoObject:forKey:] updates user info");
PASS_EQUAL([[progress userInfo] objectForKey:@"key"], @"new value",
"[NSProgress setUserInfoObject:forKey:] updates user info");
progress = [NSProgress discreteProgressWithTotalUnitCount:100];
PASS(progress != nil, "[NSProgress discreteProgressWithTotalUnitCount:] returns instance");
PASS(progress != nil,
"[NSProgress discreteProgressWithTotalUnitCount:] returns instance");
progress = [NSProgress progressWithTotalUnitCount:100];
PASS(progress != nil, "[NSProgress progressWithTotalUnitCount:] returns instance");
PASS(progress != nil,
"[NSProgress progressWithTotalUnitCount:] returns instance");
progress = [NSProgress progressWithTotalUnitCount:100
parent:progress
pendingUnitCount:50];
PASS(progress != nil, "[NSProgress progressWithTotalUnitCount:] returns instance");
PASS(progress != nil,
"[NSProgress progressWithTotalUnitCount:] returns instance");
[progress becomeCurrentWithPendingUnitCount:50];
NSProgress *currentProgress = [NSProgress currentProgress];
PASS(currentProgress == progress, "Correct progress object associated with current thread");
PASS(currentProgress == progress,
"Correct progress object associated with current thread");
NSProgress *new_progress = [NSProgress progressWithTotalUnitCount:100
parent:progress
@ -40,7 +47,8 @@ int main()
[currentProgress resignCurrent];
PASS([NSProgress currentProgress] == nil, "Current progress is nil after resign current");
PASS([NSProgress currentProgress] == nil,
"Current progress is nil after resign current");
[arp release]; arp = nil;
return 0;

View file

@ -9,7 +9,7 @@ NSZombie_OBJC_FILES = NSZombie.m
processgroup_OBJC_FILES = processgroup.m
testcat_OBJC_FILES = testcat.m
testcat_C_FILES = testcat.c
testecho_OBJC_FILES = testecho.m

View file

@ -10,6 +10,8 @@ int main()
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSFileManager *mgr;
NSString *helpers;
NSString *testecho;
NSString *testcat;
NSArray *args;
id task;
id info;
@ -18,6 +20,16 @@ int main()
id pth2;
BOOL yes;
/* Windows MSVC adds the '.exe' suffix to executables
*/
#if defined(_MSC_VER)
testecho = @"testecho.exe";
testcat = @"testcat.exe";
#else
testecho = @"testecho";
testcat = @"testcat";
#endif
info = [NSProcessInfo processInfo];
env = [[info environment] mutableCopy];
yes = YES;
@ -32,7 +44,8 @@ int main()
helpers = [helpers stringByAppendingPathComponent: @"Helpers"];
helpers = [helpers stringByAppendingPathComponent: @"obj"];
pth1 = [helpers stringByAppendingPathComponent: @"testcat"];
pth1 = [helpers stringByAppendingPathComponent: testcat];
pth2 = [helpers stringByAppendingPathComponent: testecho];
/* Try some tasks. Make sure the program we use is common between Unix
and Windows (and others?) */
@ -43,7 +56,6 @@ int main()
task = [NSTask new];
args = [NSArray arrayWithObjects: @"xxx", @"yyy", nil];
pth2 = [helpers stringByAppendingPathComponent: @"testecho"];
[task setEnvironment: env];
[task setLaunchPath: pth2];
[task setArguments: args];

View file

@ -8,15 +8,28 @@
int main()
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
NSTask *task;
NSPipe *outPipe;
NSFileManager *mgr;
NSString *helpers;
NSString *testecho;
NSString *testcat;
NSString *processgroup;
NSFileHandle *outHandle;
NSAutoreleasePool *arp;
NSData *data = nil;
arp = [[NSAutoreleasePool alloc] init];
/* Windows MSVC adds the '.exe' suffix to executables
*/
#if defined(_MSC_VER)
testecho = @"testecho.exe";
testcat = @"testcat.exe";
processgroup = @"processgroup.exe";
#else
testecho = @"testecho";
testcat = @"testcat";
processgroup = @"processgroup";
#endif
mgr = [NSFileManager defaultManager];
helpers = [mgr currentDirectoryPath];
@ -25,7 +38,7 @@ int main()
task = [[NSTask alloc] init];
outPipe = [[NSPipe pipe] retain];
[task setLaunchPath: [helpers stringByAppendingPathComponent: @"testcat"]];
[task setLaunchPath: [helpers stringByAppendingPathComponent: testcat]];
[task setArguments: [NSArray arrayWithObjects: nil]];
[task setStandardOutput: outPipe];
outHandle = [outPipe fileHandleForReading];
@ -39,7 +52,7 @@ int main()
task = [[NSTask alloc] init];
outPipe = [[NSPipe pipe] retain];
[task setLaunchPath: [helpers stringByAppendingPathComponent: @"testecho"]];
[task setLaunchPath: [helpers stringByAppendingPathComponent: testecho]];
[task setArguments: [NSArray arrayWithObjects: @"Hello", @"there", nil]];
[task setStandardOutput: outPipe];
outHandle = [outPipe fileHandleForReading];
@ -59,7 +72,7 @@ int main()
#if !defined(_WIN32)
task = [[NSTask alloc] init];
[task setLaunchPath:
[helpers stringByAppendingPathComponent: @"processgroup"]];
[helpers stringByAppendingPathComponent: processgroup]];
[task setArguments: [NSArray arrayWithObjects:
[NSString stringWithFormat: @"%d", getpgrp()],
nil]];

View file

@ -32,7 +32,19 @@ static BOOL taskTerminationNotificationReceived;
- (void) testNSTaskNotifications
{
NSDate *deadline;
NSString *testsleep;
NSString *testecho;
BOOL earlyTermination = NO;
/* Windows MSVC adds the '.exe' suffix to executables
*/
#if defined(_MSC_VER)
testecho = @"testecho.exe";
testsleep = @"testsleep.exe";
#else
testecho = @"testecho";
testsleep = @"testsleep";
#endif
for (;;)
{
@ -48,7 +60,7 @@ static BOOL taskTerminationNotificationReceived;
{
BOOL terminated = NO;
[task setLaunchPath:
[path stringByAppendingPathComponent: @"testsleep"]];
[path stringByAppendingPathComponent: testsleep]];
[task launch];
NSLog(@"Launched pid %d", [task processIdentifier]);
NSLog(@"Running run loop for 5 seconds");
@ -74,7 +86,7 @@ static BOOL taskTerminationNotificationReceived;
else
{
[task setLaunchPath:
[path stringByAppendingPathComponent: @"testecho"]];
[path stringByAppendingPathComponent: testecho]];
[task launch];
NSLog(@"Launched pid %d", [task processIdentifier]);
NSLog(@"Running run loop for 15 seconds");

View file

@ -2,6 +2,7 @@
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSFileManager.h>
#import <Foundation/NSStream.h>
#import <Foundation/NSURL.h>
#import <Foundation/NSUserDefaults.h>
#import <Foundation/NSXMLParser.h>
#include <string.h>
@ -256,6 +257,12 @@ testParser(NSXMLParser *parser, NSString *expect)
}
else
{
#if defined(_WIN32)
/* Replace CRLF from result files with LF
*/
expect = [expect stringByReplacingOccurrencesOfString: @"\r\n" withString: @"\n"];
#endif
if (NO == [[handler description] isEqual: expect])
{
NSLog(@"######## Expected:\n%@\n######## Parsed:\n%@\n########\n",
@ -370,6 +377,8 @@ int main()
{
NSString *exp;
NSString *mgrPath;
NSString *absolutePath;
NSData *dat;
exp = @"parserDidStartDocument:\n\
@ -378,10 +387,13 @@ parser:didStartElement:namespaceURI:qualifiedName:attributes: file file {\n}\n\
parserDidEndDocument:\n\
";
mgrPath = [[mgr currentDirectoryPath] stringByAppendingPathComponent: @"GNUmakefile"];
absolutePath = [[NSURL fileURLWithPath: mgrPath] absoluteString];
str = [NSString stringWithFormat:
@"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
@"<!DOCTYPE file [<!ENTITY foo SYSTEM \"file://%@/GNUmakefile\">]>\n"
@"<file>&amp;&foo;&#65;</file>", [mgr currentDirectoryPath]];
@"<!DOCTYPE file [<!ENTITY foo SYSTEM \"%@\">]>\n"
@"<file>&amp;&foo;&#65;</file>", absolutePath];
dat = [str dataUsingEncoding: NSUTF8StringEncoding];
PASS((testParseData(dat, exp, YES)), "external entity (strict)")

Binary file not shown.

View file

@ -114,15 +114,10 @@ void testReadBasicType_##testName (char *pre, testType *expect, testType *toDeco
NSData *data; \
NSUnarchiver *unArch; \
NSString *str2; \
NSArray *encodedFiles; \
NSString *prefix = [[NSString stringWithCString:pre] retain]; \
unsigned int i, c; \
encodedFiles = [[NSBundle bundleWithPath: [fm currentDirectoryPath]] \
pathsForResourcesOfType:@"type" inDirectory:nil]; \
for (i = 0, c = [encodedFiles count]; i < c; i++) \
{ \
NSString *fileName = [encodedFiles objectAtIndex:i]; \
if ([[fileName lastPathComponent] hasPrefix:prefix]) \
NSString *fileName; \
long typeSize = sizeof(testType); \
fileName = [[NSString stringWithFormat:@"%s-%li.type",pre,typeSize] retain]; \
if ([fm isReadableFileAtPath:fileName]) \
{ \
data = [NSData dataWithContentsOfFile:fileName]; \
unArch = [[NSUnarchiver alloc] initForReadingWithData:data]; \
@ -136,7 +131,10 @@ void testReadBasicType_##testName (char *pre, testType *expect, testType *toDeco
PASS((VAL_TEST(*expect,*toDecode) && [str isEqual:str2]), \
"can unarchive %s from %s", pre, [fileName UTF8String]); \
} \
} \
else \
{ \
PASS(1 == 2, "Archive %s not found.", [fileName UTF8String]); \
} \
}
#define VAL_TEST(testX,testY) testX == testY

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.