Skip to content

Commit 4941247

Browse files
committed
add process err tests
1 parent 301227b commit 4941247

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

binding/ios/CobraAppTest/CobraAppTestUITests/CobraAppTestUITests.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,20 @@ class CobraAppTestUITests: XCTestCase {
7272
XCTAssert("\(error.localizedDescription)".count == first_error.count)
7373
}
7474
}
75+
76+
77+
func testProcessMessageStack() throws {
78+
let cobra: Cobra = try Cobra(accessKey: accessKey)
79+
cobra.delete()
80+
81+
var testPcm: [Int16] = []
82+
testPcm.reserveCapacity(Int(Cobra.frameLength))
83+
84+
do {
85+
let res = try cobra.process(pcm: testPcm)
86+
XCTAssert(res != true)
87+
} catch {
88+
XCTAssert("\(error.localizedDescription)".count > 0)
89+
}
90+
}
7591
}

binding/python/test_cobra.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,24 @@ def test_message_stack(self):
6767
self.assertEqual(len(error), len(e.message_stack))
6868
self.assertListEqual(list(error), list(e.message_stack))
6969

70+
def test_process_message_stack(self):
71+
relative_path = '../..'
72+
73+
c = Cobra(access_key=sys.argv[1], library_path=pv_library_path(relative_path))
74+
test_pcm = [0] * c.frame_length
75+
76+
address = c._handle
77+
c._handle = None
78+
79+
try:
80+
res = c.process(test_pcm)
81+
self.assertTrue(res == -1)
82+
except CobraError as e:
83+
self.assertGreater(len(e.message_stack), 0)
84+
self.assertLess(len(e.message_stack), 8)
85+
86+
c._handle = address
87+
7088

7189
if __name__ == '__main__':
7290
if len(sys.argv) != 2:

binding/rust/src/cobra.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,3 +363,36 @@ impl Drop for CobraInner {
363363
}
364364
}
365365
}
366+
367+
#[cfg(test)]
368+
mod tests {
369+
use std::env;
370+
371+
use crate::util::{pv_library_path};
372+
use crate::cobra::{CobraInner};
373+
374+
#[test]
375+
fn test_process_error_stack() {
376+
let access_key = env::var("PV_ACCESS_KEY")
377+
.expect("Pass the AccessKey in using the PV_ACCESS_KEY env variable");
378+
379+
let mut inner = CobraInner::init(
380+
&access_key.as_str(),
381+
pv_library_path()
382+
).expect("Unable to create Cobra");
383+
384+
let test_pcm = vec![0; inner.frame_length as usize];
385+
let address = inner.ccobra;
386+
inner.ccobra = std::ptr::null_mut();
387+
388+
let res = inner.process(&test_pcm);
389+
390+
inner.ccobra = address;
391+
if let Err(err) = res {
392+
assert!(err.message_stack.len() > 0);
393+
assert!(err.message_stack.len() < 8);
394+
} else {
395+
assert!(res.unwrap() == true);
396+
}
397+
}
398+
}

0 commit comments

Comments
 (0)