}
}
- class Key { public int Foo; }
- class Val { public int Foo; }
+ class Key {
+ public int Foo;
+ public override string ToString () {
+ return "key-" + Foo;
+ }
+ }
+
+ class Val {
+ public int Foo;
+ public override string ToString () {
+ return "value-" + Foo;
+ }
+ }
+
[Test]
public void GetValue () {
public void OldGenKeysMakeNewGenObjectsReachable ()
{
if (GC.MaxGeneration == 0) /*Boehm doesn't handle ephemerons */
- return;
+ return;
ConditionalWeakTable<object, Val> table = new ConditionalWeakTable<object, Val>();
List<Key> keys = new List<Key>();
// should be collected ever.
//
for (int x = 0; x < 1000; x++)
- keys.Add(new Key() { Foo = x });
+ keys.Add (new Key () { Foo = x });
- for (int i = 0; i < 10000; ++i) {
+ for (int i = 0; i < 1000; ++i) {
// Insert all keys into the ConditionalWeakTable
foreach (var key in keys)
- table.Add(key, new Val() { Foo = key.Foo });
+ table.Add (key, new Val () { Foo = key.Foo });
// Look up all keys to verify that they are still there
Val val;
foreach (var key in keys)
- Assert.IsTrue (table.TryGetValue(key, out val), "#1-" + i);
+ Assert.IsTrue (table.TryGetValue (key, out val), "#1-" + i + "-k-" + key);
// Remove all keys from the ConditionalWeakTable
foreach (var key in keys)
- Assert.IsTrue (!table.Remove(key), "#2-" + i);
+ Assert.IsTrue (table.Remove (key), "#2-" + i + "-k-" + key);
}
}
}