Skip to content

Commit 12bca36

Browse files
authored
Merge pull request #383 from maspe36/remove_rclrs_tests
Move the tests in the `rclrs_tests` crate into `rclrs`.
2 parents 996c091 + 42e0b5c commit 12bca36

27 files changed

+412
-403
lines changed

rclrs/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,11 @@ libloading = { version = "0.8", optional = true }
2626
# Needed for the Message trait, among others
2727
rosidl_runtime_rs = "0.4"
2828

29-
[dependencies.builtin_interfaces]
30-
version = "*"
31-
3229
[dev-dependencies]
3330
# Needed for e.g. writing yaml files in tests
3431
tempfile = "3.3.0"
32+
# Needed for publisher and subscriber tests
33+
test_msgs = {version = "*"}
3534

3635
[build-dependencies]
3736
# Needed for FFI

rclrs/package.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
<depend>builtin_interfaces</depend>
2020
<depend>rcl_interfaces</depend>
2121
<depend>rosgraph_msgs</depend>
22+
23+
<test_depend>test_msgs</test_depend>
2224

2325
<export>
2426
<build_type>ament_cargo</build_type>

rclrs/src/client.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,3 +289,38 @@ where
289289
Ok(())
290290
}
291291
}
292+
293+
#[cfg(test)]
294+
mod tests {
295+
use super::*;
296+
use crate::test_helpers::*;
297+
use test_msgs::srv;
298+
299+
#[test]
300+
fn traits() {
301+
assert_send::<Client<srv::Arrays>>();
302+
assert_sync::<Client<srv::Arrays>>();
303+
}
304+
305+
#[test]
306+
fn test_clients() -> Result<(), RclrsError> {
307+
let namespace = "/test_clients_graph";
308+
let graph = construct_test_graph(namespace)?;
309+
let _node_2_empty_client = graph
310+
.node2
311+
.create_client::<srv::Empty>("graph_test_topic_4")?;
312+
313+
std::thread::sleep(std::time::Duration::from_millis(200));
314+
315+
let client_names_and_types = graph
316+
.node2
317+
.get_client_names_and_types_by_node(&graph.node2.name(), &graph.node2.namespace())?;
318+
let types = client_names_and_types
319+
.get("/test_clients_graph/graph_test_topic_4")
320+
.unwrap();
321+
322+
assert!(types.contains(&"test_msgs/srv/Empty".to_string()));
323+
324+
Ok(())
325+
}
326+
}

rclrs/src/clock.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,10 @@ unsafe impl Send for rcl_clock_t {}
195195
mod tests {
196196
use super::*;
197197

198-
fn assert_send<T: Send>() {}
199-
fn assert_sync<T: Sync>() {}
200-
201198
#[test]
202-
fn clock_is_send_and_sync() {
199+
fn traits() {
200+
use crate::test_helpers::*;
201+
203202
assert_send::<Clock>();
204203
assert_sync::<Clock>();
205204
}

rclrs/src/context.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,10 @@ impl Context {
120120
mod tests {
121121
use super::*;
122122

123-
fn assert_send<T: Send>() {}
124-
fn assert_sync<T: Sync>() {}
125-
126123
#[test]
127-
fn context_is_send_and_sync() {
124+
fn traits() {
125+
use crate::test_helpers::*;
126+
128127
assert_send::<Context>();
129128
assert_sync::<Context>();
130129
}

rclrs/src/dynamic_message.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,11 +253,10 @@ impl DynamicMessageMetadata {
253253
mod tests {
254254
use super::*;
255255

256-
fn assert_send<T: Send>() {}
257-
fn assert_sync<T: Sync>() {}
258-
259256
#[test]
260-
fn all_types_are_sync_and_send() {
257+
fn traits() {
258+
use crate::test_helpers::*;
259+
261260
assert_send::<DynamicMessageMetadata>();
262261
assert_sync::<DynamicMessageMetadata>();
263262
}

rclrs/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ mod time_source;
2222
mod vendor;
2323
mod wait;
2424

25+
#[cfg(test)]
26+
mod test_helpers;
27+
2528
mod rcl_bindings;
2629

2730
#[cfg(feature = "dyn_msg")]

rclrs/src/node.rs

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -454,13 +454,56 @@ pub(crate) unsafe fn call_string_getter_with_handle(
454454
#[cfg(test)]
455455
mod tests {
456456
use super::*;
457-
458-
fn assert_send<T: Send>() {}
459-
fn assert_sync<T: Sync>() {}
457+
use crate::test_helpers::*;
460458

461459
#[test]
462-
fn node_is_send_and_sync() {
460+
fn traits() {
463461
assert_send::<Node>();
464462
assert_sync::<Node>();
465463
}
464+
465+
#[test]
466+
fn test_topic_names_and_types() -> Result<(), RclrsError> {
467+
use crate::QOS_PROFILE_SYSTEM_DEFAULT;
468+
use test_msgs::msg;
469+
470+
let graph = construct_test_graph("test_topics_graph")?;
471+
472+
let _node_1_defaults_subscription = graph.node1.create_subscription::<msg::Defaults, _>(
473+
"graph_test_topic_3",
474+
QOS_PROFILE_SYSTEM_DEFAULT,
475+
|_msg: msg::Defaults| {},
476+
)?;
477+
let _node_2_empty_subscription = graph.node2.create_subscription::<msg::Empty, _>(
478+
"graph_test_topic_1",
479+
QOS_PROFILE_SYSTEM_DEFAULT,
480+
|_msg: msg::Empty| {},
481+
)?;
482+
let _node_2_basic_types_subscription =
483+
graph.node2.create_subscription::<msg::BasicTypes, _>(
484+
"graph_test_topic_2",
485+
QOS_PROFILE_SYSTEM_DEFAULT,
486+
|_msg: msg::BasicTypes| {},
487+
)?;
488+
489+
std::thread::sleep(std::time::Duration::from_millis(100));
490+
491+
let topic_names_and_types = graph.node1.get_topic_names_and_types()?;
492+
493+
let types = topic_names_and_types
494+
.get("/test_topics_graph/graph_test_topic_1")
495+
.unwrap();
496+
assert!(types.contains(&"test_msgs/msg/Empty".to_string()));
497+
let types = topic_names_and_types
498+
.get("/test_topics_graph/graph_test_topic_2")
499+
.unwrap();
500+
assert!(types.contains(&"test_msgs/msg/BasicTypes".to_string()));
501+
502+
let types = topic_names_and_types
503+
.get("/test_topics_graph/graph_test_topic_3")
504+
.unwrap();
505+
assert!(types.contains(&"test_msgs/msg/Defaults".to_string()));
506+
507+
Ok(())
508+
}
466509
}

rclrs/src/node/graph.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,6 @@ fn convert_names_and_types(
457457

458458
#[cfg(test)]
459459
mod tests {
460-
461460
use super::*;
462461
use crate::Context;
463462

rclrs/src/publisher.rs

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,3 +230,81 @@ impl<'a, T: Message> MessageCow<'a, T> for &'a T {
230230
Cow::Borrowed(self)
231231
}
232232
}
233+
234+
#[cfg(test)]
235+
mod tests {
236+
use super::*;
237+
use crate::test_helpers::*;
238+
239+
#[test]
240+
fn traits() {
241+
assert_send::<Publisher<test_msgs::msg::BoundedSequences>>();
242+
assert_sync::<Publisher<test_msgs::msg::BoundedSequences>>();
243+
}
244+
245+
#[test]
246+
fn test_publishers() -> Result<(), RclrsError> {
247+
use crate::TopicEndpointInfo;
248+
use crate::QOS_PROFILE_SYSTEM_DEFAULT;
249+
use test_msgs::msg;
250+
251+
let namespace = "/test_publishers_graph";
252+
let graph = construct_test_graph(namespace)?;
253+
254+
let node_1_empty_publisher = graph
255+
.node1
256+
.create_publisher::<msg::Empty>("graph_test_topic_1", QOS_PROFILE_SYSTEM_DEFAULT)?;
257+
let topic1 = node_1_empty_publisher.topic_name();
258+
let node_1_basic_types_publisher = graph.node1.create_publisher::<msg::BasicTypes>(
259+
"graph_test_topic_2",
260+
QOS_PROFILE_SYSTEM_DEFAULT,
261+
)?;
262+
let topic2 = node_1_basic_types_publisher.topic_name();
263+
let node_2_default_publisher = graph
264+
.node2
265+
.create_publisher::<msg::Defaults>("graph_test_topic_3", QOS_PROFILE_SYSTEM_DEFAULT)?;
266+
let topic3 = node_2_default_publisher.topic_name();
267+
268+
std::thread::sleep(std::time::Duration::from_millis(100));
269+
270+
// Test count_publishers()
271+
assert_eq!(graph.node1.count_publishers(&topic1)?, 1);
272+
assert_eq!(graph.node1.count_publishers(&topic2)?, 1);
273+
assert_eq!(graph.node1.count_publishers(&topic3)?, 1);
274+
275+
// Test get_publisher_names_and_types_by_node()
276+
let node_1_publisher_names_and_types = graph
277+
.node1
278+
.get_publisher_names_and_types_by_node(&graph.node1.name(), namespace)?;
279+
280+
let types = node_1_publisher_names_and_types.get(&topic1).unwrap();
281+
assert!(types.contains(&"test_msgs/msg/Empty".to_string()));
282+
283+
let types = node_1_publisher_names_and_types.get(&topic2).unwrap();
284+
assert!(types.contains(&"test_msgs/msg/BasicTypes".to_string()));
285+
286+
let node_2_publisher_names_and_types = graph
287+
.node1
288+
.get_publisher_names_and_types_by_node(&graph.node2.name(), namespace)?;
289+
290+
let types = node_2_publisher_names_and_types.get(&topic3).unwrap();
291+
assert!(types.contains(&"test_msgs/msg/Defaults".to_string()));
292+
293+
// Test get_publishers_info_by_topic()
294+
let expected_publishers_info = vec![TopicEndpointInfo {
295+
node_name: String::from("graph_test_node_1"),
296+
node_namespace: String::from(namespace),
297+
topic_type: String::from("test_msgs/msg/Empty"),
298+
}];
299+
assert_eq!(
300+
graph.node1.get_publishers_info_by_topic(&topic1)?,
301+
expected_publishers_info
302+
);
303+
assert_eq!(
304+
graph.node2.get_publishers_info_by_topic(&topic1)?,
305+
expected_publishers_info
306+
);
307+
308+
Ok(())
309+
}
310+
}

0 commit comments

Comments
 (0)