Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding test case to prove existence of <svg:title> #295

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions odfdom/src/test/java/org/odftoolkit/odfdom/doc/LoadSaveTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
public class LoadSaveTest {

private static final String SOURCE = "not-only-odf.odt";
private static final String SOURCE2 = "svgTitleTest.odt";
private static final String TARGET = "loadsavetest.odt";
private static final String TARGET2 = "loadsavetest2.odt";
private static final String FOREIGN_ATTRIBUTE_NAME = "foreignAttribute";
private static final String FOREIGN_ATTRIBUTE_VALUE = "foreignAttributeValue";
private static final String FOREIGN_ELEMENT_TEXT = "foreignText";
Expand Down Expand Up @@ -101,4 +103,46 @@ public void testLoadSave() {
Assert.fail(e.getMessage());
}
}

@Test
public void testLoadSave2() {
try {
System.out.println("\n\nStarting SVG Title Test (testLoadSave2)");
OdfDocument odfDocument =
OdfDocument.loadDocument(ResourceUtilities.getAbsoluteInputPath(SOURCE2));
Assert.assertTrue(odfDocument.getPackage().contains("content.xml"));
String baseURI1 = odfDocument.getBaseURI();
System.out.println("SOURCE URI: " + baseURI1);

OdfFileDom odfContent = odfDocument.getContentDom();
OfficeDocumentContentElement content =
(OfficeDocumentContentElement) odfContent.getDocumentElement();
NodeList svgTitleList =
odfContent.getElementsByTagNameNS(OdfDocumentNamespace.SVG.getUri(), "title");
Assert.assertTrue(
"There should be a single <svg:title> within the document",
svgTitleList.getLength() == 1);
NodeList svgDescList =
odfContent.getElementsByTagNameNS(OdfDocumentNamespace.SVG.getUri(), "desc");
Assert.assertTrue(
"There should be no <svg:desc> within the document", svgDescList.getLength() == 0);

odfDocument.save(ResourceUtilities.getTestOutputFile(TARGET2));
odfDocument = OdfDocument.loadDocument(ResourceUtilities.getAbsoluteOutputPath(TARGET2));
System.out.println("TARGET: " + ResourceUtilities.getAbsoluteOutputPath(TARGET2));

odfContent = odfDocument.getContentDom();
svgTitleList = odfContent.getElementsByTagNameNS(OdfDocumentNamespace.SVG.getUri(), "title");
Assert.assertTrue(
"There should be a single <svg:title> within the document",
svgTitleList.getLength() == 1);
svgDescList = odfContent.getElementsByTagNameNS(OdfDocumentNamespace.SVG.getUri(), "desc");
Assert.assertTrue(
"There should be no <svg:desc> within the document", svgDescList.getLength() == 0);
} catch (Exception e) {
Logger.getLogger(LoadSaveTest.class.getName())
.log(Level.SEVERE, e.getMessage() + ExceptionUtils.getStackTrace(e), e);
Assert.fail(e.getMessage());
}
}
}
Binary file not shown.
Loading