public void AsyncOperationHandle_Release_DecrementsRefCount() { int expectedCount = 10; var op = new FakeTypedOperation(); AsyncOperationHandle <GameObject> typedHandle = new AsyncOperationHandle <GameObject>(op); AsyncOperationHandle <GameObject> validationHandle = new AsyncOperationHandle <GameObject>(op); IncreaseRefCount(typedHandle, expectedCount - 1); typedHandle.Release(); expectedCount--; var actualRefCount = DestructiveGetRefCount(validationHandle); Assert.AreEqual(expectedCount, actualRefCount); op = new FakeTypedOperation(); AsyncOperationHandle typelessHandle = new AsyncOperationHandle(op); AsyncOperationHandle typelessValidation = new AsyncOperationHandle(op); IncreaseRefCount(typelessHandle, expectedCount - 1); typelessHandle.Release(); expectedCount--; actualRefCount = DestructiveGetRefCount(typelessValidation); Assert.AreEqual(expectedCount, actualRefCount); }
public void AsyncOperationHandle_ConvertToTyped_WithValidOpSucceeds() { var op = new FakeTypedOperation(); AsyncOperationHandle handle = new AsyncOperationHandle(op); AsyncOperationHandle <GameObject> typedHandle = handle.Convert <GameObject>(); Assert.True(handle.IsValid()); Assert.True(typedHandle.IsValid()); }
public void AsyncOperationHandle_ConvertToTyped_WithInvalidOpThrows() { var op = new FakeTypedOperation(); AsyncOperationHandle handle = new AsyncOperationHandle(op); AsyncOperationHandle handle2 = new AsyncOperationHandle(op); handle2.Release(); Assert.Throws <Exception>(() => { handle.Convert <GameObject>(); }); }
public void AsyncOperationHandle_ReleaseToZero_InvalidatesAllHandles() { var op = new FakeTypedOperation(); AsyncOperationHandle <GameObject> typedHandle = new AsyncOperationHandle <GameObject>(op); AsyncOperationHandle <GameObject> typedHandle2 = new AsyncOperationHandle <GameObject>(op); typedHandle.Release(); Assert.IsFalse(typedHandle.IsValid()); Assert.IsFalse(typedHandle2.IsValid()); op = new FakeTypedOperation(); AsyncOperationHandle typelessHandle = new AsyncOperationHandle(op); AsyncOperationHandle typelessHandle2 = new AsyncOperationHandle(op); typelessHandle.Release(); Assert.IsFalse(typelessHandle.IsValid()); Assert.IsFalse(typelessHandle2.IsValid()); }
public void AsyncOperationHandle_ReleaseToNonZero_InvalidatesOnlyCurrentHandle() { var op = new FakeTypedOperation(); AsyncOperationHandle <GameObject> typedHandle = new AsyncOperationHandle <GameObject>(op); IncreaseRefCount(typedHandle, 1); AsyncOperationHandle <GameObject> typedHandle2 = new AsyncOperationHandle <GameObject>(op); typedHandle.Release(); Assert.IsFalse(typedHandle.IsValid()); Assert.IsTrue(typedHandle2.IsValid()); op = new FakeTypedOperation(); AsyncOperationHandle typelessHandle = new AsyncOperationHandle(op); IncreaseRefCount(typelessHandle, 1); AsyncOperationHandle typelessHandle2 = new AsyncOperationHandle(op); typelessHandle.Release(); Assert.IsFalse(typelessHandle.IsValid()); Assert.IsTrue(typelessHandle2.IsValid()); }
public void AsyncOperationHandle_Acquire_IncrementsRefCount() { int expectedCount = 2; var op = new FakeTypedOperation(); AsyncOperationHandle <GameObject> typedHandle = new AsyncOperationHandle <GameObject>(op); var copyTyped = typedHandle.Acquire(); Assert.True(copyTyped.IsValid()); Assert.True(typedHandle.IsValid()); int actualCount = DestructiveGetRefCount(typedHandle); Assert.AreEqual(expectedCount, actualCount); op = new FakeTypedOperation(); AsyncOperationHandle typelessHandle = new AsyncOperationHandle(op); var copyTypeless = typelessHandle.Acquire(); Assert.True(copyTypeless.IsValid()); Assert.True(typelessHandle.IsValid()); actualCount = DestructiveGetRefCount(typelessHandle); Assert.AreEqual(expectedCount, actualCount); }
public void AsyncOperationHandle_ConvertToTypeless_MaintainsValidity() { var op = new FakeTypedOperation(); AsyncOperationHandle <GameObject> typedHandle = new AsyncOperationHandle <GameObject>(op); //implicit conversion of valid op AsyncOperationHandle typelessHandle = (AsyncOperationHandle)typedHandle; Assert.IsNotNull(typelessHandle); Assert.IsTrue(typedHandle.IsValid()); Assert.IsTrue(typelessHandle.IsValid()); //make handle invalid AsyncOperationHandle <GameObject> typedHandle2 = new AsyncOperationHandle <GameObject>(op); typedHandle2.Release(); //implicit conversion of invalid op AsyncOperationHandle invalidHandle = (AsyncOperationHandle)typedHandle; Assert.IsNotNull(invalidHandle); Assert.IsFalse(invalidHandle.IsValid()); Assert.IsFalse(typedHandle.IsValid()); }