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,156 @@
// 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 NameUtilTest
{
[TestCase("{}", "base", "base")]
[TestCase(@"{""node"":[{""name"":""a""}]}", "base", "base")]
[TestCase(@"{""node"":[{},{}]}", "", "")]
[TestCase(@"{""node"":[{""name"":""base""},{""name"":""base_02""}]}", "base", "base_03")]
public void GetUnusedNodeName_ShouldReturnUniqueName(string configJson, string nameBase, string uniqueName)
{
var config = CalculatorGraphConfig.Parser.ParseJson(configJson);
Assert.AreEqual(uniqueName, Tool.GetUnusedNodeName(config, nameBase));
}
[TestCase("{}", "base", "base")]
[TestCase(@"{""node"":[{""input_side_packet"":[""a""]}]}", "base", "base")]
[TestCase(@"{""node"":[{},{""input_side_packet"":[]}]}", "", "")]
[TestCase(@"{""node"":[{""input_side_packet"":[""base""]},{""input_side_packet"":[""TAG:base_02""]}]}", "base", "base_03")]
public void GetUnusedSidePacketName_ShouldReturnUniqueName(string configJson, string nameBase, string uniqueName)
{
var config = CalculatorGraphConfig.Parser.ParseJson(configJson);
Assert.AreEqual(uniqueName, Tool.GetUnusedSidePacketName(config, nameBase));
}
[TestCase(@"{""node"":[{""name"":""x""}]}", 0, "x")]
[TestCase(@"{""node"":[{""name"":""x""},{""name"":""x""},{""name"":""y""},{""name"":""x""}]}", 0, "x_1")]
[TestCase(@"{""node"":[{""name"":""x""},{""name"":""x""},{""name"":""y""},{""name"":""x""}]}", 1, "x_2")]
[TestCase(@"{""node"":[{""name"":""x""},{""name"":""x""},{""name"":""y""},{""name"":""x""}]}", 2, "y")]
[TestCase(@"{""node"":[{""name"":""x""},{""name"":""x""},{""name"":""y""},{""name"":""x""}]}", 3, "x_3")]
[TestCase(@"{""node"":[{""calculator"":""x""},{""name"":""x""}]}", 0, "x_1")]
[TestCase(@"{""node"":[{""calculator"":""x""},{""name"":""x""}]}", 1, "x_2")]
[TestCase(@"{""node"":[{""name"":""x""},{""calculator"":""x""}]}", 0, "x_1")]
[TestCase(@"{""node"":[{""name"":""x""},{""calculator"":""x""}]}", 1, "x_2")]
public void CanonicalNodeName_ShouldReturnCanonicalNodeName_When_NodeIdIsValid(string configJson, int nodeId, string name)
{
var config = CalculatorGraphConfig.Parser.ParseJson(configJson);
Assert.AreEqual(name, Tool.CanonicalNodeName(config, nodeId));
}
[Test]
public void CanonicalNodeName_ShouldThrow_When_NodeIdIsNegative()
{
var config = CalculatorGraphConfig.Parser.ParseJson(@"{""node"":[{""name"":""name""}]}");
#pragma warning disable IDE0058
Assert.Throws<ArgumentOutOfRangeException>(() => { Tool.CanonicalNodeName(config, -1); });
#pragma warning restore IDE0058
}
[Test]
public void CanonicalNodeName_ShouldThrow_When_NodeIdIsInvalid()
{
var config = CalculatorGraphConfig.Parser.ParseJson(@"{""node"":[{""name"":""name""}]}");
#pragma warning disable IDE0058
Assert.Throws<ArgumentOutOfRangeException>(() => { Tool.CanonicalNodeName(config, 1); });
#pragma warning restore IDE0058
}
[Test]
public void CanonicalNodeName_ShouldThrow_When_NodeIsEmpty()
{
var config = CalculatorGraphConfig.Parser.ParseJson("{}");
#pragma warning disable IDE0058
Assert.Throws<ArgumentOutOfRangeException>(() => { Tool.CanonicalNodeName(config, 0); });
#pragma warning restore IDE0058
}
[TestCase("stream", "stream")]
[TestCase("TAG:x", "x")]
[TestCase("TAG:1:x", "x")]
public void ParseNameFromStream_ShouldReturnName_When_InputIsValid(string stream, string name)
{
Assert.AreEqual(name, Tool.ParseNameFromStream(stream));
}
[TestCase(":stream")]
[TestCase("TAG::stream")]
[TestCase("TAG:1:")]
public void ParseNameFromStream_ShouldThrow_When_InputIsInvalid(string stream)
{
#pragma warning disable IDE0058
Assert.Throws<ArgumentException>(() => { Tool.ParseNameFromStream(stream); });
#pragma warning restore IDE0058
}
[TestCase("", "", 0)]
[TestCase("TAG", "TAG", 0)]
[TestCase(":1", "", 1)]
[TestCase("TAG:1", "TAG", 1)]
public void ParseTagIndex_ShouldReturnTagIndexPair_When_InputIsValid(string tagIndex, string tag, int index)
{
var output = Tool.ParseTagIndex(tagIndex);
Assert.AreEqual(tag, output.Item1);
Assert.AreEqual(index, output.Item2);
}
[TestCase("tag")]
[TestCase(":")]
[TestCase("TAG:")]
[TestCase("1")]
public void ParseTagIndex_ShouldThrow_When_InputIsInvalid(string tagIndex)
{
#pragma warning disable IDE0058
Assert.Throws<ArgumentException>(() => { Tool.ParseTagIndex(tagIndex); });
#pragma warning restore IDE0058
}
[TestCase("stream", "", -1)]
[TestCase("TAG:x", "TAG", 0)]
[TestCase("TAG:1:x", "TAG", 1)]
public void ParseTagIndexFromStream_ShouldReturnTagIndexPair_When_InputIsValid(string stream, string tag, int index)
{
var output = Tool.ParseTagIndexFromStream(stream);
Assert.AreEqual(tag, output.Item1);
Assert.AreEqual(index, output.Item2);
}
[TestCase(":stream")]
[TestCase("TAG::stream")]
[TestCase("TAG:1:")]
public void ParseTagIndexFromStream_ShouldThrow_When_InputIsInvalid(string stream)
{
#pragma warning disable IDE0058
Assert.Throws<ArgumentException>(() => { Tool.ParseTagIndexFromStream(stream); });
#pragma warning restore IDE0058
}
[TestCase("", -1, "")]
[TestCase("", 1, "")]
[TestCase("TAG", -1, "TAG")]
[TestCase("TAG", 1, "TAG:1")]
public void CatTag_ShouldReturnTag(string tag, int index, string output)
{
Assert.AreEqual(output, Tool.CatTag(tag, index));
}
[TestCase("", -1, "x", "x")]
[TestCase("", 1, "x", "x")]
[TestCase("TAG", -1, "x", "TAG:x")]
[TestCase("TAG", 1, "x", "TAG:1:x")]
public void CatStream_ShouldReturnStream(string tag, int index, string name, string output)
{
Assert.AreEqual(output, Tool.CatStream((tag, index), name));
}
}
}

View File

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

View File

@@ -0,0 +1,290 @@
// 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 ValidateNameTest
{
#region .ValidateName
[TestCase("humphrey")]
[TestCase("humphrey_bogart")]
[TestCase("humphrey_bogart_1899")]
[TestCase("aa")]
[TestCase("b1")]
[TestCase("_1")]
public void ValidateName_ShouldNotThrow_WhenNameIsValid(string name)
{
Assert.DoesNotThrow(() => { Tool.ValidateName(name); });
}
[TestCase("")]
[TestCase("humphrey bogart")]
[TestCase("humphreyBogart")]
[TestCase("humphrey-bogart")]
[TestCase("humphrey/bogart")]
[TestCase("humphrey.bogart")]
[TestCase("humphrey:bogart")]
[TestCase("1ST")]
[TestCase("7_ELEVEN")]
[TestCase("401K")]
[TestCase("0")]
[TestCase("1")]
[TestCase("11")]
[TestCase("92091")]
[TestCase("1st")]
[TestCase("7_eleven")]
[TestCase("401k")]
[TestCase("\0contains_escapes\t")]
public void ValidateName_ShouldThrow_WhenNameIsInvalid(string name)
{
#pragma warning disable IDE0058
Assert.Throws<ArgumentException>(() => { Tool.ValidateName(name); });
#pragma warning restore IDE0058
}
#endregion
#region .ValidateNumber
[TestCase("0")]
[TestCase("10")]
[TestCase("1234567890")]
public void ValidateNumber_ShouldNotThrow_WhenNumberIsValid(string number)
{
Assert.DoesNotThrow(() => { Tool.ValidateNumber(number); });
}
[TestCase("01")]
[TestCase("1a")]
public void ValidateNumber_ShouldThrow_WhenNumberIsInvalid(string number)
{
#pragma warning disable IDE0058
Assert.Throws<ArgumentException>(() => { Tool.ValidateNumber(number); });
#pragma warning restore IDE0058
}
#endregion
#region .ValidateTag
[TestCase("MALE")]
[TestCase("MALE_ACTOR")]
[TestCase("ACTOR_1899")]
[TestCase("AA")]
[TestCase("B1")]
[TestCase("_1")]
public void ValidateTag_ShouldNotThrow_WhenTagIsValid(string tag)
{
Assert.DoesNotThrow(() => { Tool.ValidateTag(tag); });
}
[TestCase("")]
[TestCase("MALE ACTOR")]
[TestCase("MALEaCTOR")]
[TestCase("MALE-ACTOR")]
[TestCase("MALE/ACTOR")]
[TestCase("MALE.ACTOR")]
[TestCase("MALE:ACTOR")]
[TestCase("0")]
[TestCase("1")]
[TestCase("11")]
[TestCase("92091")]
[TestCase("1ST")]
[TestCase("7_ELEVEN")]
[TestCase("401K")]
[TestCase("\0CONTAINS_ESCAPES\t")]
public void ValidateTag_ShouldThrow_WhenTagIsInvalid(string tag)
{
#pragma warning disable IDE0058
Assert.Throws<ArgumentException>(() => { Tool.ValidateTag(tag); });
#pragma warning restore IDE0058
}
#endregion
#region .ParseTagAndName
[TestCase("MALE:humphrey", "MALE", "humphrey")]
[TestCase("ACTOR:humphrey_bogart", "ACTOR", "humphrey_bogart")]
[TestCase("ACTOR_1899:humphrey_1899", "ACTOR_1899", "humphrey_1899")]
[TestCase("humphrey_bogart", "", "humphrey_bogart")]
[TestCase("ACTOR:humphrey", "ACTOR", "humphrey")]
public void ParseTagAndName_ShouldParseInput_When_InputIsValid(string input, string expectedTag, string expectedName)
{
Tool.ParseTagAndName(input, out var tag, out var name);
Assert.AreEqual(expectedTag, tag);
Assert.AreEqual(expectedName, name);
}
[TestCase(":humphrey")]
[TestCase("humphrey bogart")]
[TestCase("actor:humphrey")]
[TestCase("actor:humphrey")]
[TestCase("ACTOR:HUMPHREY")]
public void ParseTagAndName_ShouldThrow_When_InputIsInvalid(string input)
{
var tag = "UNTOUCHED";
var name = "untouched";
#pragma warning disable IDE0058
Assert.Throws<ArgumentException>(() => { Tool.ParseTagAndName(input, out tag, out name); });
Assert.AreEqual("UNTOUCHED", tag);
Assert.AreEqual("untouched", name);
#pragma warning restore IDE0058
}
[Test]
public void ParseTagAndName_ShouldThrow_When_InputIncludesBadCharacters(
[Values(' ', '-', '/', '.', ':')] char ch,
[Values("MALE$0ACTOR:humphrey", "ACTOR:humphrey$0:bogart")] string str
)
{
ParseTagAndName_ShouldThrow_When_InputIsInvalid(str.Replace("$0", $"{ch}"));
}
#endregion
#region .ParseTagIndexName
[TestCase("MALE:humphrey", "MALE", 0, "humphrey")]
[TestCase("ACTOR:humphrey_bogart", "ACTOR", 0, "humphrey_bogart")]
[TestCase("ACTOR_1899:humphrey_1899", "ACTOR_1899", 0, "humphrey_1899")]
[TestCase("humphrey_bogart", "", -1, "humphrey_bogart")]
[TestCase("ACTRESS:3:mieko_harada", "ACTRESS", 3, "mieko_harada")]
[TestCase("ACTRESS:0:mieko_harada", "ACTRESS", 0, "mieko_harada")]
[TestCase("A1:100:mieko1", "A1", 100, "mieko1")]
[TestCase("A1:10000:mieko1", "A1", 10000, "mieko1")]
public void ParseTagIndexName_ShouldParseInput_When_InputIsValid(string input, string expectedTag, int expectedIndex, string expectedName)
{
Tool.ParseTagIndexName(input, out var tag, out var index, out var name);
Assert.AreEqual(expectedTag, tag);
Assert.AreEqual(expectedIndex, index);
Assert.AreEqual(expectedName, name);
}
[TestCase("")]
[TestCase("A")]
[TestCase("Aa")]
[TestCase("aA")]
[TestCase("1a")]
[TestCase("1")]
[TestCase(":name")]
[TestCase("A:")]
[TestCase("a:name")]
[TestCase("Aa:name")]
[TestCase("aA:name")]
[TestCase("1A:name")]
[TestCase("1:name")]
[TestCase(":1:name")]
[TestCase("A:1:")]
[TestCase("A::name")]
[TestCase("a:1:name")]
[TestCase("Aa:1:name")]
[TestCase("aA:1:name")]
[TestCase("1A:1:name")]
[TestCase("1:1:name")]
[TestCase("A:1:N")]
[TestCase("A:1:nN")]
[TestCase("A:1:Nn")]
[TestCase("A:1:1name")]
[TestCase("A:1:1")]
[TestCase("A:-0:name")]
[TestCase("A:-1:name")]
[TestCase("A:01:name")]
[TestCase("A:00:name")]
[TestCase("A:10001:a")]
[TestCase("A:1:a:")]
[TestCase(":A:1:a")]
[TestCase("A:1:a:a")]
[TestCase("A:1:a:A")]
[TestCase("A:1:a:1")]
public void ParseTagIndexName_ShouldThrow_When_InputIsInvalid(string input)
{
var tag = "UNTOUCHED";
var index = -1;
var name = "untouched";
#pragma warning disable IDE0058
Assert.Throws<ArgumentException>(() => { Tool.ParseTagIndexName(input, out tag, out index, out name); });
Assert.AreEqual("UNTOUCHED", tag);
Assert.AreEqual(-1, index);
Assert.AreEqual("untouched", name);
#pragma warning restore IDE0058
}
[Test]
public void ParseTagIndexName_ShouldThrow_When_InputIncludesBadCharacters(
[Values('!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '{', '}', '[', ']',
'/', '=', '?', '+', '\\', '|', '-', ';', ':', '\'', '"', '<', '.', '>')] char ch,
[Values("$0", "$0a", "a$0", "$0:a", "A$0:a", "$0A:a", "A:$0:a", "A:$01:a", "A:1$0:a", "A:1:a$0", "$0A:1:a")] string str
)
{
ParseTagIndexName_ShouldThrow_When_InputIsInvalid(str.Replace("$0", $"{ch}"));
}
#endregion
#region .ParseTagIndex
[TestCase("", "", 0)]
[TestCase("VIDEO:0", "VIDEO", 0)]
[TestCase("VIDEO:1", "VIDEO", 1)]
[TestCase("AUDIO:2", "AUDIO", 2)]
[TestCase(":0", "", 0)]
[TestCase(":1", "", 1)]
[TestCase(":100", "", 100)]
[TestCase("VIDEO:10000", "VIDEO", 10000)]
public void ParseTagIndex_ShouldParseInput_When_InputIsValid(string input, string expectedTag, int expectedIndex)
{
Tool.ParseTagIndex(input, out var tag, out var index);
Assert.AreEqual(expectedTag, tag);
Assert.AreEqual(expectedIndex, index);
}
[TestCase("a")]
[TestCase("Aa")]
[TestCase("aA")]
[TestCase("1A")]
[TestCase("1")]
[TestCase(":")]
[TestCase(":a")]
[TestCase(":A")]
[TestCase(":-0")]
[TestCase(":-1")]
[TestCase(":01")]
[TestCase(":00")]
[TestCase("A:")]
[TestCase("A:a")]
[TestCase("A:A")]
[TestCase("A:-0")]
[TestCase("A:-1")]
[TestCase("A:01")]
[TestCase("A:00")]
[TestCase("A:10001")]
[TestCase("A:1:")]
[TestCase(":A:1")]
[TestCase("A:1:2")]
[TestCase("A:A:1")]
public void ParseTagIndex_ShouldThrow_When_InputIsInvalid(string input)
{
var tag = "UNTOUCHED";
var index = -1;
#pragma warning disable IDE0058
Assert.Throws<ArgumentException>(() => { Tool.ParseTagIndex(input, out tag, out index); });
Assert.AreEqual("UNTOUCHED", tag);
Assert.AreEqual(-1, index);
#pragma warning restore IDE0058
}
[Test]
public void ParseTagIndex_ShouldThrow_When_InputIncludesBadCharacters(
[Values('!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '{', '}', '[', ']',
'/', '=', '?', '+', '\\', '|', '-', ';', ':', '\'', '"', '<', '.', '>')] char ch,
[Values("$0", "$0A", "A$0", "$0:1", "A$0:1", "$0A:1", "A:1$0", "A:$01")] string str
)
{
ParseTagIndex_ShouldThrow_When_InputIsInvalid(str.Replace("$0", $"{ch}"));
}
#endregion
}
}

View File

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