Skip to content

Commit 26ed2cd

Browse files
committed
Fix collaboration support checks in rust unit tests
1 parent e2bd9ea commit 26ed2cd

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

rust/src/collaboration.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ use crate::string::{BnStrCompatible, BnString};
3636
// TODO: on what functions need to have been called prior? I feel like we should make the user have to pull
3737
// TODO: the data because they have a greater understanding of where the function is being called from.
3838

39+
/// Check whether the client has collaboration support.
40+
///
41+
/// Call this if you intend on providing divergent behavior, as otherwise you will likely
42+
/// crash calling collaboration APIs on unsupported builds of Binary Ninja.
43+
pub fn has_collaboration_support() -> bool {
44+
let mut count = 0;
45+
let value = unsafe { BNCollaborationGetRemotes(&mut count) };
46+
!value.is_null()
47+
}
48+
3949
/// Get the single actively connected Remote (for ux simplification), if any
4050
pub fn active_remote() -> Option<Ref<Remote>> {
4151
let value = unsafe { BNCollaborationGetActiveRemote() };

rust/tests/collaboration.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use binaryninja::binary_view::BinaryViewExt;
2-
use binaryninja::collaboration::{NoNameChangeset, Remote, RemoteFileType, RemoteProject};
2+
use binaryninja::collaboration::{has_collaboration_support, NoNameChangeset, Remote, RemoteFileType, RemoteProject};
33
use binaryninja::headless::Session;
44
use binaryninja::symbol::{SymbolBuilder, SymbolType};
55
use rstest::*;
@@ -47,11 +47,11 @@ fn temp_project_scope<T: Fn(&RemoteProject)>(remote: &Remote, cb: T) {
4747

4848
#[rstest]
4949
fn test_connection(_session: &Session) {
50-
let remotes = binaryninja::collaboration::known_remotes();
51-
if remotes.is_empty() {
52-
eprintln!("No known remotes, skipping test...");
50+
if !has_collaboration_support() {
51+
eprintln!("No collaboration support, skipping test...");
5352
return;
5453
}
54+
let remotes = binaryninja::collaboration::known_remotes();
5555
let remote = remotes.iter().next().expect("No known remotes!");
5656
assert!(remote.connect().is_ok(), "Failed to connect to remote");
5757
remote
@@ -62,11 +62,11 @@ fn test_connection(_session: &Session) {
6262

6363
#[rstest]
6464
fn test_project_creation(_session: &Session) {
65-
let remotes = binaryninja::collaboration::known_remotes();
66-
if remotes.is_empty() {
67-
eprintln!("No known remotes, skipping test...");
65+
if !has_collaboration_support() {
66+
eprintln!("No collaboration support, skipping test...");
6867
return;
6968
}
69+
let remotes = binaryninja::collaboration::known_remotes();
7070
let remote = remotes.iter().next().expect("No known remotes!");
7171
temp_project_scope(&remote, |project| {
7272
// Create the file than verify it by opening and checking contents.
@@ -142,11 +142,11 @@ fn test_project_creation(_session: &Session) {
142142

143143
#[rstest]
144144
fn test_project_sync(_session: &Session) {
145-
let remotes = binaryninja::collaboration::known_remotes();
146-
if remotes.is_empty() {
147-
eprintln!("No known remotes, skipping test...");
145+
if !has_collaboration_support() {
146+
eprintln!("No collaboration support, skipping test...");
148147
return;
149148
}
149+
let remotes = binaryninja::collaboration::known_remotes();
150150
let remote = remotes.iter().next().expect("No known remotes!");
151151
temp_project_scope(&remote, |project| {
152152
// Open a view so that we can upload it.

0 commit comments

Comments
 (0)