public void testTidyStreamOnInvalidFile() { // Spreadsheet has a good mix of alternate file types POIDataSamples files = POIDataSamples.GetSpreadSheetInstance(); FileInfo[] notValidF = new FileInfo[] { files.GetFileInfo("SampleSS.ods"), files.GetFileInfo("SampleSS.txt") }; Stream[] notValidS = new Stream[] { files.OpenResourceAsStream("SampleSS.ods"), files.OpenResourceAsStream("SampleSS.txt") }; foreach (FileInfo notValid in notValidF) { ZipPackage pkg = new ZipPackage(notValid, PackageAccess.READ); Assert.IsNotNull(pkg.ZipArchive); Assert.IsFalse(pkg.ZipArchive.IsClosed); try { pkg.GetParts(); Assert.Fail("Shouldn't work"); } catch (ODFNotOfficeXmlFileException e) { } catch (NotOfficeXmlFileException ne) { } pkg.Close(); Assert.IsNotNull(pkg.ZipArchive); Assert.IsTrue(pkg.ZipArchive.IsClosed); } foreach (InputStream notValid in notValidS) { ZipPackage pkg = new ZipPackage(notValid, PackageAccess.READ); Assert.IsNotNull(pkg.ZipArchive); Assert.IsFalse(pkg.ZipArchive.IsClosed); try { pkg.GetParts(); Assert.Fail("Shouldn't work"); } catch (ODFNotOfficeXmlFileException e) { } catch (NotOfficeXmlFileException ne) { } pkg.Close(); Assert.IsNotNull(pkg.ZipArchive); Assert.IsTrue(pkg.ZipArchive.IsClosed); } }
public void office2007prettyPrintedRels() { OPCPackage pkg = OPCPackage.Open(testdata.GetFileInfo("office2007prettyPrintedRels.docx"), PackageAccess.READ); try { SignatureConfig sic = new SignatureConfig(); sic.SetOpcPackage(pkg); SignatureInfo si = new SignatureInfo(); si.SetSignatureConfig(sic); bool isValid = si.VerifySignature(); Assert.IsTrue(isValid); } finally { pkg.Close(); } }
protected static String ReadVBA(POIDataSamples poiDataSamples) { FileInfo macro = poiDataSamples.GetFileInfo("SimpleMacro.vba"); byte[] bytes; try { FileStream stream = new FileStream(macro.FullName, FileMode.Open, FileAccess.ReadWrite); try { bytes = IOUtils.ToByteArray(stream); } finally { stream.Close(); } } catch (IOException e) { //throw new Exception(e); throw e; } String testMacroContents = Encoding.UTF8.GetString(bytes); if (!testMacroContents.StartsWith("Sub ")) { throw new ArgumentException("Not a macro"); } return(testMacroContents.Substring(testMacroContents.IndexOf("()") + 3)); }
protected void FromFile(POIDataSamples dataSamples, String filename) { FileInfo f = dataSamples.GetFileInfo(filename); VBAMacroReader r = new VBAMacroReader(f); try { AssertMacroContents(dataSamples, r); } finally { r.Close(); } }
protected void FromNPOIFS(POIDataSamples dataSamples, String filename) { FileInfo f = dataSamples.GetFileInfo(filename); NPOIFSFileSystem fs = new NPOIFSFileSystem(f); try { VBAMacroReader r = new VBAMacroReader(fs); try { AssertMacroContents(dataSamples, r); } finally { r.Close(); } } finally { fs.Close(); } }
public static FileInfo GetSampleFile(string sampleFileName) { return(_inst.GetFileInfo(sampleFileName)); }