-
-
Notifications
You must be signed in to change notification settings - Fork 459
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
373 additions
and
55 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
27 changes: 27 additions & 0 deletions
27
Assets/MediaPipe/SDK/Scripts/PInvoke/NativeMethods/Framework/CalculatorGraph_Safe.cs
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,27 @@ | ||
using System; | ||
using System.Diagnostics.Contracts; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Mediapipe { | ||
internal static partial class SafeNativeMethods { | ||
[Pure, DllImport (MediaPipeLibrary, ExactSpelling = true)] | ||
[return: MarshalAs(UnmanagedType.I1)] | ||
public static extern bool mp_CalculatorGraph__HasError(IntPtr graph); | ||
|
||
[Pure, DllImport (MediaPipeLibrary, ExactSpelling = true)] | ||
[return: MarshalAs(UnmanagedType.I1)] | ||
public static extern bool mp_CalculatorGraph__HasInputStream__PKc(IntPtr graph, string name); | ||
|
||
[Pure, DllImport (MediaPipeLibrary, ExactSpelling = true)] | ||
[return: MarshalAs(UnmanagedType.I1)] | ||
public static extern bool mp_CalculatorGraph__GraphInputStreamsClosed(IntPtr graph); | ||
|
||
[Pure, DllImport (MediaPipeLibrary, ExactSpelling = true)] | ||
[return: MarshalAs(UnmanagedType.I1)] | ||
public static extern bool mp_CalculatorGraph__IsNodeThrottled__i(IntPtr graph, int nodeId); | ||
|
||
[Pure, DllImport (MediaPipeLibrary, ExactSpelling = true)] | ||
[return: MarshalAs(UnmanagedType.I1)] | ||
public static extern bool mp_CalculatorGraph__UnthrottleSources(IntPtr graph); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/MediaPipe/SDK/Scripts/PInvoke/NativeMethods/Framework/CalculatorGraph_Safe.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
1 change: 0 additions & 1 deletion
1
Assets/MediaPipe/SDK/Tests/Framework/CalculatorGraphConfigTest.cs
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
121 changes: 121 additions & 0 deletions
121
Assets/MediaPipe/SDK/Tests/Framework/CalculatorGraphTest.cs
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,121 @@ | ||
using Mediapipe; | ||
using NUnit.Framework; | ||
|
||
namespace Tests { | ||
public class CalculatorGraphTest { | ||
private static string validConfigText = @"node { | ||
calculator: ""PassThroughCalculator"" | ||
input_stream: ""in"" | ||
output_stream: ""out1"" | ||
} | ||
node { | ||
calculator: ""PassThroughCalculator"" | ||
input_stream: ""out1"" | ||
output_stream: ""out"" | ||
} | ||
input_stream: ""in"" | ||
output_stream: ""out"" | ||
"; | ||
|
||
#region Constructor | ||
[Test] | ||
public void Ctor_ShouldInstantiateCalculatorGraph_When_CalledWithNoArguments() { | ||
Assert.DoesNotThrow(() => { new CalculatorGraph(); }); | ||
} | ||
|
||
[Test] | ||
public void Ctor_ShouldInstantiateCalculatorGraph_When_CalledWithConfigText() { | ||
var graph = new CalculatorGraph(validConfigText); | ||
var config = graph.config; | ||
|
||
Assert.Greater(config.byteSizeLong, 0); | ||
} | ||
#endregion | ||
|
||
#region #isDisposed | ||
[Test] | ||
public void isDisposed_ShouldReturnFalse_When_NotDisposedYet() { | ||
var graph = new CalculatorGraph(); | ||
|
||
Assert.False(graph.isDisposed); | ||
} | ||
|
||
[Test] | ||
public void isDisposed_ShouldReturnTrue_When_AlreadyDisposed() { | ||
var graph = new CalculatorGraph(); | ||
graph.Dispose(); | ||
|
||
Assert.True(graph.isDisposed); | ||
} | ||
#endregion | ||
|
||
#region #Initialize | ||
[Test] | ||
public void Initialize_ShouldReturnOk_When_CalledWithConfig_And_ConfigIsNotSet() { | ||
var graph = new CalculatorGraph(); | ||
var config = CalculatorGraphConfig.ParseFromString(validConfigText); | ||
var status = graph.Initialize(config); | ||
|
||
Assert.True(status.ok); | ||
Assert.Greater(graph.config.byteSizeLong, 0); | ||
} | ||
|
||
[Test] | ||
public void Initialize_ShouldReturnInternalError_When_CalledWithConfig_And_ConfigIsSet() { | ||
var graph = new CalculatorGraph(validConfigText); | ||
var config = CalculatorGraphConfig.ParseFromString(validConfigText); | ||
var status = graph.Initialize(config); | ||
|
||
Assert.AreEqual(status.code, Status.StatusCode.Internal); | ||
} | ||
|
||
[Test] | ||
public void Initialize_ShouldReturnOk_When_CalledWithConfigAndSidePacket_And_ConfigIsNotSet() { | ||
var graph = new CalculatorGraph(); | ||
var config = CalculatorGraphConfig.ParseFromString(validConfigText); | ||
var sidePacket = new SidePacket(); | ||
sidePacket.Emplace("flag", new BoolPacket(true)); | ||
var status = graph.Initialize(config, sidePacket); | ||
|
||
Assert.True(status.ok); | ||
} | ||
|
||
|
||
[Test] | ||
public void Initialize_ShouldReturnInternalError_When_CalledWithConfigAndSidePacket_And_ConfigIsSet() { | ||
var graph = new CalculatorGraph(validConfigText); | ||
var config = CalculatorGraphConfig.ParseFromString(validConfigText); | ||
var sidePacket = new SidePacket(); | ||
sidePacket.Emplace("flag", new BoolPacket(true)); | ||
var status = graph.Initialize(config, sidePacket); | ||
|
||
Assert.AreEqual(status.code, Status.StatusCode.Internal); | ||
} | ||
#endregion | ||
|
||
#region lifecycle | ||
[Test] | ||
public void LifecycleMethods_ShouldControlGraphLifeCycle() { | ||
var graph = new CalculatorGraph(validConfigText); | ||
|
||
Assert.True(graph.StartRun().ok); | ||
Assert.False(graph.GraphInputStreamsClosed()); | ||
|
||
Assert.True(graph.WaitUntilIdle().ok); | ||
Assert.True(graph.CloseAllPacketSources().ok); | ||
Assert.True(graph.GraphInputStreamsClosed()); | ||
Assert.True(graph.WaitUntilDone().ok); | ||
Assert.False(graph.HasError()); | ||
} | ||
|
||
[Test] | ||
public void Cancel_ShouldCancelGraph() { | ||
var graph = new CalculatorGraph(validConfigText); | ||
|
||
Assert.True(graph.StartRun().ok); | ||
graph.Cancel(); | ||
Assert.AreEqual(graph.WaitUntilDone().code, Status.StatusCode.Cancelled); | ||
} | ||
#endregion | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/MediaPipe/SDK/Tests/Framework/CalculatorGraphTest.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
Assets/MediaPipe/SDK/Tests/Framework/Packet/ImageFramePacketTest.cs
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 |
---|---|---|
@@ -1,6 +1,5 @@ | ||
using Mediapipe; | ||
using NUnit.Framework; | ||
using System; | ||
|
||
namespace Tests { | ||
public class ImageFramePacketTest { | ||
|
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 |
---|---|---|
@@ -1,6 +1,5 @@ | ||
using Mediapipe; | ||
using NUnit.Framework; | ||
using System; | ||
|
||
namespace Tests { | ||
public class SidePacketTest { | ||
|
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
Oops, something went wrong.