FixedBufferStringQueueTests.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using NUnit.Framework;
  2. using System;
  3. namespace UnityEngine.Rendering.Tests
  4. {
  5. unsafe class FixedBufferStringQueueTests
  6. {
  7. [Test]
  8. public void PushAndPopInBufferRange()
  9. {
  10. const int size = 512;
  11. var bufferStart = stackalloc byte[size];
  12. var buffer = new CoreUnsafeUtils.FixedBufferStringQueue(bufferStart, size);
  13. Assert.True(buffer.TryPush("Lorem ipsum dolor sit"));
  14. Assert.True(buffer.TryPush("amet, consectetur adipiscing"));
  15. Assert.True(buffer.TryPush("elit, sed do eiusmod"));
  16. Assert.True(buffer.TryPush("tempor incididunt ut labore"));
  17. Assert.AreEqual(4, buffer.Count);
  18. Assert.True(buffer.TryPop(out string v) && v == "Lorem ipsum dolor sit");
  19. Assert.True(buffer.TryPop(out v) && v == "amet, consectetur adipiscing");
  20. Assert.True(buffer.TryPop(out v) && v == "elit, sed do eiusmod");
  21. Assert.True(buffer.TryPop(out v) && v == "tempor incididunt ut labore");
  22. }
  23. [Test]
  24. public void PushAndPopOutOfBufferRange()
  25. {
  26. const int size = 64;
  27. var bufferStart = stackalloc byte[size];
  28. var buffer = new CoreUnsafeUtils.FixedBufferStringQueue(bufferStart, size);
  29. Assert.True(buffer.TryPush("Lorem ipsum dolor sit"));
  30. Assert.False(buffer.TryPush("amet, consectetur adipiscing"));
  31. Assert.AreEqual(1, buffer.Count);
  32. }
  33. [Test]
  34. public void PushAndPopAndClear()
  35. {
  36. const int size = 128;
  37. var bufferStart = stackalloc byte[size];
  38. var buffer = new CoreUnsafeUtils.FixedBufferStringQueue(bufferStart, size);
  39. Assert.True(buffer.TryPush("Lorem ipsum dolor sit"));
  40. Assert.True(buffer.TryPush("amet, consectetur adipiscing"));
  41. Assert.False(buffer.TryPush("elit, sed do eiusmod"));
  42. Assert.AreEqual(2, buffer.Count);
  43. buffer.Clear();
  44. Assert.AreEqual(0, buffer.Count);
  45. Assert.True(buffer.TryPush("elit, sed do eiusmod"));
  46. Assert.True(buffer.TryPush("tempor incididunt ut labore"));
  47. Assert.True(buffer.TryPop(out string v) && v == "elit, sed do eiusmod");
  48. Assert.True(buffer.TryPop(out v) && v == "tempor incididunt ut labore");
  49. }
  50. }
  51. }