ソースを参照

Add topic filter tests from MQTT spec

release/3.x.x
Christian 6年前
コミット
74a5522965
2個のファイルの変更28行の追加2行の削除
  1. +1
    -1
      Frameworks/MQTTnet.NetStandard/Adapter/MqttChannelAdapter.cs
  2. +27
    -1
      Tests/MQTTnet.Core.Tests/TopicFilterComparerTests.cs

+ 1
- 1
Frameworks/MQTTnet.NetStandard/Adapter/MqttChannelAdapter.cs ファイルの表示

@@ -129,7 +129,7 @@ namespace MQTTnet.Adapter
{
return null;
}
if (header.BodyLength == 0)
{
return new ReceivedMqttPacket(header, new MemoryStream(new byte[0], false));


+ 27
- 1
Tests/MQTTnet.Core.Tests/TopicFilterComparerTests.cs ファイルの表示

@@ -60,7 +60,33 @@ namespace MQTTnet.Core.Tests
CompareAndAssert("A/B/C/D", "#", true);
}

private void CompareAndAssert(string topic, string filter, bool expectedResult)
[TestMethod]
public void TopicFilterComparer_MultiLevel_Sport()
{
// Tests from official MQTT spec (4.7.1.2 Multi-level wildcard)
CompareAndAssert("sport/tennis/player1", "sport/tennis/player1/#", true);
CompareAndAssert("sport/tennis/player1/ranking", "sport/tennis/player1/#", true);
CompareAndAssert("sport/tennis/player1/score/wimbledon", "sport/tennis/player1/#", true);

CompareAndAssert("sport/tennis/player1", "sport/tennis/+", true);
CompareAndAssert("sport/tennis/player2", "sport/tennis/+", true);
CompareAndAssert("sport/tennis/player1/ranking", "sport/tennis/+", false);

CompareAndAssert("sport", "sport/#", true);
CompareAndAssert("sport", "sport/+", false);
CompareAndAssert("sport/", "sport/+", true);
}

[TestMethod]
public void TopicFilterComparer_SingleLevel_Finance()
{
// Tests from official MQTT spec (4.7.1.3 Single level wildcard)
CompareAndAssert("/finance", "+/+", true);
CompareAndAssert("/finance", "/+", true);
CompareAndAssert("/finance", "+", false);
}

private static void CompareAndAssert(string topic, string filter, bool expectedResult)
{
Assert.AreEqual(expectedResult, MqttTopicFilterComparer.IsMatch(topic, filter));
}


読み込み中…
キャンセル
保存