Exemplo n.º 1
0
        public void GetStringCachingMultipleStrings()
        {
            string[] expected = new[]
            {
                "Hello",
                "hello",
                "World",
                "World ",
                "foo",
                "bar",
                "baz",
                "qux",
                "0",
                "1",
                " ",
                String.Empty,
            };
            string[] actual = new string[expected.Length];

            for (int i = 0; i < expected.Length; ++i)
            {
                byte[] buffer = Encoding.Unicode.GetBytes(expected[i]);
                actual[i] = StringCache.GetString(buffer, 0, buffer.Length);
                Assert.AreEqual(expected[i], actual[i], "First conversion is incorrect");
            }

            for (int i = 0; i < expected.Length; ++i)
            {
                byte[] buffer = Encoding.Unicode.GetBytes(expected[i]);
                string cached = StringCache.GetString(buffer, 0, buffer.Length);
                Assert.AreEqual(expected[i], cached, "Cached value is incorrect");
                Assert.AreSame(actual[i], cached, "Value {0} was not cached", expected[i]);
            }
        }
Exemplo n.º 2
0
        public void GetStringCaching()
        {
            byte[] buffer = Encoding.Unicode.GetBytes("Hello");
            string s1     = StringCache.GetString(buffer, 0, buffer.Length);
            string s2     = StringCache.GetString(buffer, 0, buffer.Length);

            Assert.AreSame(s1, s2);
        }
Exemplo n.º 3
0
        public void VerifyLongStringIsNotCached()
        {
            string expected = Any.StringOfLength(8192);

            byte[] buffer = Encoding.Unicode.GetBytes(expected);
            string actual = StringCache.GetString(buffer, 0, buffer.Length);

            Assert.AreEqual(expected, actual);
            Assert.AreNotSame(actual, StringCache.GetString(buffer, 0, buffer.Length));
        }
Exemplo n.º 4
0
 public void GetStringCachingRandomStrings()
 {
     for (int i = 0; i < 250000; ++i)
     {
         string expected = Any.String;
         byte[] buffer   = Encoding.Unicode.GetBytes(expected);
         string actual   = StringCache.GetString(buffer, 0, buffer.Length);
         Assert.AreEqual(expected, actual);
         Assert.AreSame(actual, StringCache.GetString(buffer, 0, buffer.Length));
     }
 }
Exemplo n.º 5
0
 public void GetString()
 {
     byte[] buffer = Encoding.Unicode.GetBytes("Hello");
     Assert.AreEqual("Hello", StringCache.GetString(buffer, 0, buffer.Length));
 }
Exemplo n.º 6
0
 public void GetStringWithNull()
 {
     byte[] buffer = null;
     Assert.AreEqual(String.Empty, StringCache.GetString(buffer, 0, 0));
 }