mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Add NSThread unit test for name: and setName: on win32
This commit is contained in:
parent
10eaba4f13
commit
80c3d66677
1 changed files with 44 additions and 0 deletions
44
Tests/base/NSThread/name.m
Normal file
44
Tests/base/NSThread/name.m
Normal file
|
@ -0,0 +1,44 @@
|
|||
#import "ObjectTesting.h"
|
||||
#include <winerror.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");
|
||||
|
||||
NSString *name = [[[NSThread alloc] init] name];
|
||||
PASS(name != nil, "-[NSThread name] returns a valid string");
|
||||
NSLog(@"Name: %@", name);
|
||||
PASS([name isEqualToString: @"Test"], "Thread name is correct");
|
||||
[name 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;
|
||||
}
|
Loading…
Reference in a new issue