Skip to content

Commit

Permalink
v3.0 tests (#634)
Browse files Browse the repository at this point in the history
  • Loading branch information
ksyeo1010 authored Nov 2, 2023
1 parent c2c1360 commit 6bbd1e8
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 3 deletions.
28 changes: 28 additions & 0 deletions binding/dotnet/RhinoTest/MainTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,34 @@ public void TestMessageStack()
}
}

[TestMethod]
public void TestProcessMessageStack()
{
Rhino r = Rhino.Create(
_accessKey,
GetContextPath("en", "smart_lighting"),
GetModelPath("en"));
short[] testPcm = new short[r.FrameLength];

var obj = typeof(Rhino).GetField("_libraryPointer", BindingFlags.NonPublic | BindingFlags.Instance);
IntPtr address = (IntPtr)obj.GetValue(r);
obj.SetValue(r, IntPtr.Zero);

try
{
bool res = r.Process(testPcm);
Assert.IsTrue(res);
}
catch (RhinoException e)
{
Assert.IsTrue(0 < e.MessageStack.Length);
Assert.IsTrue(e.MessageStack.Length < 8);
}

obj.SetValue(r, address);
r.Dispose();
}

[TestMethod]
[DynamicData(nameof(WithinContextTestData))]
public void TestWithinContext(
Expand Down
25 changes: 25 additions & 0 deletions binding/go/rhino_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,28 @@ func TestMessageStack(t *testing.T) {
t.Fatalf("length of 1st init '%d' does not match 2nd init '%d'", len(err.Error()), len(err2.Error()))
}
}

func TestProcessMessageStack(t *testing.T) {
rhino := NewRhino(testAccessKey, getTestContextPath("en", "smart_lighting"))

err := rhino.Init()
if err != nil {
t.Fatalf("%v", err)
}

address := rhino.handle
rhino.handle = nil

testPcm := make([]int16, FrameLength)

_, err = rhino.Process(testPcm)
rhino.handle = address
if err == nil {
t.Fatalf("Expected rhino process to fail")
}

delErr := rhino.Delete()
if delErr != nil {
t.Fatalf("%v", delErr)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -331,4 +331,25 @@ class RhinoAppTestUITests: BaseTest {
XCTAssert("\(error.localizedDescription)".count == first_error.count)
}
}

func testProcessMessageStack() throws {
let bundle = Bundle(for: type(of: self))
let contextPath = bundle.path(
forResource: "coffee_maker_ios",
ofType: "rhn",
inDirectory: "test_resources/context_files/en")!

let r = try Rhino.init(accessKey: accessKey, contextPath: contextPath)
r.delete()

var testPcm: [Int16] = []
testPcm.reserveCapacity(Int(Rhino.frameLength))

do {
let res = try r.process(pcm: testPcm)
XCTAssert(res != true)
} catch {
XCTAssert("\(error.localizedDescription)".count > 0)
}
}
}
22 changes: 22 additions & 0 deletions binding/python/test_rhino.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,28 @@ def test_message_stack(self):
self.assertEqual(len(error), len(e.message_stack))
self.assertListEqual(list(error), list(e.message_stack))

def test_process_message_stack(self):
relative_path = '../..'

r = Rhino(
access_key=sys.argv[1],
library_path=pv_library_path(relative_path),
model_path=get_model_path_by_language(relative_path, 'en'),
context_path=get_context_path_by_language(relative_path, 'smart_lighting', 'en'))
test_pcm = [0] * r.frame_length

address = r._handle
r._handle = None

try:
res = r.process(test_pcm)
self.assertTrue(res)
except RhinoError as e:
self.assertGreater(len(e.message_stack), 0)
self.assertLess(len(e.message_stack), 8)

r._handle = address


if __name__ == '__main__':
if len(sys.argv) != 2:
Expand Down
48 changes: 48 additions & 0 deletions binding/rust/src/rhino.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,3 +617,51 @@ impl Drop for RhinoInner {
}
}
}

#[cfg(test)]
mod tests {
use std::env;

use crate::util::{pv_library_path, pv_model_path, pv_platform};
use crate::rhino::{RhinoInner};

#[test]
fn test_process_error_stack() {
let access_key = env::var("PV_ACCESS_KEY")
.expect("Pass the AccessKey in using the PV_ACCESS_KEY env variable");

let context_path = format!(
"{}{}/{}/{}_{}.rhn",
env!("CARGO_MANIFEST_DIR"),
"/../../resources/contexts",
pv_platform(),
"smart_lighting",
pv_platform()
);

let mut inner = RhinoInner::init(
&access_key.as_str(),
pv_library_path(),
pv_model_path(),
context_path.into(),
0.5,
1.0,
false
).expect("Unable to create Rhino");

let test_pcm = vec![0; inner.frame_length as usize];
let address = inner.crhino;
inner.crhino = std::ptr::null_mut();

let res = inner.process(&test_pcm);

inner.crhino = address;
if let Err(err) = res {
assert!(err.message_stack.len() > 0);
assert!(err.message_stack.len() < 8);
} else {
assert!(res.unwrap() == true);
}
}
}

2 changes: 1 addition & 1 deletion binding/unity/Assets/Rhino/RhinoException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public RhinoException(string message, string[] messageStack) : base(ModifyMessag
this._messageStack = messageStack;
}

public string[] messageStack
public string[] MessageStack
{
get => _messageStack;
}
Expand Down
33 changes: 31 additions & 2 deletions binding/unity/Assets/Rhino/Tests/Integration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public void TestMessageStack()
}
catch (RhinoException e)
{
messageList = e.messageStack;
messageList = e.MessageStack;
}

Assert.IsTrue(0 < messageList.Length);
Expand All @@ -287,11 +287,40 @@ public void TestMessageStack()
{
for (int i = 0; i < messageList.Length; i++)
{
Assert.AreEqual(messageList[i], e.messageStack[i]);
Assert.AreEqual(messageList[i], e.MessageStack[i]);
}
}
}


[Test]
public void TestProcessMessageStack()
{
Rhino r = Rhino.Create(
ACCESS_KEY,
GetContextPath("en", "smart_lighting"));

short[] testPcm = new short[r.FrameLength];

var obj = typeof(Rhino).GetField("_libraryPointer", BindingFlags.NonPublic | BindingFlags.Instance);
IntPtr address = (IntPtr)obj.GetValue(r);
obj.SetValue(r, IntPtr.Zero);

try
{
bool res = r.Process(testPcm);
Assert.IsTrue(res);
}
catch (RhinoException e)
{
Assert.IsTrue(0 < e.MessageStack.Length);
Assert.IsTrue(e.MessageStack.Length < 8);
}

obj.SetValue(r, address);
r.Dispose();
}

[Test]
public void TestReset()
{
Expand Down
Binary file modified binding/unity/rhino-3.0.0.unitypackage
Binary file not shown.

0 comments on commit 6bbd1e8

Please sign in to comment.