Skip to content

Commit

Permalink
Add exception handling test (currently failing).
Browse files Browse the repository at this point in the history
  • Loading branch information
kring committed Jan 24, 2025
1 parent 917f468 commit bb850dc
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Runtime/ConfigureReinterop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,8 @@ Cesium3DTilesetLoadFailureDetails tilesetDetails

EditorUtility.SetDirty(null);
#endif

TestReinterop.ThrowAnException();
}
}
}
18 changes: 18 additions & 0 deletions Runtime/TestReinterop.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Reinterop;

namespace CesiumForUnity
{
/// <summary>
/// Internal helpers for testing Reinterop functionality.
/// </summary>
[ReinteropNativeImplementation("CesiumForUnityNative::TestReinteropImpl", "TestReinteropImpl.h", true)]
internal partial class TestReinterop
{
public partial bool CallThrowAnExceptionFromCpp();

public static void ThrowAnException()
{
throw new System.Exception("Test Exception!");
}
}
}
11 changes: 11 additions & 0 deletions Runtime/TestReinterop.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions Tests/TestReinterop.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using NUnit.Framework;

public class TestReinterop
{
[Test]
public void TestADotNetExceptionCanBeCaughtInCpp()
{
CesiumForUnity.TestReinterop o = new CesiumForUnity.TestReinterop();
Assert.IsTrue(o.CallThrowAnExceptionFromCpp());
}
}
11 changes: 11 additions & 0 deletions Tests/TestReinterop.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions native~/Runtime/src/TestReinteropImpl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "TestReinteropImpl.h"

#include <DotNet/CesiumForUnity/TestReinterop.h>

namespace CesiumForUnityNative {

bool TestReinteropImpl::CallThrowAnExceptionFromCpp(
const DotNet::CesiumForUnity::TestReinterop& instance) {
try {
instance.ThrowAnException();
} catch (...) {
return true;
}

return false;
}

} // namespace CesiumForUnityNative
17 changes: 17 additions & 0 deletions native~/Runtime/src/TestReinteropImpl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

#include <CesiumImpl.h>

namespace DotNet::CesiumForUnity {
class TestReinterop;
}

namespace CesiumForUnityNative {

class TestReinteropImpl {
public:
static bool CallThrowAnExceptionFromCpp(
const DotNet::CesiumForUnity::TestReinterop& instance);
};

} // namespace CesiumForUnityNative

0 comments on commit bb850dc

Please sign in to comment.