Exemplo n.º 1
0
        public void TestSeekTruncatedStrict()
        {
            using (var stream = new MemoryStream()) {
                stream.Write(BitConverter.GetBytes(0x223e9f78), 0, 4);
                stream.WriteByte(0);
                stream.WriteByte(0);
                stream.WriteByte((byte)TnefAttributeLevel.Message);
                stream.Write(BitConverter.GetBytes((int)TnefAttributeTag.TnefVersion), 0, 4);
                stream.Write(BitConverter.GetBytes(4), 0, 4);
                stream.Write(BitConverter.GetBytes(65536), 0, 4);
                stream.WriteByte((byte)TnefAttributeLevel.Message);
                stream.Write(BitConverter.GetBytes((int)TnefAttributeTag.OemCodepage), 0, 4);
                stream.Write(BitConverter.GetBytes(4), 0, 4);
                stream.Write(BitConverter.GetBytes(28591), 0, 4);
                stream.Position = 0;

                using (var reader = new TnefReader(stream, 0, TnefComplianceMode.Strict)) {
                    try {
                        reader.Seek(64);
                        Assert.Fail("Seek should have thrown TnefException");
                    } catch (TnefException ex) {
                        Assert.AreEqual(TnefComplianceStatus.StreamTruncated, ex.Error, "Error");
                    } catch (Exception ex) {
                        Assert.Fail("Seek should have thrown TnefException, not {0}", ex);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void TestSeekTruncatedLoose()
        {
            using (var stream = new MemoryStream()) {
                stream.Write(BitConverter.GetBytes(0x223e9f78), 0, 4);
                stream.WriteByte(0);
                stream.WriteByte(0);
                stream.WriteByte((byte)TnefAttributeLevel.Message);
                stream.Write(BitConverter.GetBytes((int)TnefAttributeTag.TnefVersion), 0, 4);
                stream.Write(BitConverter.GetBytes(4), 0, 4);
                stream.Write(BitConverter.GetBytes(65536), 0, 4);
                stream.WriteByte((byte)TnefAttributeLevel.Message);
                stream.Write(BitConverter.GetBytes((int)TnefAttributeTag.OemCodepage), 0, 4);
                stream.Write(BitConverter.GetBytes(4), 0, 4);
                stream.Write(BitConverter.GetBytes(28591), 0, 4);
                stream.Position = 0;

                using (var reader = new TnefReader(stream, 0, TnefComplianceMode.Loose)) {
                    Assert.IsFalse(reader.Seek(64), "Seek");
                    Assert.AreEqual(TnefComplianceStatus.StreamTruncated, reader.ComplianceStatus);
                }
            }
        }