test coverage and fix bugs with ascii 85 filter

This commit is contained in:
Eliot Jones
2017-12-30 13:09:46 +00:00
parent 6adc0c169d
commit 2a706af87b
3 changed files with 27 additions and 3 deletions

View File

@@ -1,5 +1,6 @@
namespace UglyToad.Pdf.Tests.Filters
{
using System;
using System.Text;
using ContentStream;
using Pdf.Filters;
@@ -29,6 +30,28 @@ O<DJ+*.@<*K0@<6L(Df-\0Ec5e;DffZ(EZee.Bl.9pF""AGXBPCsi + DGm >@3BB / F * &OCAfu2
text);
}
[Fact]
public void ReplacesZWithEmptyBytes()
{
var bytes = Encoding.ASCII.GetBytes("9jqo^zBlbD-");
var result = filter.Decode(bytes, new PdfDictionary(), 1);
var text = Encoding.ASCII.GetString(result);
Assert.Equal("Man \0\0\0\0is d", text);
}
[Fact]
public void ZInMiddleOf5CharacterSequenceThrows()
{
var bytes = Encoding.ASCII.GetBytes("qjzqo^");
Action action = () => filter.Decode(bytes, new PdfDictionary(), 0);
Assert.Throws<InvalidOperationException>(action);
}
private const string PdfContent = @"1 0 obj
<< /Length 568 >>
stream
@@ -95,5 +118,7 @@ Li?EZek1DKKT1F`2DD/TboKAKY](@:s.m/h%oBC'mC/$>""*cF*)G6@;Q?_DIdZpC&";
Assert.Equal(PdfContent.Replace("\r\n", "\n"), text);
}
}
}

View File

@@ -1,7 +1,6 @@
namespace UglyToad.Pdf.Tests.Filters
{
using System;
using System.Net.NetworkInformation;
using System.Text;
using ContentStream;
using Pdf.Filters;

View File

@@ -65,12 +65,12 @@
{
if (index > 0)
{
// Should I throw here?
throw new InvalidOperationException("Encountered z within a 5 character block");
}
for (int j = 0; j < 4; j++)
{
writer.Write(0);
writer.Write((byte)0);
}
index = 0;