DynamicHlsControllerTests.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.Collections.Generic;
  3. using AutoFixture;
  4. using AutoFixture.AutoMoq;
  5. using Jellyfin.Api.Controllers;
  6. using Jellyfin.Api.Helpers;
  7. using Jellyfin.Api.Models.StreamingDtos;
  8. using MediaBrowser.Controller.Library;
  9. using MediaBrowser.Controller.MediaEncoding;
  10. using Moq;
  11. using Xunit;
  12. namespace Jellyfin.Api.Tests.Controllers
  13. {
  14. public class DynamicHlsControllerTests
  15. {
  16. [Theory]
  17. [MemberData(nameof(GetSegmentLengths_Success_TestData))]
  18. public void GetSegmentLengths_Success(long runtimeTicks, int segmentlength, double[] expected)
  19. {
  20. var res = DynamicHlsController.GetSegmentLengthsInternal(runtimeTicks, segmentlength);
  21. Assert.Equal(expected.Length, res.Length);
  22. for (int i = 0; i < expected.Length; i++)
  23. {
  24. Assert.Equal(expected[i], res[i]);
  25. }
  26. }
  27. public static IEnumerable<object[]> GetSegmentLengths_Success_TestData()
  28. {
  29. yield return new object[] { 0, 6, Array.Empty<double>() };
  30. yield return new object[]
  31. {
  32. TimeSpan.FromSeconds(3).Ticks,
  33. 6,
  34. new double[] { 3 }
  35. };
  36. yield return new object[]
  37. {
  38. TimeSpan.FromSeconds(6).Ticks,
  39. 6,
  40. new double[] { 6 }
  41. };
  42. yield return new object[]
  43. {
  44. TimeSpan.FromSeconds(3.3333333).Ticks,
  45. 6,
  46. new double[] { 3.3333333 }
  47. };
  48. yield return new object[]
  49. {
  50. TimeSpan.FromSeconds(9.3333333).Ticks,
  51. 6,
  52. new double[] { 6, 3.3333333 }
  53. };
  54. }
  55. }
  56. }