public void T010_AddObjects() { TestHelpers.InMethod(); random = new Random(); SceneObjectGroup found; EntityManager entman = new EntityManager(); SceneObjectGroup sog = NewSOG(); UUID obj1 = sog.UUID; uint li1 = sog.LocalId; entman.Add(sog); sog = NewSOG(); UUID obj2 = sog.UUID; uint li2 = sog.LocalId; entman.Add(sog); found = (SceneObjectGroup)entman[obj1]; Assert.That(found.UUID ,Is.EqualTo(obj1)); found = (SceneObjectGroup)entman[li1]; Assert.That(found.UUID ,Is.EqualTo(obj1)); found = (SceneObjectGroup)entman[obj2]; Assert.That(found.UUID ,Is.EqualTo(obj2)); found = (SceneObjectGroup)entman[li2]; Assert.That(found.UUID ,Is.EqualTo(obj2)); entman.Remove(obj1); entman.Remove(li2); Assert.That(entman.ContainsKey(obj1), Is.False); Assert.That(entman.ContainsKey(li1), Is.False); Assert.That(entman.ContainsKey(obj2), Is.False); Assert.That(entman.ContainsKey(li2), Is.False); }
public void T011_ThreadAddRemoveTest() { TestHelpers.InMethod(); // This test adds and removes with mutiple threads, attempting to break the // uuid and localid dictionary coherence. EntityManager entman = new EntityManager(); SceneObjectGroup sog = NewSOG(); for (int j=0; j<20; j++) { List<Thread> trdlist = new List<Thread>(); for (int i=0; i<4; i++) { // Adds scene object NewTestThreads test = new NewTestThreads(entman,sog); Thread start = new Thread(new ThreadStart(test.TestAddSceneObject)); start.Start(); trdlist.Add(start); // Removes it test = new NewTestThreads(entman,sog); start = new Thread(new ThreadStart(test.TestRemoveSceneObject)); start.Start(); trdlist.Add(start); } foreach (Thread thread in trdlist) { thread.Join(); } if (entman.ContainsKey(sog.UUID) || entman.ContainsKey(sog.LocalId)) { found = (SceneObjectGroup)entman[sog.UUID]; Assert.That(found.UUID,Is.EqualTo(sog.UUID)); found = (SceneObjectGroup)entman[sog.LocalId]; Assert.That(found.UUID,Is.EqualTo(sog.UUID)); } } }
public NewTestThreads(EntityManager entman, SceneObjectGroup sog) { this.entman = entman; this.sog = sog; this.random = new Random(); }