Skip to content

Commit 7a8cfb6

Browse files
authored
Merge pull request #65 from nissl-lab/ReadStreamSupport
Read stream support
2 parents fd6b17b + c62cf18 commit 7a8cfb6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+622
-222
lines changed

Toxy.Test/AudioParserTest.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,13 @@ public void TestParseFlac()
6666
ToxyMetadata x = parser.Parse();
6767
ClassicAssert.AreEqual(16, x.Count);
6868
}
69+
[Test]
70+
public void TestStreamFromAudioMetadataParser()
71+
{
72+
ParserContext context = new ParserContext(TestDataSample.GetFileStream("sample.flac", "Audio"));
73+
var parser = ParserFactory.CreateMetadata(context);
74+
var result = parser.Parse();
75+
ClassicAssert.AreEqual(16, result.Count);
76+
}
6977
}
7078
}

Toxy.Test/CsvParserTest.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using NUnit.Framework.Legacy;
33
using System;
44
using System.Collections.Generic;
5+
using System.IO;
56
using System.Linq;
67
using System.Text;
78

@@ -46,6 +47,12 @@ public void TestParseIndexOutOfRange()
4647
ClassicAssert.IsTrue(ex.Message.Contains("CSV only has one table"));
4748
}
4849
}
50+
[Test]
51+
public void TestStreamForCsvSpreadsheetParser()
52+
{
53+
ParserContext context = new ParserContext(TestDataSample.GetFileStream("countrylist.csv", null));
54+
Assert.Throws<InvalidDataException>(() => { var parser = ParserFactory.CreateSpreadsheet(context); });
55+
}
4956
}
5057
}
5158

Toxy.Test/EmlEmailParserTest.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using NUnit.Framework.Legacy;
33
using System;
44
using System.Collections.Generic;
5+
using System.IO;
56
using System.Linq;
67
using System.Text;
78

@@ -29,5 +30,17 @@ public void ReadEmlTest()
2930
ClassicAssert.IsNull(email.HtmlBody);
3031

3132
}
33+
[Test]
34+
public void TestStreamForEmlTextParser()
35+
{
36+
ParserContext context = new ParserContext(TestDataSample.GetFileStream("test.eml", "Email"));
37+
Assert.Throws<InvalidDataException>(() => { var parser = ParserFactory.CreateText(context); });
38+
}
39+
[Test]
40+
public void TestStreamForEmlEmailParser()
41+
{
42+
ParserContext context = new ParserContext(TestDataSample.GetFileStream("test.eml", "Email"));
43+
Assert.Throws<InvalidDataException>(() => { var parser = ParserFactory.CreateEmail(context); });
44+
}
3245
}
3346
}

Toxy.Test/Excel2003ParserTest.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ public void TestExcelWithComments()
6363
base.BaseTestExcelComment("comments.xls");
6464
}
6565
[Test]
66+
public void TestStreamForSpreadsheetParser()
67+
{
68+
TestStreamForSpreadsheetParser("Employee.xls");
69+
}
70+
[Test]
6671
public void TestEncryptedExcel()
6772
{
6873
try

Toxy.Test/Excel2007ParserTest.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ public void TestParseSheetIndexOutOfRange()
6565
}
6666
}
6767
[Test]
68+
public void TestStreamForSpreadsheetParser()
69+
{
70+
base.TestStreamForSpreadsheetParser("Formatting.xlsx");
71+
}
72+
[Test]
6873
public void TestEncryptedExcel()
6974
{
7075
try

Toxy.Test/ExcelParserBaseTest.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using NUnit.Framework;
1+
using DocumentFormat.OpenXml.Math;
2+
using MathNet.Numerics.LinearAlgebra;
3+
using NUnit.Framework;
24
using NUnit.Framework.Legacy;
35
using System;
46

@@ -214,6 +216,11 @@ public void BaseTestExcelFormatedString(string filename)
214216
ClassicAssert.AreEqual("10.5", ss.Tables[0][11][1].ToString());
215217
ClassicAssert.AreEqual("£10.52", ss.Tables[0][12][1].ToString());
216218
}
219+
220+
public void TestStreamForSpreadsheetParser(string filename)
221+
{
222+
ParserContext context = new ParserContext(TestDataSample.GetFileStream(filename,"Excel"));
223+
}
217224
public void TestEncryptedExcel(string filename)
218225
{
219226
ParserContext context = new ParserContext(TestDataSample.GetExcelPath(filename));

Toxy.Test/ExcelTextParserTest.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using NUnit.Framework;
1+
using NPOI.HPSF;
2+
using NUnit.Framework;
23
using NUnit.Framework.Legacy;
34

45
namespace Toxy.Test
@@ -61,5 +62,13 @@ public void TestExcel2007TextParserWithHeaderFooter()
6162
ClassicAssert.IsNotNull(result);
6263
ClassicAssert.IsTrue(result.IndexOf("This is the header") > 0);
6364
}
65+
66+
[Test]
67+
public void TestStreamForTextParser()
68+
{
69+
ParserContext context = new ParserContext(TestDataSample.GetFileStream("WithVariousData.xlsx", "Excel"));
70+
var parser = ParserFactory.CreateText(context);
71+
var result = parser.Parse();
72+
}
6473
}
6574
}

Toxy.Test/ImageParserTest.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ public void TestParseTiff()
7676
ClassicAssert.AreEqual("+150", x.Get("Tint").Value);
7777
ClassicAssert.AreEqual("5", x.Get("Shadows").Value);
7878
}
79-
79+
80+
[Test]
81+
public void TestStreamFromImageMetadataParser()
82+
{
83+
ParserContext context = new ParserContext(TestDataSample.GetFileStream("sample_gimp.tiff", "Image"));
84+
var parser = ParserFactory.CreateMetadata(context);
85+
var result = parser.Parse();
86+
ClassicAssert.AreEqual(97, result.Count);
87+
}
88+
8089
}
8190
}

Toxy.Test/MsgEmailParserTest.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using NUnit.Framework;
1+
using DocumentFormat.OpenXml.Office.Y2022.FeaturePropertyBag;
2+
using NUnit.Framework;
23
using NUnit.Framework.Legacy;
34

45
namespace Toxy.Test
@@ -38,9 +39,6 @@ public void PureTextMsg_ReadTextTest()
3839
[Test]
3940
public void HtmlMsg_ReadMsgEntityTest()
4041
{
41-
//patch for 'No data is available for encoding 936'
42-
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
43-
4442
string path = TestDataSample.GetEmailPath("Azure pricing and services updates.msg");
4543
ParserContext context = new ParserContext(path);
4644
var parser = ParserFactory.CreateEmail(context);
@@ -57,5 +55,19 @@ public void HtmlMsg_ReadMsgEntityTest()
5755
ClassicAssert.IsNotNull(result.TextBody);
5856
ClassicAssert.IsNotNull(result.HtmlBody);
5957
}
58+
[Test]
59+
public void TestStreamForMsgTextParser()
60+
{
61+
ParserContext context = new ParserContext(TestDataSample.GetFileStream("raw text mail demo.msg", "Email"));
62+
var parser = ParserFactory.CreateText(context);
63+
string result = parser.Parse();
64+
}
65+
[Test]
66+
public void TestStreamForMsgEmailParser()
67+
{
68+
ParserContext context = new ParserContext(TestDataSample.GetFileStream("raw text mail demo.msg", "Email"));
69+
var parser = ParserFactory.CreateEmail(context);
70+
var result = parser.Parse();
71+
}
6072
}
6173
}

Toxy.Test/OLE2MetadataParserTest.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,19 @@ public void TestSolidWorksFile()
7171
ClassicAssert.AreEqual("{F29F85E0-4FF9-1068-AB91-08002B27B3D9}", x.Get("ClassID").Value);
7272
ClassicAssert.AreEqual("scj", x.Get("LastAuthor").Value);
7373
}
74+
75+
[Test]
76+
public void TestStreamFromOLE2()
77+
{
78+
ParserContext context = new ParserContext(TestDataSample.GetFileStream("TestCorel.shw", "ole2"));
79+
Assert.Throws<InvalidDataException>(() =>
80+
{
81+
var parser = ParserFactory.CreateMetadata(context);
82+
});
83+
84+
ParserContext context2 = new ParserContext(TestDataSample.GetFileStream("Employee.xls", "Excel"));
85+
var parser = ParserFactory.CreateMetadata(context2);
86+
parser.Parse();
87+
}
7488
}
7589
}

0 commit comments

Comments
 (0)