-
-
Notifications
You must be signed in to change notification settings - Fork 483
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: initialize RectPacket from proto (#970)
* feat: initialize RectPacket from proto * implement RectPacket.ValidateAsType * test: add RectPacket tests
- Loading branch information
Showing
11 changed files
with
440 additions
and
22 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
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
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
44 changes: 44 additions & 0 deletions
44
...b.homuler.mediapipe/Runtime/Scripts/PInvoke/NativeMethods/Framework/Format/Rect_Unsafe.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,44 @@ | ||
// Copyright (c) 2021 homuler | ||
// | ||
// Use of this source code is governed by an MIT-style | ||
// license that can be found in the LICENSE file or at | ||
// https://opensource.org/licenses/MIT. | ||
|
||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Mediapipe | ||
{ | ||
internal static partial class UnsafeNativeMethods | ||
{ | ||
[DllImport(MediaPipeLibrary, ExactSpelling = true)] | ||
public static extern MpReturnCode mp__MakeRectPacket__PKc_i(byte[] serializedData, int size, out IntPtr packet_out); | ||
|
||
[DllImport(MediaPipeLibrary, ExactSpelling = true)] | ||
public static extern MpReturnCode mp__MakeRectPacket_At__PKc_i_Rt(byte[] serializedData, int size, IntPtr timestamp, out IntPtr packet_out); | ||
|
||
[DllImport(MediaPipeLibrary, ExactSpelling = true)] | ||
public static extern MpReturnCode mp_Packet__GetRect(IntPtr packet, out SerializedProto serializedProto); | ||
|
||
[DllImport(MediaPipeLibrary, ExactSpelling = true)] | ||
public static extern MpReturnCode mp_Packet__GetRectVector(IntPtr packet, out SerializedProtoVector serializedProtoVector); | ||
|
||
[DllImport(MediaPipeLibrary, ExactSpelling = true)] | ||
public static extern MpReturnCode mp_Packet__ValidateAsRect(IntPtr packet, out IntPtr status); | ||
|
||
[DllImport(MediaPipeLibrary, ExactSpelling = true)] | ||
public static extern MpReturnCode mp__MakeNormalizedRectPacket__PKc_i(byte[] serializedData, int size, out IntPtr packet_out); | ||
|
||
[DllImport(MediaPipeLibrary, ExactSpelling = true)] | ||
public static extern MpReturnCode mp__MakeNormalizedRectPacket_At__PKc_i_Rt(byte[] serializedData, int size, IntPtr timestamp, out IntPtr packet_out); | ||
|
||
[DllImport(MediaPipeLibrary, ExactSpelling = true)] | ||
public static extern MpReturnCode mp_Packet__GetNormalizedRect(IntPtr packet, out SerializedProto serializedProto); | ||
|
||
[DllImport(MediaPipeLibrary, ExactSpelling = true)] | ||
public static extern MpReturnCode mp_Packet__GetNormalizedRectVector(IntPtr packet, out SerializedProtoVector serializedProtoVector); | ||
|
||
[DllImport(MediaPipeLibrary, ExactSpelling = true)] | ||
public static extern MpReturnCode mp_Packet__ValidateAsNormalizedRect(IntPtr packet, out IntPtr status); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...uler.mediapipe/Runtime/Scripts/PInvoke/NativeMethods/Framework/Format/Rect_Unsafe.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
131 changes: 131 additions & 0 deletions
131
.../com.github.homuler.mediapipe/Tests/EditMode/Framework/Packet/NormalizedRectPacketTest.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,131 @@ | ||
// Copyright (c) 2021 homuler | ||
// | ||
// Use of this source code is governed by an MIT-style | ||
// license that can be found in the LICENSE file or at | ||
// https://opensource.org/licenses/MIT. | ||
|
||
using NUnit.Framework; | ||
using System; | ||
|
||
namespace Mediapipe.Tests | ||
{ | ||
public class NormalizedRectPacketTest | ||
{ | ||
#region Constructor | ||
[Test, SignalAbort] | ||
public void Ctor_ShouldInstantiatePacket_When_CalledWithNoArguments() | ||
{ | ||
using (var packet = new NormalizedRectPacket()) | ||
{ | ||
var exception = Assert.Throws<BadStatusException>(packet.ValidateAsType); | ||
Assert.AreEqual(StatusCode.Internal, exception.statusCode); | ||
_ = Assert.Throws<MediaPipeException>(() => { _ = packet.Get(); }); | ||
Assert.AreEqual(Timestamp.Unset(), packet.Timestamp()); | ||
} | ||
|
||
} | ||
|
||
[Test] | ||
public void Ctor_ShouldInstantiatePacket_When_CalledWithRect() | ||
{ | ||
var rect = new NormalizedRect() { XCenter = 0, YCenter = 0, Width = 0.1f, Height = 0.2f }; | ||
using (var packet = new NormalizedRectPacket(rect)) | ||
{ | ||
Assert.DoesNotThrow(packet.ValidateAsType); | ||
var value = packet.Get(); | ||
Assert.AreEqual(rect.Width, value.Width); | ||
Assert.AreEqual(rect.Height, value.Height); | ||
Assert.AreEqual(Timestamp.Unset(), packet.Timestamp()); | ||
} | ||
} | ||
|
||
[Test] | ||
public void Ctor_ShouldInstantiatePacket_When_CalledWithValueAndTimestamp() | ||
{ | ||
using (var timestamp = new Timestamp(1)) | ||
{ | ||
var rect = new NormalizedRect() { XCenter = 0, YCenter = 0, Width = 0.1f, Height = 0.2f }; | ||
using (var packet = new NormalizedRectPacket(rect, timestamp)) | ||
{ | ||
Assert.DoesNotThrow(packet.ValidateAsType); | ||
var value = packet.Get(); | ||
Assert.AreEqual(rect.Width, value.Width); | ||
Assert.AreEqual(rect.Height, value.Height); | ||
Assert.AreEqual(timestamp, packet.Timestamp()); | ||
} | ||
} | ||
} | ||
#endregion | ||
|
||
#region #isDisposed | ||
[Test] | ||
public void IsDisposed_ShouldReturnFalse_When_NotDisposedYet() | ||
{ | ||
using (var packet = new NormalizedRectPacket()) | ||
{ | ||
Assert.False(packet.isDisposed); | ||
} | ||
} | ||
|
||
[Test] | ||
public void IsDisposed_ShouldReturnTrue_When_AlreadyDisposed() | ||
{ | ||
var packet = new NormalizedRectPacket(); | ||
packet.Dispose(); | ||
|
||
Assert.True(packet.isDisposed); | ||
} | ||
#endregion | ||
|
||
#region #At | ||
[Test] | ||
public void At_ShouldReturnNewPacketWithTimestamp() | ||
{ | ||
using (var timestamp = new Timestamp(1)) | ||
{ | ||
var rect = new NormalizedRect() { XCenter = 0, YCenter = 0, Width = 0.1f, Height = 0.2f }; | ||
var packet = new NormalizedRectPacket(rect).At(timestamp); | ||
|
||
var value = packet.Get(); | ||
Assert.AreEqual(rect.Width, value.Width); | ||
Assert.AreEqual(rect.Height, value.Height); | ||
Assert.AreEqual(timestamp, packet.Timestamp()); | ||
|
||
using (var newTimestamp = new Timestamp(2)) | ||
{ | ||
var newPacket = packet.At(newTimestamp); | ||
Assert.AreEqual(newTimestamp, newPacket.Timestamp()); | ||
} | ||
|
||
Assert.AreEqual(timestamp, packet.Timestamp()); | ||
} | ||
} | ||
#endregion | ||
|
||
#region #Consume | ||
[Test] | ||
public void Consume_ShouldThrowNotSupportedException() | ||
{ | ||
var rect = new NormalizedRect() { XCenter = 0, YCenter = 0, Width = 0.1f, Height = 0.2f }; | ||
using (var packet = new NormalizedRectPacket(rect)) | ||
{ | ||
#pragma warning disable IDE0058 | ||
Assert.Throws<NotSupportedException>(() => { packet.Consume(); }); | ||
#pragma warning restore IDE0058 | ||
} | ||
} | ||
#endregion | ||
|
||
#region #ValidateAsType | ||
[Test] | ||
public void ValidateAsType_ShouldNotThrow_When_ValueIsSet() | ||
{ | ||
var rect = new NormalizedRect() { XCenter = 0, YCenter = 0, Width = 0.1f, Height = 0.2f }; | ||
using (var packet = new NormalizedRectPacket(rect)) | ||
{ | ||
Assert.DoesNotThrow(packet.ValidateAsType); | ||
} | ||
} | ||
#endregion | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...github.homuler.mediapipe/Tests/EditMode/Framework/Packet/NormalizedRectPacketTest.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.