Esempio n. 1
0
        public async Task Serialization()
        {
            var st = new StringTable();
            var pt = new PathTable(st);

            string path1 = A("c", "a", "b", "c");
            var    ap1   = AbsolutePath.Create(pt, path1);
            string path2 = A("c", "d", "c", "a");
            var    ap2   = AbsolutePath.Create(pt, path2);

            string path3 = A("d", "a", "c", "a");
            var    ap3   = AbsolutePath.Create(pt, path3);

            string path3Caps = A("D", "A", "c", "a");
            var    ap3Caps   = AbsolutePath.Create(pt, path3Caps);

            PathTable pt2;

            using (MemoryStream ms = new MemoryStream())
            {
                using (BuildXLWriter writer = new BuildXLWriter(true, ms, true, logStats: true))
                {
                    pt.Serialize(writer);
                }

                ms.Position = 0;

                using (BuildXLReader reader = new BuildXLReader(true, ms, true))
                {
                    pt2 = await PathTable.DeserializeAsync(reader, Task.FromResult(st));
                }
            }

            // Retrieve AbsolutePaths created with the original table from the deserialized one
            XAssert.AreEqual(path1, ap1.ToString(pt));
            XAssert.AreEqual(path1, ap1.ToString(pt2));
            XAssert.AreEqual(path2, ap2.ToString(pt2));
            XAssert.AreEqual(path3, ap3.ToString(pt2));

            // Recreate the paths and make sure they match the originals
            var ap1Recreated     = AbsolutePath.Create(pt2, path1);
            var ap2Recreated     = AbsolutePath.Create(pt2, path2);
            var ap3Recreated     = AbsolutePath.Create(pt2, path3);
            var ap3CapsRecreated = AbsolutePath.Create(pt2, path3Caps);

            XAssert.AreEqual(ap1, ap1Recreated);
            XAssert.AreEqual(ap2, ap2Recreated);
            XAssert.AreEqual(ap3, ap3Recreated);
            XAssert.AreEqual(ap3, ap3CapsRecreated);

            // Make sure a new path can be added
            string path4 = A("c", "a", "s", "d");
            var    ap4   = AbsolutePath.Create(pt2, path4);

            XAssert.AreEqual(path4, ap4.ToString(pt2));
        }
Esempio n. 2
0
        public async Task EmptySerialization()
        {
            var st = new StringTable();
            var pt = new PathTable(st);

            PathTable pt2;

            using (MemoryStream ms = new MemoryStream())
            {
                using (BuildXLWriter writer = new BuildXLWriter(true, ms, true, logStats: true))
                {
                    pt.Serialize(writer);
                }

                ms.Position = 0;

                using (BuildXLReader reader = new BuildXLReader(true, ms, true))
                {
                    pt2 = await PathTable.DeserializeAsync(reader, Task.FromResult(st));
                }
            }

            XAssert.AreEqual(pt.Count, pt2.Count);
        }
Esempio n. 3
0
        public async Task Serialization_Bug695424()
        {
            var st = new StringTable();
            var pt = new PathTable(st);
            ConcurrentBigSet <AbsolutePath> paths = new ConcurrentBigSet <AbsolutePath>();
            List <string> pathStrings             = new List <string>();

            int max = 32769;

            StringBuilder builder = new StringBuilder();

            builder.Append(A("c", "i"));
            var length = builder.Length;

            for (int i = 0; i < 100; i++)
            {
                builder.Length = length;
                builder.Append(i);
                builder.Append('\\');

                var jLength = builder.Length;
                for (int j = 0; j < 10; j++)
                {
                    builder.Length = jLength;
                    builder.Append('j');
                    builder.Append(j);
                    builder.Append('\\');

                    var kLenght = builder.Length;
                    for (int k = 0; k < 66; k++)
                    {
                        builder.Length = kLenght;
                        builder.Append('k');
                        builder.Append(k);
                        builder.Append('\\');
                        if (pt.Count < max)
                        {
                            paths.Add(AbsolutePath.Create(pt, builder.ToString()));
                        }
                        else
                        {
                            pathStrings.Add(builder.ToString());
                        }
                    }
                }
            }

            PathTable pt2;

            using (MemoryStream ms = new MemoryStream())
            {
                using (BuildXLWriter writer = new BuildXLWriter(true, ms, true, logStats: true))
                {
                    pt.Serialize(writer);
                }

                ms.Position = 0;

                using (BuildXLReader reader = new BuildXLReader(true, ms, true))
                {
                    pt2 = await PathTable.DeserializeAsync(reader, Task.FromResult(st));
                }
            }

            foreach (var pathString in pathStrings)
            {
                AbsolutePath.Create(pt2, pathString);
            }

            foreach (var path in paths.UnsafeGetList())
            {
                var pathString = path.ToString(pt).ToUpperInvariant();
                var path2      = AbsolutePath.Create(pt2, pathString);
                XAssert.AreEqual(path, path2);
            }
        }