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
|
#import "ObjectTesting.h"
#import <Foundation/NSThread.h>
#if defined(_WIN32) && (NTDDI_VERSION >= NTDDI_WIN10_RS1)
#include <processthreadsapi.h>
#else
#include <pthread.h>
#endif
int main(void)
{
NSAutoreleasePool *arp = [NSAutoreleasePool new];
// SetThreadDescription() was added in Windows 10 1607 (Redstone 1)
#if defined(_WIN32) && (NTDDI_VERSION >= NTDDI_WIN10_RS1)
PWSTR nativeThreadName = NULL;
HANDLE current = GetCurrentThread();
HRESULT hr = SetThreadDescription(current, L"Test");
PASS(SUCCEEDED(hr), "SetThreadDescription was successful");
NSThread *thread = [[NSThread alloc] init];
NSString *name = [thread name];
PASS(name != nil, "-[NSThread name] returns a valid string");
NSLog(@"Name: %@", name);
PASS([name isEqualToString: @"Test"], "Thread name is correct");
[thread release];
[[NSThread currentThread] setName: @"Test2"];
name = [[NSThread currentThread] name];
PASS(name != nil, "-[NSThread name] returns a valid string");
PASS([name isEqualToString: @"Test2"], "-[NSThread name] returns a valid string after setName");
hr = GetThreadDescription(current, &nativeThreadName);
PASS(SUCCEEDED(hr), "SetThreadDescription was successful");
name = [NSString stringWithCharacters: (void *)nativeThreadName length: wcslen(nativeThreadName)];
PASS([name isEqualToString: @"Test2"], "-[NSThread setName] successfully updated thread name");
LocalFree(nativeThreadName);
#else
#endif
return 0;
}
|