public void AddNewReference() { ConcurrentDictionary <string, int> refCountByName = new ConcurrentDictionary <string, int>(); ReferenceCounting.AddReference(refCountByName, "memes"); Assert.AreEqual(1, refCountByName["memes"]); }
public void EmptyDictionary() { ConcurrentDictionary <string, int> refCountByName = new ConcurrentDictionary <string, int>(); HashSet <string> namesWithNoReferences = ReferenceCounting.GetObjectsWithNoReferences(refCountByName); Assert.AreEqual(0, namesWithNoReferences.Count); }
public void DecrementExistingReference() { ConcurrentDictionary <string, int> refCountByName = new ConcurrentDictionary <string, int>(); ReferenceCounting.IncrementReference(refCountByName, "memes"); ReferenceCounting.DecrementReference(refCountByName, "memes"); Assert.AreEqual(0, refCountByName["memes"]); }
public void TryDecrementInvalidReference() { // Doesn't throw exception. ConcurrentDictionary <string, int> refCountByName = new ConcurrentDictionary <string, int>(); ReferenceCounting.DecrementReference(refCountByName, "memes"); Assert.IsFalse(refCountByName.ContainsKey("memes")); }
public void DecrementZeroReference() { var refCountByName = new ConcurrentDictionary <string, int>(); ReferenceCounting.AddReference(refCountByName, "memes"); ReferenceCounting.RemoveReference(refCountByName, "memes"); ReferenceCounting.RemoveReference(refCountByName, "memes"); Assert.AreEqual(0, refCountByName["memes"]); }
public void OneObjectWithNoReferences() { ConcurrentDictionary <string, int> refCountByName = new ConcurrentDictionary <string, int>(); refCountByName.TryAdd("a", 1); refCountByName.TryAdd("b", 0); refCountByName.TryAdd("c", 1); HashSet <string> namesWithNoReferences = ReferenceCounting.GetObjectsWithNoReferences(refCountByName); Assert.AreEqual(1, namesWithNoReferences.Count); Assert.IsTrue(namesWithNoReferences.Contains("b")); }
public void DuplicateObjecstWithNoReferences() { ConcurrentDictionary <string, int> refCountByName = new ConcurrentDictionary <string, int>(); refCountByName.TryAdd("a", 0); refCountByName.TryAdd("a", 0); refCountByName.TryAdd("a", 0); // Names are unique, so there is no need to delete an OpenGL object more than once. HashSet <string> namesWithNoReferences = ReferenceCounting.GetObjectsWithNoReferences(refCountByName); Assert.AreEqual(1, namesWithNoReferences.Count); Assert.IsTrue(namesWithNoReferences.Contains("a")); }
/// <summary> /// Increments the reference count and initializes <see cref="Id"/>. /// </summary> public GLObject(int id) { // We need a constructor to set the readonly field and preserve polymorphic behavior. Id = id; ReferenceCounting.IncrementReference(GLObjectManager.referenceCountByGLObject, new Tuple <GLObjectType, int>(ObjectType, Id)); }