예제 #1
0
        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);
            }
        }
예제 #2
0
        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);
        }
예제 #3
0
 public void PooledStringBuilder_ArgumentChecking()
 {
     Assert.ThrowsException <ArgumentOutOfRangeException>(() => StringBuilderPool.Create(4, -1));
     Assert.ThrowsException <ArgumentOutOfRangeException>(() => StringBuilderPool.Create(4, 16, -1));
 }
예제 #4
0
        public void PooledStringBuilder_Simple2()
        {
            var pool = StringBuilderPool.Create(4, 16);

            PooledStringBuilder_Simple_Impl(pool);
        }