Wes xx mediapipe integration

This commit is contained in:
Jelle De Geest
2023-03-12 20:34:16 +00:00
parent 8349b5f149
commit b11eeb465c
975 changed files with 192230 additions and 0 deletions

View File

@@ -0,0 +1,132 @@
// 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 BoolPacketTest
{
#region Constructor
[Test, SignalAbort]
public void Ctor_ShouldInstantiatePacket_When_CalledWithNoArguments()
{
using (var packet = new BoolPacket())
{
#pragma warning disable IDE0058
Assert.AreEqual(Status.StatusCode.Internal, packet.ValidateAsType().Code());
Assert.Throws<MediaPipeException>(() => { packet.Get(); });
Assert.AreEqual(Timestamp.Unset(), packet.Timestamp());
#pragma warning restore IDE0058
}
}
[Test]
public void Ctor_ShouldInstantiatePacket_When_CalledWithTrue()
{
using (var packet = new BoolPacket(true))
{
Assert.True(packet.ValidateAsType().Ok());
Assert.True(packet.Get());
Assert.AreEqual(Timestamp.Unset(), packet.Timestamp());
}
}
[Test]
public void Ctor_ShouldInstantiatePacket_When_CalledWithFalse()
{
using (var packet = new BoolPacket(false))
{
Assert.True(packet.ValidateAsType().Ok());
Assert.False(packet.Get());
Assert.AreEqual(Timestamp.Unset(), packet.Timestamp());
}
}
[Test]
public void Ctor_ShouldInstantiatePacket_When_CalledWithValueAndTimestamp()
{
using (var timestamp = new Timestamp(1))
{
using (var packet = new BoolPacket(true, timestamp))
{
Assert.True(packet.ValidateAsType().Ok());
Assert.True(packet.Get());
Assert.AreEqual(timestamp, packet.Timestamp());
}
}
}
#endregion
#region #isDisposed
[Test]
public void IsDisposed_ShouldReturnFalse_When_NotDisposedYet()
{
using (var packet = new BoolPacket())
{
Assert.False(packet.isDisposed);
}
}
[Test]
public void IsDisposed_ShouldReturnTrue_When_AlreadyDisposed()
{
var packet = new BoolPacket();
packet.Dispose();
Assert.True(packet.isDisposed);
}
#endregion
#region #At
[Test]
public void At_ShouldReturnNewPacketWithTimestamp()
{
using (var timestamp = new Timestamp(1))
{
var packet = new BoolPacket(true).At(timestamp);
Assert.True(packet.Get());
Assert.AreEqual(timestamp, packet.Timestamp());
using (var newTimestamp = new Timestamp(2))
{
var newPacket = packet.At(newTimestamp);
Assert.True(newPacket.Get());
Assert.AreEqual(newTimestamp, newPacket.Timestamp());
}
Assert.AreEqual(timestamp, packet.Timestamp());
}
}
#endregion
#region #Consume
[Test]
public void Consume_ShouldThrowNotSupportedException()
{
using (var packet = new BoolPacket())
{
#pragma warning disable IDE0058
Assert.Throws<NotSupportedException>(() => { packet.Consume(); });
#pragma warning restore IDE0058
}
}
#endregion
#region #ValidateAsType
[Test]
public void ValidateAsType_ShouldReturnOk_When_ValueIsSet()
{
using (var packet = new BoolPacket(true))
{
Assert.True(packet.ValidateAsType().Ok());
}
}
#endregion
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b59151b6708d204ee970450f8028d00b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,137 @@
// 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 FloatArrayPacketTest
{
#region Constructor
[Test, SignalAbort]
public void Ctor_ShouldInstantiatePacket_When_CalledWithNoArguments()
{
using (var packet = new FloatArrayPacket())
{
#pragma warning disable IDE0058
packet.length = 0;
Assert.AreEqual(Status.StatusCode.Internal, packet.ValidateAsType().Code());
Assert.Throws<MediaPipeException>(() => { packet.Get(); });
Assert.AreEqual(Timestamp.Unset(), packet.Timestamp());
#pragma warning restore IDE0058
}
}
[Test]
public void Ctor_ShouldInstantiatePacket_When_CalledWithEmptyArray()
{
float[] array = { };
using (var packet = new FloatArrayPacket(array))
{
Assert.True(packet.ValidateAsType().Ok());
Assert.AreEqual(array, packet.Get());
Assert.AreEqual(Timestamp.Unset(), packet.Timestamp());
}
}
[Test]
public void Ctor_ShouldInstantiatePacket_When_CalledWithArray()
{
float[] array = { 0.01f };
using (var packet = new FloatArrayPacket(array))
{
Assert.True(packet.ValidateAsType().Ok());
Assert.AreEqual(array, packet.Get());
Assert.AreEqual(Timestamp.Unset(), packet.Timestamp());
}
}
[Test]
public void Ctor_ShouldInstantiatePacket_When_CalledWithValueAndTimestamp()
{
float[] array = { 0.01f, 0.02f };
using (var timestamp = new Timestamp(1))
{
using (var packet = new FloatArrayPacket(array, timestamp))
{
Assert.True(packet.ValidateAsType().Ok());
Assert.AreEqual(array, packet.Get());
Assert.AreEqual(timestamp, packet.Timestamp());
}
}
}
#endregion
#region #isDisposed
[Test]
public void IsDisposed_ShouldReturnFalse_When_NotDisposedYet()
{
using (var packet = new FloatArrayPacket())
{
Assert.False(packet.isDisposed);
}
}
[Test]
public void IsDisposed_ShouldReturnTrue_When_AlreadyDisposed()
{
var packet = new FloatArrayPacket();
packet.Dispose();
Assert.True(packet.isDisposed);
}
#endregion
#region #At
[Test]
public void At_ShouldReturnNewPacketWithTimestamp()
{
using (var timestamp = new Timestamp(1))
{
float[] array = { 0.0f };
var packet = new FloatArrayPacket(array).At(timestamp);
Assert.AreEqual(array, packet.Get());
Assert.AreEqual(timestamp, packet.Timestamp());
using (var newTimestamp = new Timestamp(2))
{
var newPacket = packet.At(newTimestamp);
Assert.AreEqual(array, newPacket.Get());
Assert.AreEqual(newTimestamp, newPacket.Timestamp());
}
Assert.AreEqual(timestamp, packet.Timestamp());
}
}
#endregion
#region #Consume
[Test]
public void Consume_ShouldThrowNotSupportedException()
{
using (var packet = new FloatArrayPacket())
{
#pragma warning disable IDE0058
Assert.Throws<NotSupportedException>(() => { packet.Consume(); });
#pragma warning restore IDE0058
}
}
#endregion
#region #ValidateAsType
[Test]
public void ValidateAsType_ShouldReturnOk_When_ValueIsSet()
{
float[] array = { 0.01f };
using (var packet = new FloatArrayPacket(array))
{
Assert.True(packet.ValidateAsType().Ok());
}
}
#endregion
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 43430c0ef642804f9a6347fce4ec497a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,120 @@
// 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 FloatPacketTest
{
#region Constructor
[Test, SignalAbort]
public void Ctor_ShouldInstantiatePacket_When_CalledWithNoArguments()
{
using (var packet = new FloatPacket())
{
#pragma warning disable IDE0058
Assert.AreEqual(Status.StatusCode.Internal, packet.ValidateAsType().Code());
Assert.Throws<MediaPipeException>(() => { packet.Get(); });
Assert.AreEqual(Timestamp.Unset(), packet.Timestamp());
#pragma warning restore IDE0058
}
}
[Test]
public void Ctor_ShouldInstantiatePacket_When_CalledWithValue()
{
using (var packet = new FloatPacket(0.01f))
{
Assert.True(packet.ValidateAsType().Ok());
Assert.AreEqual(0.01f, packet.Get());
Assert.AreEqual(Timestamp.Unset(), packet.Timestamp());
}
}
[Test]
public void Ctor_ShouldInstantiatePacket_When_CalledWithValueAndTimestamp()
{
using (var timestamp = new Timestamp(1))
{
using (var packet = new FloatPacket(0.01f, timestamp))
{
Assert.True(packet.ValidateAsType().Ok());
Assert.AreEqual(0.01f, packet.Get());
Assert.AreEqual(timestamp, packet.Timestamp());
}
}
}
#endregion
#region #isDisposed
[Test]
public void IsDisposed_ShouldReturnFalse_When_NotDisposedYet()
{
using (var packet = new FloatPacket())
{
Assert.False(packet.isDisposed);
}
}
[Test]
public void IsDisposed_ShouldReturnTrue_When_AlreadyDisposed()
{
var packet = new FloatPacket();
packet.Dispose();
Assert.True(packet.isDisposed);
}
#endregion
#region #At
[Test]
public void At_ShouldReturnNewPacketWithTimestamp()
{
using (var timestamp = new Timestamp(1))
{
var packet = new FloatPacket(0).At(timestamp);
Assert.AreEqual(0.0f, packet.Get());
Assert.AreEqual(timestamp, packet.Timestamp());
using (var newTimestamp = new Timestamp(2))
{
var newPacket = packet.At(newTimestamp);
Assert.AreEqual(0.0f, newPacket.Get());
Assert.AreEqual(newTimestamp, newPacket.Timestamp());
}
Assert.AreEqual(timestamp, packet.Timestamp());
}
}
#endregion
#region #Consume
[Test]
public void Consume_ShouldThrowNotSupportedException()
{
using (var packet = new FloatPacket())
{
#pragma warning disable IDE0058
Assert.Throws<NotSupportedException>(() => { packet.Consume(); });
#pragma warning restore IDE0058
}
}
#endregion
#region #ValidateAsType
[Test]
public void ValidateAsType_ShouldReturnOk_When_ValueIsSet()
{
using (var packet = new FloatPacket(0.01f))
{
Assert.True(packet.ValidateAsType().Ok());
}
}
#endregion
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 39a81137616a1218b9b2b11d2feeadd0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,176 @@
// 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;
using System.Collections.Generic;
namespace Mediapipe.Tests
{
public class FloatVectorPacketTest
{
#region Constructor
[Test, SignalAbort]
public void Ctor_ShouldInstantiatePacket_When_CalledWithNoArguments()
{
using (var packet = new FloatVectorPacket())
{
#pragma warning disable IDE0058
Assert.AreEqual(Status.StatusCode.Internal, packet.ValidateAsType().Code());
Assert.Throws<MediaPipeException>(() => { packet.Get(); });
Assert.AreEqual(Timestamp.Unset(), packet.Timestamp());
#pragma warning restore IDE0058
}
}
[Test]
public void Ctor_ShouldInstantiatePacket_When_CalledWithEmptyArray()
{
float[] data = { };
using (var packet = new FloatVectorPacket(data))
{
Assert.True(packet.ValidateAsType().Ok());
Assert.AreEqual(data, packet.Get());
Assert.AreEqual(Timestamp.Unset(), packet.Timestamp());
}
}
[Test]
public void Ctor_ShouldInstantiatePacket_When_CalledWithArray()
{
float[] data = { 0.01f };
using (var packet = new FloatVectorPacket(data))
{
Assert.True(packet.ValidateAsType().Ok());
Assert.AreEqual(data, packet.Get());
Assert.AreEqual(Timestamp.Unset(), packet.Timestamp());
}
}
[Test]
public void Ctor_ShouldInstantiatePacket_When_CalledWithValueAndTimestamp()
{
float[] data = { 0.01f, 0.02f };
using (var timestamp = new Timestamp(1))
{
using (var packet = new FloatVectorPacket(data, timestamp))
{
Assert.True(packet.ValidateAsType().Ok());
Assert.AreEqual(data, packet.Get());
Assert.AreEqual(timestamp, packet.Timestamp());
}
}
}
[Test]
public void Ctor_ShouldInstantiatePacket_When_CalledWithEmptyList()
{
var data = new List<float>();
using (var packet = new FloatVectorPacket(data))
{
Assert.True(packet.ValidateAsType().Ok());
Assert.AreEqual(data, packet.Get());
Assert.AreEqual(Timestamp.Unset(), packet.Timestamp());
}
}
[Test]
public void Ctor_ShouldInstantiatePacket_When_CalledWithList()
{
var data = new List<float>() { 0.01f };
using (var packet = new FloatVectorPacket(data))
{
Assert.True(packet.ValidateAsType().Ok());
Assert.AreEqual(data, packet.Get());
Assert.AreEqual(Timestamp.Unset(), packet.Timestamp());
}
}
[Test]
public void Ctor_ShouldInstantiatePacket_When_CalledWithListAndTimestamp()
{
var data = new List<float>() { 0.01f, 0.02f };
using (var timestamp = new Timestamp(1))
{
using (var packet = new FloatVectorPacket(data, timestamp))
{
Assert.True(packet.ValidateAsType().Ok());
Assert.AreEqual(data, packet.Get());
Assert.AreEqual(timestamp, packet.Timestamp());
}
}
}
#endregion
#region #isDisposed
[Test]
public void IsDisposed_ShouldReturnFalse_When_NotDisposedYet()
{
using (var packet = new FloatVectorPacket())
{
Assert.False(packet.isDisposed);
}
}
[Test]
public void IsDisposed_ShouldReturnTrue_When_AlreadyDisposed()
{
var packet = new FloatVectorPacket();
packet.Dispose();
Assert.True(packet.isDisposed);
}
#endregion
#region #At
[Test]
public void At_ShouldReturnNewPacketWithTimestamp()
{
using (var timestamp = new Timestamp(1))
{
var data = new List<float>() { 0.0f };
var packet = new FloatVectorPacket(data).At(timestamp);
Assert.AreEqual(data, packet.Get());
Assert.AreEqual(timestamp, packet.Timestamp());
using (var newTimestamp = new Timestamp(2))
{
var newPacket = packet.At(newTimestamp);
Assert.AreEqual(data, newPacket.Get());
Assert.AreEqual(newTimestamp, newPacket.Timestamp());
}
Assert.AreEqual(timestamp, packet.Timestamp());
}
}
#endregion
#region #Consume
[Test]
public void Consume_ShouldThrowNotSupportedException()
{
using (var packet = new FloatVectorPacket())
{
#pragma warning disable IDE0058
Assert.Throws<NotSupportedException>(() => { packet.Consume(); });
#pragma warning restore IDE0058
}
}
#endregion
#region #ValidateAsType
[Test]
public void ValidateAsType_ShouldReturnOk_When_ValueIsSet()
{
float[] array = { 0.01f };
using (var packet = new FloatVectorPacket(array))
{
Assert.True(packet.ValidateAsType().Ok());
}
}
#endregion
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8a567519c65348c47ae2c5784431179e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,178 @@
// 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;
namespace Mediapipe.Tests
{
public class ImageFramePacketTest
{
#region Constructor
[Test]
public void Ctor_ShouldInstantiatePacket_When_CalledWithNoArguments()
{
using (var packet = new ImageFramePacket())
{
using (var statusOrImageFrame = packet.Consume())
{
Assert.AreEqual(Status.StatusCode.Internal, packet.ValidateAsType().Code());
Assert.AreEqual(Status.StatusCode.Internal, statusOrImageFrame.status.Code());
Assert.AreEqual(Timestamp.Unset(), packet.Timestamp());
}
}
}
[Test]
public void Ctor_ShouldInstantiatePacket_When_CalledWithValue()
{
var srcImageFrame = new ImageFrame();
using (var packet = new ImageFramePacket(srcImageFrame))
{
Assert.True(srcImageFrame.isDisposed);
Assert.True(packet.ValidateAsType().Ok());
Assert.AreEqual(Timestamp.Unset(), packet.Timestamp());
using (var statusOrImageFrame = packet.Consume())
{
Assert.True(statusOrImageFrame.Ok());
using (var imageFrame = statusOrImageFrame.Value())
{
Assert.AreEqual(ImageFormat.Types.Format.Unknown, imageFrame.Format());
}
}
}
}
[Test]
public void Ctor_ShouldInstantiatePacket_When_CalledWithValueAndTimestamp()
{
var srcImageFrame = new ImageFrame();
using (var timestamp = new Timestamp(1))
{
using (var packet = new ImageFramePacket(srcImageFrame, timestamp))
{
Assert.True(srcImageFrame.isDisposed);
Assert.True(packet.ValidateAsType().Ok());
using (var statusOrImageFrame = packet.Consume())
{
Assert.True(statusOrImageFrame.Ok());
using (var imageFrame = statusOrImageFrame.Value())
{
Assert.AreEqual(ImageFormat.Types.Format.Unknown, imageFrame.Format());
Assert.AreEqual(timestamp, packet.Timestamp());
}
}
}
}
}
#endregion
#region #isDisposed
[Test]
public void IsDisposed_ShouldReturnFalse_When_NotDisposedYet()
{
using (var packet = new ImageFramePacket())
{
Assert.False(packet.isDisposed);
}
}
[Test]
public void IsDisposed_ShouldReturnTrue_When_AlreadyDisposed()
{
var packet = new ImageFramePacket();
packet.Dispose();
Assert.True(packet.isDisposed);
}
#endregion
#region #At
[Test]
public void At_ShouldReturnNewPacketWithTimestamp()
{
using (var timestamp = new Timestamp(1))
{
var packet = new ImageFramePacket(new ImageFrame(ImageFormat.Types.Format.Srgba, 10, 10)).At(timestamp);
Assert.AreEqual(10, packet.Get().Width());
Assert.AreEqual(timestamp, packet.Timestamp());
using (var newTimestamp = new Timestamp(2))
{
var newPacket = packet.At(newTimestamp);
Assert.AreEqual(10, newPacket.Get().Width());
Assert.AreEqual(newTimestamp, newPacket.Timestamp());
}
Assert.AreEqual(timestamp, packet.Timestamp());
}
}
#endregion
#region #Get
[Test, SignalAbort]
public void Get_ShouldThrowMediaPipeException_When_DataIsEmpty()
{
using (var packet = new ImageFramePacket())
{
#pragma warning disable IDE0058
Assert.Throws<MediaPipeException>(() => { packet.Get(); });
#pragma warning restore IDE0058
}
}
public void Get_ShouldReturnImageFrame_When_DataIsNotEmpty()
{
using (var packet = new ImageFramePacket(new ImageFrame(ImageFormat.Types.Format.Sbgra, 10, 10)))
{
using (var imageFrame = packet.Get())
{
Assert.AreEqual(ImageFormat.Types.Format.Sbgra, imageFrame.Format());
Assert.AreEqual(10, imageFrame.Width());
Assert.AreEqual(10, imageFrame.Height());
}
}
}
#endregion
#region #Consume
[Test]
public void Consume_ShouldReturnImageFrame()
{
using (var packet = new ImageFramePacket(new ImageFrame(ImageFormat.Types.Format.Sbgra, 10, 10)))
{
using (var statusOrImageFrame = packet.Consume())
{
Assert.True(statusOrImageFrame.Ok());
using (var imageFrame = statusOrImageFrame.Value())
{
Assert.AreEqual(ImageFormat.Types.Format.Sbgra, imageFrame.Format());
Assert.AreEqual(10, imageFrame.Width());
Assert.AreEqual(10, imageFrame.Height());
}
}
}
}
#endregion
#region #ValidateAsType
[Test]
public void ValidateAsType_ShouldReturnOk_When_ValueIsSet()
{
using (var packet = new ImageFramePacket(new ImageFrame()))
{
Assert.True(packet.ValidateAsType().Ok());
}
}
#endregion
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a3eb7f3538d626cd68495da48b11e6f7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,111 @@
// 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.Collections.Generic;
using NUnit.Framework;
using System;
namespace Mediapipe.Tests
{
public class MatrixPacketTest
{
#region Constructor
[Test]
public void Ctor_ShouldInstantiatePacket_When_CalledWithValue()
{
var matrix = CreateMatrixInputData();
using (var packet = new MatrixPacket(matrix))
{
Assert.True(packet.ValidateAsType().Ok());
Assert.AreEqual(matrix, packet.Get());
Assert.AreEqual(Timestamp.Unset(), packet.Timestamp());
}
}
#endregion
#region #isDisposed
[Test]
public void IsDisposed_ShouldReturnFalse_When_NotDisposedYet()
{
using (var packet = new MatrixPacket())
{
Assert.False(packet.isDisposed);
}
}
[Test]
public void IsDisposed_ShouldReturnTrue_When_AlreadyDisposed()
{
var packet = new MatrixPacket();
packet.Dispose();
Assert.True(packet.isDisposed);
}
#endregion
#region #At
[Test]
public void At_ShouldReturnNewPacketWithTimestamp()
{
using (var timestamp = new Timestamp(1))
{
var matrix = CreateMatrixInputData();
var packet = new MatrixPacket(matrix).At(timestamp);
Assert.AreEqual(matrix, packet.Get());
Assert.AreEqual(timestamp, packet.Timestamp());
using (var newTimestamp = new Timestamp(2))
{
var newPacket = packet.At(newTimestamp);
Assert.AreEqual(matrix, newPacket.Get());
Assert.AreEqual(newTimestamp, newPacket.Timestamp());
}
Assert.AreEqual(timestamp, packet.Timestamp());
}
}
#endregion
#region #Consume
[Test]
public void Consume_ShouldThrowNotSupportedException()
{
using (var packet = new MatrixPacket())
{
#pragma warning disable IDE0058
Assert.Throws<NotSupportedException>(() => { packet.Consume(); });
#pragma warning restore IDE0058
}
}
#endregion
#region #ValidateAsType
[Test]
public void ValidateAsType_ShouldReturnOk_When_ValueIsSet()
{
using (var packet = new MatrixPacket(CreateMatrixInputData()))
{
Assert.True(packet.ValidateAsType().Ok());
}
}
#endregion
private static MatrixData CreateMatrixInputData()
{
var matrix = new MatrixData();
matrix.PackedData.Add(0);
matrix.PackedData.Add(1);
matrix.PackedData.Add(2);
matrix.PackedData.Add(3);
matrix.PackedData.Add(4);
matrix.PackedData.Add(5);
matrix.Rows = 2;
matrix.Cols = 3;
return matrix;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a3a4963f37dcdcc43a8292c2493c19bc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,57 @@
// 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;
namespace Mediapipe.Tests
{
public class PacketTest
{
#region #DebugString
[Test]
public void DebugString_ShouldReturnDebugString_When_InstantiatedWithDefaultConstructor()
{
using (var packet = new BoolPacket())
{
Assert.AreEqual("mediapipe::Packet with timestamp: Timestamp::Unset() and no data", packet.DebugString());
}
}
#endregion
#region #DebugTypeName
[Test]
public void DebugTypeName_ShouldReturnTypeName_When_ValueIsNotSet()
{
using (var packet = new BoolPacket())
{
Assert.AreEqual("{empty}", packet.DebugTypeName());
}
}
#endregion
#region #RegisteredTypeName
[Test]
public void RegisteredTypeName_ShouldReturnEmptyString()
{
using (var packet = new BoolPacket())
{
Assert.AreEqual("", packet.RegisteredTypeName());
}
}
#endregion
#region #ValidateAsProtoMessageLite
[Test]
public void ValidateAsProtoMessageLite_ShouldReturnInvalidArgument_When_ValueIsBool()
{
using (var packet = new BoolPacket(true))
{
Assert.AreEqual(Status.StatusCode.InvalidArgument, packet.ValidateAsProtoMessageLite().Code());
}
}
#endregion
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8c8b062f481adfe73be16b679e3c1cca
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,129 @@
// 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;
namespace Mediapipe.Tests
{
public class SidePacketTest
{
#region #size
[Test]
public void Size_ShouldReturnZero_When_Initialized()
{
using (var sidePacket = new SidePacket())
{
Assert.AreEqual(0, sidePacket.size);
}
}
[Test]
public void Size_ShouldReturnSize_When_AfterPacketsAreEmplaced()
{
using (var sidePacket = new SidePacket())
{
var flagPacket = new BoolPacket(true);
var valuePacket = new FloatPacket(1.0f);
sidePacket.Emplace("flag", flagPacket);
sidePacket.Emplace("value", valuePacket);
Assert.AreEqual(2, sidePacket.size);
Assert.True(flagPacket.isDisposed);
Assert.True(valuePacket.isDisposed);
}
}
#endregion
#region #Emplace
[Test]
public void Emplace_ShouldInsertAndDisposePacket()
{
using (var sidePacket = new SidePacket())
{
Assert.AreEqual(0, sidePacket.size);
Assert.IsNull(sidePacket.At<FloatPacket, float>("value"));
var flagPacket = new FloatPacket(1.0f);
sidePacket.Emplace("value", flagPacket);
Assert.AreEqual(1, sidePacket.size);
Assert.AreEqual(1.0f, sidePacket.At<FloatPacket, float>("value").Get());
Assert.True(flagPacket.isDisposed);
}
}
[Test]
public void Emplace_ShouldIgnoreValue_When_KeyExists()
{
using (var sidePacket = new SidePacket())
{
var oldValuePacket = new FloatPacket(1.0f);
sidePacket.Emplace("value", oldValuePacket);
Assert.AreEqual(1.0f, sidePacket.At<FloatPacket, float>("value").Get());
var newValuePacket = new FloatPacket(2.0f);
sidePacket.Emplace("value", newValuePacket);
Assert.AreEqual(1.0f, sidePacket.At<FloatPacket, float>("value").Get());
}
}
#endregion
#region #Erase
[Test]
public void Erase_ShouldDoNothing_When_KeyDoesNotExist()
{
using (var sidePacket = new SidePacket())
{
var count = sidePacket.Erase("value");
Assert.AreEqual(0, sidePacket.size);
Assert.AreEqual(0, count);
}
}
[Test]
public void Erase_ShouldEraseKey_When_KeyExists()
{
using (var sidePacket = new SidePacket())
{
sidePacket.Emplace("value", new BoolPacket(true));
Assert.AreEqual(1, sidePacket.size);
var count = sidePacket.Erase("value");
Assert.AreEqual(0, sidePacket.size);
Assert.AreEqual(1, count);
}
}
#endregion
#region #Clear
[Test]
public void Clear_ShouldDoNothing_When_SizeIsZero()
{
using (var sidePacket = new SidePacket())
{
sidePacket.Clear();
Assert.AreEqual(0, sidePacket.size);
}
}
[Test]
public void Clear_ShouldClearAllKeys_When_SizeIsNotZero()
{
using (var sidePacket = new SidePacket())
{
sidePacket.Emplace("flag", new BoolPacket(true));
sidePacket.Emplace("value", new FloatPacket(1.0f));
Assert.AreEqual(2, sidePacket.size);
sidePacket.Clear();
Assert.AreEqual(0, sidePacket.size);
}
}
#endregion
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 148809b5633f2f8cd9f277e01bb7b0ca
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,177 @@
// 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.Text.RegularExpressions;
namespace Mediapipe.Tests
{
public class StringPacketTest
{
#region Constructor
[Test, SignalAbort]
public void Ctor_ShouldInstantiatePacket_When_CalledWithNoArguments()
{
using (var packet = new StringPacket())
{
#pragma warning disable IDE0058
Assert.AreEqual(Status.StatusCode.Internal, packet.ValidateAsType().Code());
Assert.Throws<MediaPipeException>(() => { packet.Get(); });
Assert.AreEqual(Timestamp.Unset(), packet.Timestamp());
#pragma warning restore IDE0058
}
}
[Test]
public void Ctor_ShouldInstantiatePacket_When_CalledWithString()
{
using (var packet = new StringPacket("test"))
{
Assert.True(packet.ValidateAsType().Ok());
Assert.AreEqual("test", packet.Get());
Assert.AreEqual(Timestamp.Unset(), packet.Timestamp());
}
}
[Test]
public void Ctor_ShouldInstantiatePacket_When_CalledWithByteArray()
{
var bytes = new byte[] { (byte)'t', (byte)'e', (byte)'s', (byte)'t' };
using (var packet = new StringPacket(bytes))
{
Assert.True(packet.ValidateAsType().Ok());
Assert.AreEqual("test", packet.Get());
Assert.AreEqual(Timestamp.Unset(), packet.Timestamp());
}
}
[Test]
public void Ctor_ShouldInstantiatePacket_When_CalledWithStringAndTimestamp()
{
using (var timestamp = new Timestamp(1))
{
using (var packet = new StringPacket("test", timestamp))
{
Assert.True(packet.ValidateAsType().Ok());
Assert.AreEqual("test", packet.Get());
Assert.AreEqual(timestamp, packet.Timestamp());
}
}
}
[Test]
public void Ctor_ShouldInstantiatePacket_When_CalledWithByteArrayAndTimestamp()
{
var bytes = new byte[] { (byte)'t', (byte)'e', (byte)'s', (byte)'t' };
using (var timestamp = new Timestamp(1))
{
using (var packet = new StringPacket(bytes, timestamp))
{
Assert.True(packet.ValidateAsType().Ok());
Assert.AreEqual("test", packet.Get());
Assert.AreEqual(timestamp, packet.Timestamp());
}
}
}
#endregion
#region #isDisposed
[Test]
public void IsDisposed_ShouldReturnFalse_When_NotDisposedYet()
{
using (var packet = new StringPacket())
{
Assert.False(packet.isDisposed);
}
}
[Test]
public void IsDisposed_ShouldReturnTrue_When_AlreadyDisposed()
{
var packet = new StringPacket();
packet.Dispose();
Assert.True(packet.isDisposed);
}
#endregion
#region #At
[Test]
public void At_ShouldReturnNewPacketWithTimestamp()
{
using (var timestamp = new Timestamp(1))
{
var str = "str";
var packet = new StringPacket(str).At(timestamp);
Assert.AreEqual(str, packet.Get());
Assert.AreEqual(timestamp, packet.Timestamp());
using (var newTimestamp = new Timestamp(2))
{
var newPacket = packet.At(newTimestamp);
Assert.AreEqual(str, newPacket.Get());
Assert.AreEqual(newTimestamp, newPacket.Timestamp());
}
Assert.AreEqual(timestamp, packet.Timestamp());
}
}
#endregion
#region #GetByteArray
[Test]
public void GetByteArray_ShouldReturnByteArray()
{
var bytes = new byte[] { (byte)'a', (byte)'b', 0, (byte)'c' };
using (var packet = new StringPacket(bytes))
{
Assert.AreEqual(bytes, packet.GetByteArray());
Assert.AreEqual("ab", packet.Get());
}
}
#endregion
#region #Consume
[Test]
public void Consume_ShouldReturnStatusOrString_When_PacketIsEmpty()
{
using (var packet = new StringPacket())
{
using (var statusOrString = packet.Consume())
{
Assert.False(statusOrString.Ok());
Assert.AreEqual(Status.StatusCode.Internal, statusOrString.status.Code());
}
}
}
[Test]
public void Consume_ShouldReturnStatusOrString_When_PacketIsNotEmpty()
{
using (var packet = new StringPacket("abc"))
{
using (var statusOrString = packet.Consume())
{
Assert.True(statusOrString.Ok());
Assert.AreEqual("abc", statusOrString.Value());
}
Assert.True(packet.IsEmpty());
}
}
#endregion
#region #ValidateAsType
[Test]
public void ValidateAsType_ShouldReturnOk_When_ValueIsSet()
{
using (var packet = new StringPacket("test"))
{
Assert.True(packet.ValidateAsType().Ok());
}
}
#endregion
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1fc360374ea123c28b7da8b9b81ebac6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: