summaryrefslogtreecommitdiff
path: root/rust/tests
diff options
context:
space:
mode:
authorMark Rowe <mark@vector35.com>2025-08-07 22:53:00 -0700
committerMark Rowe <mark@vector35.com>2025-08-13 19:25:43 -0700
commit395a6dc683bcb687ad5fd1c5b1b63205ffd1af79 (patch)
tree735fa7374b5b91c989e10e0155670360e1c5440e /rust/tests
parente13a82d8a007aa3c2492eaf906f92a8e2adf04e6 (diff)
[Rust] Add builder API for creating workflows
`Workflow::new` is replaced by `Workflow::build` that returns a `Builder` type that supports the operations that mutate a workflow, such as registering activities. `Workflow::instance` is replaced by `Workflow::get` to make clear that it is intended to look up an existing workflow. `Workflow::cloned` is introduced to wrap the common pattern of retrieving an existing workflow and cloning it with the same name in order to modify it. `Builder::activity_before` / `Builder::activity_after` are introduced to wrap the common pattern of registering an activity then inserting it before or after a given activity.
Diffstat (limited to 'rust/tests')
-rw-r--r--rust/tests/workflow.rs55
1 files changed, 16 insertions, 39 deletions
diff --git a/rust/tests/workflow.rs b/rust/tests/workflow.rs
index bf8818c8..8fbe0240 100644
--- a/rust/tests/workflow.rs
+++ b/rust/tests/workflow.rs
@@ -8,8 +8,11 @@ use binaryninja::workflow::Workflow;
#[test]
fn test_workflow_clone() {
let _session = Session::new().expect("Failed to initialize session");
- let original_workflow = Workflow::new("core.function.baseAnalysis");
- let mut cloned_workflow = original_workflow.clone_to("clone_workflow");
+ let original_workflow = Workflow::get("core.function.metaAnalysis").unwrap();
+ let mut cloned_workflow = original_workflow
+ .clone_to("clone_workflow")
+ .register()
+ .unwrap();
assert_eq!(cloned_workflow.name().as_str(), "clone_workflow");
assert_eq!(
@@ -17,36 +20,30 @@ fn test_workflow_clone() {
original_workflow.configuration()
);
- cloned_workflow = original_workflow.clone_to("");
+ // `clone_to` with an empty name should re-use the original workflow's name.
+ cloned_workflow = original_workflow.clone_to("").register().unwrap();
assert_eq!(
cloned_workflow.name().as_str(),
- "core.function.baseAnalysis"
+ original_workflow.name().as_str()
);
}
#[test]
fn test_workflow_registration() {
let _session = Session::new().expect("Failed to initialize session");
- // Validate NULL workflows cannot be registered
- let workflow = Workflow::new("null");
- assert_eq!(workflow.name().as_str(), "null");
- assert!(!workflow.registered());
- workflow
- .register()
- .expect_err("Re-registration of null is allowed");
// Validate new workflows can be registered
- let test_workflow = Workflow::instance("core.function.baseAnalysis").clone_to("test_workflow");
+ let test_workflow = Workflow::get("core.function.baseAnalysis")
+ .unwrap()
+ .clone_to("test_workflow");
- assert_eq!(test_workflow.name().as_str(), "test_workflow");
- assert!(!test_workflow.registered());
- test_workflow
+ let test_workflow = test_workflow
.register()
.expect("Failed to register workflow");
assert!(test_workflow.registered());
assert_eq!(
test_workflow.size(),
- Workflow::instance("core.function.baseAnalysis").size()
+ Workflow::get("core.function.baseAnalysis").unwrap().size()
);
Workflow::list()
.iter()
@@ -57,32 +54,12 @@ fn test_workflow_registration() {
.iter()
.find(|&w| w == "test_workflow")
.expect("Workflow not found in settings");
-
- // Validate that registered workflows are immutable
- let immutable_workflow = Workflow::instance("test_workflow");
- assert!(!immutable_workflow.clear());
- assert!(immutable_workflow.contains("core.function.advancedAnalysis"));
- assert!(!immutable_workflow.remove("core.function.advancedAnalysis"));
- assert!(!Workflow::instance("core.function.baseAnalysis").clear());
+ assert!(Workflow::get("test_workflow").is_some());
// Validate re-registration of baseAnalysis is not allowed
- let base_workflow_clone = Workflow::instance("core.function.baseAnalysis").clone_to("");
-
- assert_eq!(
- base_workflow_clone.name().as_str(),
- "core.function.baseAnalysis"
- );
- assert!(!base_workflow_clone.registered());
+ let base_workflow_clone = Workflow::cloned("core.function.baseAnalysis").unwrap();
base_workflow_clone
.register()
+ .map(|_| ())
.expect_err("Re-registration of baseAnalysis is allowed");
- assert_eq!(
- base_workflow_clone.size(),
- Workflow::instance("core.function.baseAnalysis").size()
- );
- assert_eq!(
- base_workflow_clone.configuration(),
- Workflow::instance("core.function.baseAnalysis").configuration()
- );
- assert!(!base_workflow_clone.registered());
}