-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
432 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (C) 2024 Tristan Gerritsen <tristan@thewoosh.org> | ||
// All Rights Reserved. | ||
|
||
fn main() { | ||
#[cfg(all(target_os = "macos", test))] | ||
configure_xctest(); | ||
} | ||
|
||
#[cfg(all(target_os = "macos", test))] | ||
fn configure_xctest() { | ||
println!("cargo:rustc-link-lib=framework=XCTest"); | ||
println!("cargo:rustc-link-search=framework=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks/"); | ||
|
||
println!("cargo:rustc-env=DYLD_FRAMEWORK_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks/"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright (C) 2024 Tristan Gerritsen <tristan@thewoosh.org> | ||
// All Rights Reserved. | ||
|
||
mod xcuiapplication; | ||
mod xcuiapplicationstate; | ||
|
||
use std::{io::{stdout, Write}, sync::Once}; | ||
|
||
use cacao::{foundation::NSString, objc::runtime::Class}; | ||
|
||
pub(crate) use self::{ | ||
xcuiapplication::XCUIApplication, | ||
xcuiapplicationstate::XCUIApplicationState, | ||
}; | ||
|
||
const BUNDLE_LOAD: Once = Once::new(); | ||
|
||
pub(crate) fn load_xc_test_into_bundle() { | ||
println!("LOADBUNDLE"); | ||
|
||
use cacao::objc::{class, msg_send, sel, sel_impl}; | ||
use cacao::objc::runtime::Object; | ||
BUNDLE_LOAD.call_once(|| { | ||
let result = unsafe { | ||
objc_exception::r#try(|| { | ||
let path = NSString::new("/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks/XCTest.framework"); | ||
let xctest_framework: *const Object = msg_send![class!(NSBundle), bundleWithPath: &*path.objc]; | ||
let _: () = msg_send![xctest_framework, load]; | ||
}) | ||
}; | ||
|
||
if let Err(e) = result { | ||
panic!("Failed to load bundle: {e:p}"); | ||
} | ||
}); | ||
|
||
for class in Class::classes().into_iter() { | ||
if !class.name().starts_with("XCTestConfiguration") { continue } | ||
eprintln!("\n\nClass: {}", class.name()); | ||
|
||
for protocol in class.adopted_protocols().iter() { | ||
eprintln!(" Protocol: {}", protocol.name()); | ||
} | ||
|
||
for variable in class.instance_variables().iter() { | ||
eprintln!(" Variable: {}", variable.name()); | ||
} | ||
|
||
for method in class.instance_methods().iter() { | ||
eprintln!(" Method: {}", method.name().name()); | ||
eprintln!(" Return Type: {}", method.return_type().as_str()); | ||
eprintln!(" Arguments: {}", method.arguments_count()); | ||
for i in 0..method.arguments_count() { | ||
eprintln!(" * Argument {i}: {:?}", method.argument_type(i).map(|x| x.as_str().to_owned()).unwrap_or_default()); | ||
} | ||
} | ||
} | ||
|
||
println!("done load"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright (C) 2024 Tristan Gerritsen <tristan@thewoosh.org> | ||
// All Rights Reserved. | ||
|
||
use cacao::{foundation::{id, NSString, NSUInteger, NSURL}, objc::{class, msg_send, runtime::Class, sel, sel_impl}, utils::properties::ObjcProperty}; | ||
|
||
use super::XCUIApplicationState; | ||
|
||
pub(crate) struct XCUIApplication { | ||
objc: ObjcProperty, | ||
} | ||
|
||
impl XCUIApplication { | ||
/// <https://developer.apple.com/documentation/xctest/xcuiapplication/2879413-initwithurl?language=objc> | ||
pub fn init_with_url(uurl: &str) -> Self { | ||
super::load_xc_test_into_bundle(); | ||
|
||
let url = NSString::new(uurl); | ||
let obj: id = unsafe { | ||
let url: id = msg_send![class!(NSURL), URLWithString:&*url]; | ||
println!("URL: {url:p} from \"{uurl}\""); | ||
|
||
// let obj: id = msg_send![class!(XCUIApplication), new]; | ||
// let obj: id = msg_send![obj, initWithURL:url]; | ||
let obj: id = msg_send![class!(XCUIApplication), alloc]; | ||
let obj: id = msg_send![obj, initWithURL:url]; | ||
obj | ||
}; | ||
|
||
Self { | ||
objc: ObjcProperty::retain(obj), | ||
} | ||
} | ||
|
||
pub fn activate(&self) { | ||
let _: () = self.objc.get(|objc| unsafe { | ||
msg_send![objc, activate] | ||
}); | ||
} | ||
|
||
pub fn state(&self) -> XCUIApplicationState { | ||
let id: NSUInteger = self.objc.get(|objc| unsafe { | ||
msg_send![ | ||
objc, state | ||
] | ||
}); | ||
|
||
id.into() | ||
} | ||
} | ||
|
||
impl Drop for XCUIApplication { | ||
fn drop(&mut self) { | ||
self.objc.with_mut(|obj| unsafe { | ||
let _: () = msg_send![obj, terminate]; | ||
}) | ||
} | ||
} |
Oops, something went wrong.