private void Do(int C, int P, int M, bool noisy, bool useRAII, Func <StringBuilder, int> test) { var pool = StringBuilderPool.Create(C); void testCore(StringBuilder sb) { var len = sb.Length; Assert.AreEqual(0, len); var L = test(sb); len = sb.Length; Assert.AreEqual(L, len); } if (useRAII) { Run(() => pool.New(), o => o.StringBuilder, o => o.Dispose(), testCore, P, M, noisy); } else { Run(() => pool.Allocate(), o => o.StringBuilder, o => pool.Free(o), testCore, P, M, noisy); } }
public void PooledStringBuilder_GottenTooBig() { var bigPool = StringBuilderPool.Create(1, 16, 2048); var smallPool = StringBuilderPool.Create(1, 16, 16); TooBig(() => PooledStringBuilder.New(), h => h.StringBuilder, (h, n) => h.Append(new string('*', n)), 1024); TooBig(() => bigPool.New(), h => h.StringBuilder, (h, n) => h.Append(new string('*', n)), 2048); TooBig(() => smallPool.New(), h => h.StringBuilder, (h, n) => h.Append(new string('*', n)), 16); }
public void PooledStringBuilder_ArgumentChecking() { Assert.ThrowsException <ArgumentOutOfRangeException>(() => StringBuilderPool.Create(4, -1)); Assert.ThrowsException <ArgumentOutOfRangeException>(() => StringBuilderPool.Create(4, 16, -1)); }
public void PooledStringBuilder_Simple2() { var pool = StringBuilderPool.Create(4, 16); PooledStringBuilder_Simple_Impl(pool); }