Esempio n. 1
0
        public void BinaryStringRoundrip()
        {
            var st = new StringTable();
            var unicodeStringId = st.AddString("繙B");
            var asciiStringId   = st.AddString("Hello");

            var binaryUnicodeString = st.GetBinaryString(unicodeStringId);
            var binaryAsciiString   = st.GetBinaryString(asciiStringId);

            var roundTrippedUnicodeStringId = st.AddString(binaryUnicodeString);
            var roundTrippedAsciiStringId   = st.AddString(binaryAsciiString);

            XAssert.AreEqual(unicodeStringId, roundTrippedUnicodeStringId);
            XAssert.AreEqual(asciiStringId, roundTrippedAsciiStringId);
        }
Esempio n. 2
0
            public async Task RunCommonTestsAsync()
            {
                XAssert.AreNotEqual(StringTable.Count, AddedStrings.Count, "Ensure strings are added through harness");

                StringTable deserializedStringTable = null;

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

                    if (MaxSize < StringTable.BytesPerBuffer)
                    {
                        XAssert.IsTrue(ms.Position < StringTable.BytesPerBuffer,
                                       "Small StringTable should not serialize a full empty byte buffer.");
                    }

                    ms.Position = 0;

                    using (BuildXLReader reader = new BuildXLReader(true, ms, true))
                    {
                        deserializedStringTable = await StringTable.DeserializeAsync(reader);
                    }
                }

                foreach (var entry in AddedStrings)
                {
                    // Test deserialization behaviors
                    XAssert.AreEqual(entry.Value.Length, deserializedStringTable.GetLength(entry.Key));
                    XAssert.AreEqual(entry.Value.Length, deserializedStringTable.GetBinaryString(entry.Key).Length);
                    XAssert.AreEqual(entry.Value, deserializedStringTable.GetString(entry.Key));
                    XAssert.AreEqual(entry.Key, deserializedStringTable.AddString(entry.Value));

                    // Test original string table behaviors
                    XAssert.AreEqual(entry.Key, StringTable.AddString(entry.Value));
                    XAssert.AreEqual(entry.Value.Length, StringTable.GetLength(entry.Key));
                    XAssert.AreEqual(entry.Value.Length, StringTable.GetBinaryString(entry.Key).Length);
                    XAssert.AreEqual(entry.Value, StringTable.GetString(entry.Key));
                }
            }
Esempio n. 3
0
            public async Task RunCommonTestsAsync()
            {
                XAssert.AreNotEqual(StringTable.Count, AddedStrings.Count, "Ensure strings are added through harness");

                StringTable deserializedStringTable = null;

                using (MemoryStream ms = new MemoryStream())
                {
                    using (Stream stream = createWrapperStream(ms, compress: true))
                    {
                        using (BuildXLWriter writer = new BuildXLWriter(true, stream, true, logStats: true))
                        {
                            StringTable.Serialize(writer);
                        }

                        if (MaxSize < StringTable.BytesPerBuffer)
                        {
                            XAssert.IsTrue(stream.Position < StringTable.BytesPerBuffer,
                                           "Small StringTable should not serialize a full empty byte buffer.");
                        }
                    }

                    // We can't set a position on a wrapper stream, setting it for the memory stream that contains the data.
                    using (MemoryStream ms2 = new MemoryStream(ms.ToArray()))
                        using (Stream readStream = createWrapperStream(ms2, compress: false))
                            using (BuildXLReader reader = new BuildXLReader(true, readStream, true))
                            {
                                deserializedStringTable = await StringTable.DeserializeAsync(reader);
                            }
                }

                foreach (var entry in AddedStrings)
                {
                    // Test deserialization behaviors
                    XAssert.AreEqual(entry.Value.Length, deserializedStringTable.GetLength(entry.Key));
                    XAssert.AreEqual(entry.Value.Length, deserializedStringTable.GetBinaryString(entry.Key).Length);
                    XAssert.AreEqual(entry.Value, deserializedStringTable.GetString(entry.Key));
                    XAssert.AreEqual(entry.Key, deserializedStringTable.AddString(entry.Value));

                    // Test original string table behaviors
                    XAssert.AreEqual(entry.Key, StringTable.AddString(entry.Value));
                    XAssert.AreEqual(entry.Value.Length, StringTable.GetLength(entry.Key));
                    XAssert.AreEqual(entry.Value.Length, StringTable.GetBinaryString(entry.Key).Length);
                    XAssert.AreEqual(entry.Value, StringTable.GetString(entry.Key));
                }

                Stream createWrapperStream(MemoryStream memoryStream, bool compress)
                {
                    if (m_useDeflateStream)
                    {
                        return(new TrackedStream(
                                   new BufferedStream(
                                       compress ? new DeflateStream(memoryStream, CompressionLevel.Fastest, leaveOpen: true)
                                : new DeflateStream(memoryStream, CompressionMode.Decompress, leaveOpen: true),
                                       bufferSize: 64 << 10),
                                   // Need to close the underlying stream to flush the content.
                                   leaveOpen: false));
                    }

                    return(memoryStream);
                }
            }