aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBaronGreenback <jimcartlidge@yahoo.co.uk>2021-04-19 12:36:30 +0100
committerBaronGreenback <jimcartlidge@yahoo.co.uk>2021-04-19 12:36:30 +0100
commitc68f6163774e4d6534a5a68d2c0f6b7435240ed3 (patch)
tree69abf988ea5afa33581300cc56af4980847ba0c3
parent557a2ad7158b14ae97fa503a551ed17251b97ca0 (diff)
Flip fields
-rw-r--r--Emby.Dlna/DlnaManager.cs2
-rw-r--r--tests/Jellyfin.Dlna.Tests/ProfileTester.cs120
2 files changed, 121 insertions, 1 deletions
diff --git a/Emby.Dlna/DlnaManager.cs b/Emby.Dlna/DlnaManager.cs
index 9ab324038..88b0e1195 100644
--- a/Emby.Dlna/DlnaManager.cs
+++ b/Emby.Dlna/DlnaManager.cs
@@ -107,7 +107,7 @@ namespace Emby.Dlna
}
var profile = GetProfiles()
- .FirstOrDefault(i => i.Identification != null && IsMatch(deviceInfo, i.Identification));
+ .FirstOrDefault(i => i.Identification != null && IsMatch(i.Identification, deviceInfo));
if (profile != null)
{
diff --git a/tests/Jellyfin.Dlna.Tests/ProfileTester.cs b/tests/Jellyfin.Dlna.Tests/ProfileTester.cs
new file mode 100644
index 000000000..83638c7c4
--- /dev/null
+++ b/tests/Jellyfin.Dlna.Tests/ProfileTester.cs
@@ -0,0 +1,120 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Text.RegularExpressions;
+using System.Threading.Tasks;
+using Emby.Dlna.PlayTo;
+using MediaBrowser.Model.Dlna;
+using Xunit;
+
+namespace Jellyfin.Dlna.Tests
+{
+ public class ProfileTester
+ {
+ private bool IsMatch(DeviceIdentification deviceInfo, DeviceIdentification profileInfo)
+ {
+ if (!string.IsNullOrEmpty(profileInfo.FriendlyName))
+ {
+ if (deviceInfo.FriendlyName == null || !IsRegexOrSubstringMatch(deviceInfo.FriendlyName, profileInfo.FriendlyName))
+ {
+ return false;
+ }
+ }
+
+ if (!string.IsNullOrEmpty(profileInfo.Manufacturer))
+ {
+ if (deviceInfo.Manufacturer == null || !IsRegexOrSubstringMatch(deviceInfo.Manufacturer, profileInfo.Manufacturer))
+ {
+ return false;
+ }
+ }
+
+ if (!string.IsNullOrEmpty(profileInfo.ManufacturerUrl))
+ {
+ if (deviceInfo.ManufacturerUrl == null || !IsRegexOrSubstringMatch(deviceInfo.ManufacturerUrl, profileInfo.ManufacturerUrl))
+ {
+ return false;
+ }
+ }
+
+ if (!string.IsNullOrEmpty(profileInfo.ModelDescription))
+ {
+ if (deviceInfo.ModelDescription == null || !IsRegexOrSubstringMatch(deviceInfo.ModelDescription, profileInfo.ModelDescription))
+ {
+ return false;
+ }
+ }
+
+ if (!string.IsNullOrEmpty(profileInfo.ModelName))
+ {
+ if (deviceInfo.ModelName == null || !IsRegexOrSubstringMatch(deviceInfo.ModelName, profileInfo.ModelName))
+ {
+ return false;
+ }
+ }
+
+ if (!string.IsNullOrEmpty(profileInfo.ModelNumber))
+ {
+ if (deviceInfo.ModelNumber == null || !IsRegexOrSubstringMatch(deviceInfo.ModelNumber, profileInfo.ModelNumber))
+ {
+ return false;
+ }
+ }
+
+ if (!string.IsNullOrEmpty(profileInfo.ModelUrl))
+ {
+ if (deviceInfo.ModelUrl == null || !IsRegexOrSubstringMatch(deviceInfo.ModelUrl, profileInfo.ModelUrl))
+ {
+ return false;
+ }
+ }
+
+ if (!string.IsNullOrEmpty(profileInfo.SerialNumber))
+ {
+ if (deviceInfo.SerialNumber == null || !IsRegexOrSubstringMatch(deviceInfo.SerialNumber, profileInfo.SerialNumber))
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ private bool IsRegexOrSubstringMatch(string input, string pattern)
+ {
+ return input.Contains(pattern, StringComparison.OrdinalIgnoreCase) || Regex.IsMatch(input, pattern, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
+ }
+
+ [Fact]
+ public void Test_Profile_Matches()
+ {
+ var source = new DeviceInfo()
+ {
+ Name = "HelloWorld"
+ };
+
+ var dest = new DeviceProfile()
+ {
+ Name = "Test Subject 1",
+ FriendlyName = "HelloWorld",
+ Manufacturer = "LG Electronics",
+ ManufacturerUrl = "http://www.lge.com",
+ ModelDescription = "LG WebOSTV DMRplus",
+ ModelName = "LG TV",
+ ModelNumber = "1.0",
+ Identification = new DeviceIdentification()
+ {
+ FriendlyName = "HelloWorld",
+ Manufacturer = "LG Electronics",
+ ManufacturerUrl = "http://www.lge.com",
+ ModelDescription = "LG WebOSTV DMRplus",
+ ModelName = "LG TV",
+ ModelNumber = "1.0",
+ }
+ };
+
+ Assert.True(IsMatch(dest.Identification, source.ToDeviceIdentification()));
+ }
+ }
+}