-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
iox-#5 Add RuDiEnvironment for testing
- Loading branch information
1 parent
d0813f9
commit e8078f5
Showing
6 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
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,8 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: © Contributors to the iceoryx-rs project | ||
// SPDX-FileContributor: Mathias Kraus | ||
|
||
mod roudi_environment_ffi; | ||
|
||
// re-exports | ||
pub (crate) use roudi_environment_ffi::RouDiEnvironment; |
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,25 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: © Contributors to the iceoryx-rs project | ||
// SPDX-FileContributor: Mathias Kraus | ||
|
||
cpp! {{ | ||
#include "iceoryx_posh/testing/roudi_environment/roudi_environment.hpp" | ||
|
||
using iox::roudi::RouDiEnvironment; | ||
}} | ||
|
||
cpp_class!(pub unsafe struct RouDiEnvironment as "RouDiEnvironment"); | ||
|
||
impl RouDiEnvironment { | ||
pub(crate) fn new( | ||
) -> Box<Self> { | ||
unsafe { | ||
let raw = cpp!([] -> *mut RouDiEnvironment as "RouDiEnvironment*" | ||
{ | ||
return new RouDiEnvironment(); | ||
}); | ||
|
||
Box::from_raw(raw) | ||
} | ||
} | ||
} |
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,45 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: © Contributors to the iceoryx-rs project | ||
// SPDX-FileContributor: Mathias Kraus | ||
|
||
use crate::pb::{self, POD}; | ||
use crate::sb; | ||
use crate::Runtime; | ||
use crate::testing::RouDiEnvironment; | ||
|
||
#[repr(C)] | ||
struct CounterTopic { | ||
counter: u32, | ||
} | ||
|
||
unsafe impl POD for CounterTopic {} | ||
|
||
#[test] | ||
fn basic_pub_sub() { | ||
let _roudi = RouDiEnvironment::new(); | ||
|
||
Runtime::init("publisher_simple"); | ||
|
||
let topic = sb::TopicBuilder::<CounterTopic>::new("Radar", "FrontLeft", "Counter") | ||
.queue_capacity(5) | ||
.build(); | ||
|
||
let (subscriber, sample_receive_token) = topic.subscribe(); | ||
|
||
let topic = pb::TopicBuilder::<CounterTopic>::new("Radar", "FrontLeft", "Counter").build().expect("Topic");//?; | ||
|
||
let publisher = topic.offer(); | ||
let mut sample = publisher.allocate_sample().expect("Samle");//?; | ||
sample.counter = 42; | ||
publisher.publish(sample); | ||
|
||
println!("Sending: {}", 42); | ||
|
||
let sample_receiver = subscriber.get_sample_receiver(sample_receive_token); | ||
|
||
if sample_receiver.has_samples() { | ||
while let Some(sample) = sample_receiver.get_sample() { | ||
println!("Receiving: {}", sample.counter); | ||
} | ||
} | ||
} |
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,6 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: © Contributors to the iceoryx-rs project | ||
// SPDX-FileContributor: Mathias Kraus | ||
|
||
// minimal setup with one publisher and one subscriber exchanging data | ||
mod basic_pub_sub; |