예제 #1
0
        public void TestReadAttributeRawValueTruncatedStrict()
        {
            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.MessageId), 0, 4);
                stream.Write(BitConverter.GetBytes(28), 0, 4);
                stream.Write(BitConverter.GetBytes(0xFFFFFFFF), 0, 4);
                stream.Position = 0;

                using (var reader = new TnefReader(stream, 0, TnefComplianceMode.Strict)) {
                    Assert.IsTrue(reader.ReadNextAttribute(), "ReadNextAttribute");
                    Assert.AreEqual(TnefAttributeTag.MessageId, reader.AttributeTag, "AttributeTag");

                    var buffer = new byte[28];
                    int n;

                    n = reader.ReadAttributeRawValue(buffer, 0, buffer.Length);

                    try {
                        reader.ReadAttributeRawValue(buffer, n, buffer.Length - n);
                        Assert.Fail("ReadAttributeRawValue should have thrown TnefException");
                    } catch (TnefException ex) {
                        Assert.AreEqual(TnefComplianceStatus.StreamTruncated, ex.Error, "Error");
                    } catch (Exception ex) {
                        Assert.Fail("ReadAttributeRawValue should have thrown TnefException, not {0}", ex);
                    }
                }
            }
        }
예제 #2
0
        public void TestArgumentExceptions()
        {
            using (var stream = File.OpenRead(Path.Combine(DataDir, "winmail.tnef"))) {
                Assert.Throws <ArgumentNullException> (() => new TnefReader(null, 0, TnefComplianceMode.Strict));
                Assert.Throws <ArgumentOutOfRangeException> (() => new TnefReader(stream, -1, TnefComplianceMode.Strict));

                using (var reader = new TnefReader(stream, 1252, TnefComplianceMode.Strict)) {
                    var buffer = new byte[16];

                    Assert.Throws <ArgumentNullException> (() => reader.ReadAttributeRawValue(null, 0, buffer.Length));
                    Assert.Throws <ArgumentOutOfRangeException> (() => reader.ReadAttributeRawValue(buffer, -1, buffer.Length));
                    Assert.Throws <ArgumentOutOfRangeException> (() => reader.ReadAttributeRawValue(buffer, 0, -1));
                }
            }
        }
예제 #3
0
        public void TestReadAttributeRawValueTruncatedLoose()
        {
            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.MessageId), 0, 4);
                stream.Write(BitConverter.GetBytes(28), 0, 4);
                stream.Write(BitConverter.GetBytes(0xFFFFFFFF), 0, 4);
                stream.Position = 0;

                using (var reader = new TnefReader(stream, 0, TnefComplianceMode.Loose)) {
                    Assert.IsTrue(reader.ReadNextAttribute(), "ReadNextAttribute");
                    Assert.AreEqual(TnefAttributeTag.MessageId, reader.AttributeTag, "AttributeTag");

                    var buffer = new byte[28];
                    int nread, n = 0;

                    do
                    {
                        if ((nread = reader.ReadAttributeRawValue(buffer, n, buffer.Length - n)) == 0)
                        {
                            break;
                        }

                        n += nread;
                    } while (n < 28);

                    Assert.AreEqual(TnefComplianceStatus.StreamTruncated, reader.ComplianceStatus);
                }
            }
        }