@@ -16,6 +16,7 @@ final class HelloCodenameOneUITests: XCTestCase {
1616
1717 override func setUpWithError() throws {
1818 continueAfterFailure = false
19+ print("CN1SS:INFO:setup_begin test_class=HelloCodenameOneUITests")
1920 let env = ProcessInfo.processInfo.environment
2021
2122 if let bundleID = env["CN1_AUT_BUNDLE_ID"], !bundleID.isEmpty {
@@ -37,7 +38,11 @@ final class HelloCodenameOneUITests: XCTestCase {
3738 } else {
3839 outputDirectory = tmp.appendingPathComponent("cn1screens", isDirectory: true)
3940 }
40- try FileManager.default.createDirectory(at: outputDirectory, withIntermediateDirectories: true)
41+ do {
42+ try FileManager.default.createDirectory(at: outputDirectory, withIntermediateDirectories: true)
43+ } catch {
44+ print("CN1SS:WARN:output_directory_create_failed path=\(outputDirectory.path) error=\(error)")
45+ }
4146
4247 print("CN1SS:INFO:ui_test_target_bundle_id=\(targetBundleIdentifier ?? "(scheme-default)")")
4348 print("CN1SS:INFO:ui_test_launch_arguments=\(app.launchArguments.joined(separator: " "))")
@@ -276,7 +281,7 @@ final class HelloCodenameOneUITests: XCTestCase {
276281 if let explicit = targetBundleIdentifier, !explicit.isEmpty {
277282 return explicit
278283 }
279- if let bundle: String = dynamicAppValue ("bundleID") {
284+ if let bundle: String = codenameApplicationValue ("bundleID", for: app ) {
280285 if !bundle.isEmpty {
281286 return bundle
282287 }
@@ -371,6 +376,29 @@ final class HelloCodenameOneUITests: XCTestCase {
371376 }
372377}
373378
379+ private func codenameApplicationValue<T>(_ selectorName: String, for application: XCUIApplication) -> T? {
380+ let selector = NSSelectorFromString(selectorName)
381+ guard application.responds(to: selector) else {
382+ return nil
383+ }
384+ guard let unmanaged = application.perform(selector) else {
385+ return nil
386+ }
387+ let value = unmanaged.takeUnretainedValue()
388+ switch value {
389+ case let typed as T:
390+ return typed
391+ case let number as NSNumber where T.self == Bool.self:
392+ return (number.boolValue as? T)
393+ case let string as NSString where T.self == String.self:
394+ return (string as String) as? T
395+ case let url as NSURL where T.self == URL.self:
396+ return (url as URL) as? T
397+ default:
398+ return nil
399+ }
400+ }
401+
374402private final class CodenameOneMainInvoker {
375403 static let shared = CodenameOneMainInvoker()
376404
@@ -393,7 +421,9 @@ private final class CodenameOneMainInvoker {
393421 return
394422 }
395423
424+ print("CN1SS:INFO:codenameone_main_invoking bundle=\(bundleIdentifier)")
396425 context.invoke()
426+ print("CN1SS:INFO:codenameone_main_invocation_complete bundle=\(bundleIdentifier)")
397427
398428 queue.sync {
399429 invokedBundles.insert(bundleIdentifier)
@@ -407,11 +437,13 @@ private final class CodenameOneMainInvoker {
407437 print("CN1SS:WARN:codenameone_main_skipped reason=container_missing bundle=\(bundleIdentifier)")
408438 return nil
409439 }
440+ print("CN1SS:INFO:codenameone_main_container bundle=\(bundleIdentifier) path=\(container)")
410441
411442 guard let executable = readExecutableName(appContainer: container) else {
412443 print("CN1SS:WARN:codenameone_main_skipped reason=executable_missing bundle=\(bundleIdentifier)")
413444 return nil
414445 }
446+ print("CN1SS:INFO:codenameone_main_executable bundle=\(bundleIdentifier) name=\(executable)")
415447
416448 let binaryPath = (container as NSString).appendingPathComponent(executable)
417449 guard let handle = dlopen(binaryPath, RTLD_NOW | RTLD_GLOBAL) else {
@@ -422,6 +454,7 @@ private final class CodenameOneMainInvoker {
422454 }
423455 return nil
424456 }
457+ print("CN1SS:INFO:codenameone_main_dlopen_success bundle=\(bundleIdentifier) binary=\(binaryPath)")
425458
426459 guard let initPtr = dlsym(handle, "initConstantPool") else {
427460 print("CN1SS:WARN:codenameone_main_skipped reason=missing_initConstantPool bundle=\(bundleIdentifier)")
@@ -447,11 +480,11 @@ private final class CodenameOneMainInvoker {
447480 }
448481
449482 private func locateAppContainer(app: XCUIApplication, bundleIdentifier: String) -> String? {
450- if let bundleURL: URL = dynamicAppValue ("bundleURL"), !bundleURL.path.isEmpty {
483+ if let bundleURL: URL = codenameApplicationValue ("bundleURL", for: app ), !bundleURL.path.isEmpty {
451484 return bundleURL.path
452485 }
453486
454- if let bundlePath: String = dynamicAppValue ("bundlePath"), !bundlePath.isEmpty {
487+ if let bundlePath: String = codenameApplicationValue ("bundlePath", for: app ), !bundlePath.isEmpty {
455488 return bundlePath
456489 }
457490
@@ -522,29 +555,6 @@ private final class CodenameOneMainInvoker {
522555 return output
523556 }
524557
525- private func dynamicAppValue<T>(_ selectorName: String) -> T? {
526- let selector = NSSelectorFromString(selectorName)
527- guard app.responds(to: selector) else {
528- return nil
529- }
530- guard let unmanaged = app.perform(selector) else {
531- return nil
532- }
533- let value = unmanaged.takeUnretainedValue()
534- switch value {
535- case let typed as T:
536- return typed
537- case let number as NSNumber where T.self == Bool.self:
538- return (number.boolValue as? T)
539- case let string as NSString where T.self == String.self:
540- return (string as String) as? T
541- case let url as NSURL where T.self == URL.self:
542- return (url as URL) as? T
543- default:
544- return nil
545- }
546- }
547-
548558 private struct InvocationContext {
549559 typealias InitConstantPoolFn = @convention(c) () -> Void
550560 typealias GetThreadLocalDataFn = @convention(c) () -> UnsafeMutableRawPointer?
0 commit comments