74 void wait(
Barrier barrier) { dispatch_semaphore_wait(barriers[barrier], DISPATCH_TIME_FOREVER); }
75 void signal(
Barrier barrier) { dispatch_semaphore_signal(barriers[barrier]); }
78 #define FOREACH_BARRIER(cmd) for (int i = 0; i < BarrierCount; ++i) { cmd }
83 dispatch_semaphore_t barriers[BarrierCount];
86#define WAIT_FOR_BARRIER(b) ThreadBarriers::get()->wait(ThreadBarriers::b);
87#define SIGNAL_BARRIER(b) ThreadBarriers::get()->signal(ThreadBarriers::b);
95 NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init];
97 if (![XCTestProbe isTesting])
100 if (
Q_UNLIKELY(!([NSDate timeIntervalSinceReferenceDate] > 0)))
101 qFatal(
"error: Device date '%s' is bad, likely set to update automatically. Please correct.",
102 [[NSDate
date] description].UTF8String);
111 dispatch_async(dispatch_queue_create(
"io.qt.QTestLib.xctest-wrapper", DISPATCH_QUEUE_SERIAL), ^{
113 [XCTestProbe runTests:nil];
138 dispatch_semaphore_wait(dispatch_semaphore_create(0), DISPATCH_TIME_FOREVER);
148 if ([[[NSProcessInfo processInfo]
arguments] containsObject:
@"--use-testmanagerd"]) {
149 while (!testDriver.IDEConnection)
150 [[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
157 [[NSNotificationCenter defaultCenter] removeObserver:[XCTestProbe class]
158 name:[NSString stringWithFormat:@"%@DidFinishLaunchingNotification",
159 #if defined(Q_OS_MACOS)
167 [autoreleasepool release];
170+ (QTestLibTests *)defaultTestSuite
175+ (BOOL)usingTestManager
177 return [[[NSProcessInfo processInfo] arguments] containsObject:@"--use-testmanagerd"];
188- (
void)performTest:(XCTestSuiteRun *)testSuiteRun
202 [testSuiteRun start];
214+ (XCTestSuiteRun*)testRun
225- (instancetype)initWithInvocation:(NSInvocation *)invocation
227 if (self = [super initWithInvocation:invocation]) {
230 self.testObjectName = [NSString stringWithUTF8String:QTestResult::currentTestObjectName()];
231 self.testFunctionName = [NSString stringWithUTF8String:QTestResult::currentTestFunction()];
237- (NSString *)testClassName
239 return self.testObjectName;
242- (NSString *)testMethodName
244 return self.testFunctionName;
247- (NSString *)nameForLegacyLogging
249 NSString *
name = [NSString stringWithFormat:@"%@::%@", [
self testClassName], [
self testMethodName]];
253 const char *filler = (
currentDataTag[0] && globalDataTag[0]) ?
":" :
"";
254 name = [name stringByAppendingString:[NSString stringWithFormat:@"(%s%s%s)",
255 globalDataTag, filler, currentDataTag]];
267 return [XCTestProbe isTesting];
272 if (strncmp(
argument,
"-NS", 3) == 0 || strncmp(
argument,
"-Apple", 6) == 0)
274 else if (strcmp(
argument,
"--use-testmanagerd") == 0)
276 else if (strncmp(
argument,
"-XCTest", 7) == 0)
292 , m_testRuns([[NSMutableArray<XCTestRun *> arrayWithCapacity:2] retain])
296 s_currentTestLogger =
this;
301 s_currentTestLogger = 0;
302 [m_testRuns release];
309 static dispatch_once_t onceToken;
310 dispatch_once (&onceToken, ^{
317 NSString *suiteName = [NSString stringWithUTF8String:QTestResult::currentTestObjectName()];
318 pushTestRunForTest([XCTestSuite testSuiteWithName:suiteName], true);
326static bool isTestFunctionInActiveScope(
const char *function)
328 static NSString *testScope = [XCTestProbe testScope];
331 static TestScope activeScope =
Unknown;
334 if ([testScope isEqualToString:
@"All"])
336 else if ([testScope isEqualToString:
@"None"])
338 else if ([testScope isEqualToString:
@"Self"])
341 activeScope = Selected;
344 if (activeScope ==
All)
346 else if (activeScope ==
None)
348 else if (activeScope == Self)
353 static NSArray<NSString *> *forcedTests = [@[ @"initTestCase", @"initTestCase_data", @"cleanupTestCase" ] retain];
354 if ([forcedTests containsObject:[NSString stringWithUTF8String:function]])
357 static NSArray<NSString *> *testsInScope = [[testScope componentsSeparatedByString:@","] retain];
358 bool inScope = [testsInScope containsObject:[NSString stringWithFormat:@"%s/%s",
359 QTestResult::currentTestObjectName(), function]];
361 if ([XCTestProbe isInverseTestScope])
369 if (!isTestFunctionInActiveScope(function))
384 XCTestRun *testRun = [m_testRuns lastObject];
391 NSString *testCaseName = [[testRun test] nameForLegacyLogging];
393 [testCaseName UTF8String], description);
405 NSString *testCaseName = [[testRun test] nameForLegacyLogging];
413 if (!
file || !description)
416 [testRun recordFailureWithDescription:[NSString stringWithUTF8String:description]
417 inFile:[NSString stringWithUTF8String:file] atLine:line expected:YES];
431 XCTestRun *testRun = [m_testRuns lastObject];
432 NSString *testCaseName = [[testRun test] nameForLegacyLogging];
434 [testCaseName UTF8String],
message.toUtf8().constData());
447void QXcodeTestLogger::pushTestRunForTest(XCTest *test,
bool start)
449 XCTestRun *testRun = [[test testRunClass] testRunWithTest:test];
450 [m_testRuns addObject:testRun];
456XCTestRun *QXcodeTestLogger::popTestRun()
458 XCTestRun *testRun = [[m_testRuns lastObject] retain];
459 [m_testRuns removeLastObject];
464 [[m_testRuns lastObject] addTestRun:testRun];
472 return s_currentTestLogger;
void addMessage(MessageTypes type, const QString &message, const char *file=nullptr, int line=0) override
This is an overloaded member function, provided for convenience. It differs from the above function o...