-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.rs
120 lines (107 loc) · 4.04 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
//! A simple app that uses a VAPIX service account to access VAPIX APIs.
use std::time::Duration;
use acap_vapix::systemready;
use log::{debug, info};
use tokio::time;
#[tokio::main(flavor = "current_thread")]
async fn main() {
acap_logging::init_logger();
let client = acap_vapix::local_client().unwrap();
loop {
debug!("Checking if system is ready");
let data = systemready::systemready().execute(&client).await.unwrap();
if data.system_ready() {
if let Some(uptime) = data.uptime() {
info!("System is ready after being up for {uptime:?}");
} else {
info!("System is ready");
}
break;
} else {
debug!("System is not ready, checking soon.");
time::sleep(Duration::from_secs(1)).await;
}
}
}
#[cfg(not(target_arch = "x86_64"))]
#[cfg(test)]
mod tests {
use acap_vapix::{
applications_control, basic_device_info, parameter_management, systemready, ws_data_stream,
ws_data_stream::{ContentFilter, TopicFilter},
};
#[tokio::test]
async fn smoke_test_applications_control() {
let client = acap_vapix::local_client().unwrap();
let e = applications_control::control(applications_control::Action::Start, "foo")
.execute(&client)
.await
.unwrap_err();
let e = e.downcast::<applications_control::Error>().unwrap();
let applications_control::Error::NotFound = e else {
panic!("{e:?}")
};
}
#[tokio::test]
async fn smoke_test_basic_device_info() {
let mut client = acap_vapix::local_client().unwrap();
let properties = basic_device_info::Client::new(&client)
.get_all_properties()
.send()
.await
.unwrap();
assert_eq!(properties.property_list.unrestricted.brand, "AXIS");
let properties = basic_device_info::Client::new(&client)
.get_properties(&["Brand"])
.send()
.await
.unwrap();
assert_eq!(properties.property_list.get("Brand").unwrap(), "AXIS");
client = client.anonymous_auth();
let properties = basic_device_info::Client::new(&client)
.get_all_unrestricted_properties()
.send()
.await
.unwrap();
assert_eq!(properties.property_list.brand, "AXIS");
}
#[tokio::test]
async fn smoke_test_parameter_management() {
let client = acap_vapix::local_client().unwrap();
// It is not guaranteed that this parameter will always exist with this value, but it seems
// like it should be stable enough to be useful as a test.
let params = parameter_management::list()
.group("root.Brand.Brand")
.execute(&client)
.await
.unwrap();
assert_eq!(params.get("root.Brand.Brand").unwrap(), "AXIS")
}
#[tokio::test]
async fn smoke_test_systemready() {
let client = acap_vapix::local_client().unwrap();
let data = systemready::systemready().execute(&client).await.unwrap();
// TODO: Remove once parsed eagerly
let _ = data.preview_mode();
let _ = data.uptime();
}
#[tokio::test]
async fn smoke_test_ws_data_stream() {
let client = acap_vapix::local_client().unwrap();
// It is not guaranteed that this event will always exist, but it seems like likely enough
// to be useful as a test.
let mut stream = ws_data_stream::events_configure()
.event_filter((
ContentFilter::unvalidated(
r##"boolean(//SimpleItem[@Name="port" and @Value="1"])"##,
),
TopicFilter::unvalidated("tns1:Device/tnsaxis:IO/VirtualInput"),
))
.execute(&client)
.await
.unwrap();
let mut notification = stream.try_next().await.unwrap();
let port = notification.message.source.remove("port").unwrap();
assert_eq!(port, "1");
}
}