Esempio n. 1
0
        public void TestSkip([Values(0u, 1u, 4u, 18u)] uint amount,
                             [Values(false, true)] bool useSharpZipLib)
        {
            string zipfile = Path.Combine(Application.dataPath, "Editor/Tests/TestData/data.zip");
            uint   a, b;

            // Skip forward, then read
            using (Stream instream = GetReadStream(zipfile, "data.bin", useSharpZipLib))
            {
                SketchBinaryReader reader = new SketchBinaryReader(instream);
                reader.UInt32(); // start test at non-zero offset
                bool ok = reader.Skip(amount);
                Assert.IsTrue(ok);
                a = reader.UInt32();
            }

            // Read forward, then read
            using (Stream instream = GetReadStream(zipfile, "data.bin", useSharpZipLib))
            {
                SketchBinaryReader reader = new SketchBinaryReader(instream);
                byte[]             buf    = new byte[amount + 4];
                instream.Read(buf, 0, buf.Length);
                b = reader.UInt32();
            }

            Assert.AreEqual(a, b);
        }
Esempio n. 2
0
        public void TestListRoundTrip()
        {
            // Test a list going into and out of the stream.
            List <Vector3> lst = MathTestUtils.RandomVector3List(20);

            MemoryStream stream = new MemoryStream();

            using (var writer = new SketchBinaryWriter(stream)) {
                writer.WriteLengthPrefixed(lst);
                writer.BaseStream = null;
            }

            stream.Position = 0;
            List <Vector3> lst2 = new List <Vector3>();

            using (var reader = new SketchBinaryReader(stream)) {
                Assert.IsTrue(reader.ReadIntoExact(lst2, lst.Count));
            }
            Assert.AreEqual(lst, lst2);
        }
Esempio n. 3
0
        public void TestBaseStream()
        {
            // Quick test that BaseStream works as advertised

            MemoryStream stream = new MemoryStream();

            using (var writer = new SketchBinaryWriter(null)) {
                writer.BaseStream = stream;
                writer.Int32(12);
                Assert.IsTrue(stream.Position == 4);
                writer.BaseStream = null;
                Assert.Catch <Exception>(() => writer.Int32(12));
            }

            stream.Position = 0;
            using (var reader = new SketchBinaryReader(null)) {
                reader.BaseStream = stream;
                Assert.AreEqual(12, reader.Int32());
                reader.BaseStream = null;
                Assert.Catch <Exception>(() => reader.Int32());
            }
        }