forked from mirror/DotRecast
fix: SOH issue (#41)
- https://github.com/ikpil/DotRecast/issues/41#issuecomment-1908365394
This commit is contained in:
parent
b0644a70b7
commit
0c6921ad6b
|
@ -1,6 +1,9 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Xml;
|
||||||
using DotRecast.Core.Buffers;
|
using DotRecast.Core.Buffers;
|
||||||
|
using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Serialization;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
|
||||||
namespace DotRecast.Core.Test;
|
namespace DotRecast.Core.Test;
|
||||||
|
@ -56,4 +59,50 @@ public class RcRentedArrayTest
|
||||||
Assert.Throws<NullReferenceException>(() => rentedArray[^1] = 0);
|
Assert.Throws<NullReferenceException>(() => rentedArray[^1] = 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestSame()
|
||||||
|
{
|
||||||
|
// not same
|
||||||
|
{
|
||||||
|
using var r1 = RcRentedArray.RentDisposableArray<float>(1024);
|
||||||
|
using var r2 = RcRentedArray.RentDisposableArray<float>(1024);
|
||||||
|
|
||||||
|
Assert.That(r2.AsRentedArray() != r1.AsRentedArray(), Is.EqualTo(true));
|
||||||
|
}
|
||||||
|
|
||||||
|
// same
|
||||||
|
{
|
||||||
|
// error case
|
||||||
|
float[] r1Array;
|
||||||
|
using (var r1 = RcRentedArray.RentDisposableArray<float>(1024))
|
||||||
|
{
|
||||||
|
r1Array = r1.AsRentedArray();
|
||||||
|
for (int i = 0; i < r1.Length; ++i)
|
||||||
|
{
|
||||||
|
r1[i] = 123;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
using var r2 = RcRentedArray.RentDisposableArray<float>(1024);
|
||||||
|
|
||||||
|
Assert.That(r2.AsRentedArray() == r1Array, Is.EqualTo(true));
|
||||||
|
Assert.That(r2.AsRentedArray().Sum(), Is.EqualTo(0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestDispose()
|
||||||
|
{
|
||||||
|
var r1 = RcRentedArray.RentDisposableArray<float>(1024);
|
||||||
|
for (int i = 0; i < r1.Length; ++i)
|
||||||
|
{
|
||||||
|
r1[i] = 123;
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.That(r1.IsDisposed, Is.EqualTo(false));
|
||||||
|
r1.Dispose();
|
||||||
|
Assert.That(r1.IsDisposed, Is.EqualTo(true));
|
||||||
|
Assert.That(r1.AsRentedArray(), Is.Null);
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue