24 lines
1.8 KiB
C#
24 lines
1.8 KiB
C#
void Check(bool b,string m){if(!b)throw new Exception(m);}
|
|
var empty=new Subject();empty.Release();empty.Release();Check(Addressables.Releases==0,"uninitialized released invalid handles");
|
|
Console.WriteLine("PASS uninitialized and repeated Release");
|
|
foreach(var partial in new[]{false,true}){
|
|
Addressables.Releases=0;var source=new CancellationTokenSource();var token=source.Token;
|
|
var pool=new Pool();var subscription=new Subscription();
|
|
var s=new Subject{poolService=pool,SoundFadeTaskDic=new(){{new Sound(),source}},mixerHandle=new Handle(true),soundPrefabHandle=new Handle(!partial),lowpassEvtDisposable=partial?null:subscription};
|
|
s.Release();Check(token.IsCancellationRequested&&s.SoundFadeTaskDic==null,"pending fade not cancelled");
|
|
Check(Addressables.Releases==(partial?1:2),"wrong released handles");
|
|
Check(subscription.Disposals==(partial?0:1),"wrong subscription cleanup");
|
|
s.Release();Check(Addressables.Releases==(partial?1:2)&&subscription.Disposals==(partial?0:1),"resource released twice");
|
|
Check(!s.mixerHandle.IsValid()&&!s.soundPrefabHandle.IsValid(),"handle not reset");
|
|
Console.WriteLine("PASS "+(partial?"partial":"initialized")+" resources and repeat cleanup");
|
|
}
|
|
public partial class Subject{
|
|
public Dictionary<Sound,CancellationTokenSource> SoundFadeTaskDic;
|
|
public Pool poolService;public Handle mixerHandle,soundPrefabHandle;public IDisposable lowpassEvtDisposable;
|
|
}
|
|
public class Sound{}
|
|
public class Pool{public void DestroyPool<T>(){}}
|
|
public struct Handle{private bool valid;public Handle(bool value){valid=value;}public bool IsValid()=>valid;}
|
|
public static class Addressables{public static int Releases;public static void Release(Handle h){if(!h.IsValid())throw new Exception("invalid handle");Releases++;}}
|
|
public class Subscription:IDisposable{public int Disposals;public void Dispose(){Disposals++;}}
|