@Test public void testClasspathImage(){ Image img = Image.from_CLASSPATH("/dtpick.gif"); assertEquals(2, TestUtils.regexCount(img.getContent(), "<*w:pict>")); assertEquals(2, TestUtils.regexCount(img.getContent(), "<*v:shapetype")); assertEquals(2, TestUtils.regexCount(img.getContent(), "<*v:shape[ >]")); //white space or > assertEquals(2, TestUtils.regexCount(img.getContent(), "wordml")); assertEquals(1, TestUtils.regexCount(img.getContent(), "width:16pt;height:16pt")); assertEquals(1, TestUtils.regexCount(img.getContent(), "R0lGODlhEAAQAPMAAKVNSkpNpUpNS")); }
@Test public void testGetContent() { IElement par = ParagraphPiece.with("piece01"); assertEquals(1, TestUtils.regexCount(par.getContent(), "<w:r>")); assertEquals(1, TestUtils.regexCount(par.getContent(), "<w:t>piece01</w:t>")); assertEquals(1, TestUtils.regexCount(par.getContent(), "</w:r>")); // if there is no style, shouldn't have this assertEquals(0, TestUtils.regexCount(par.getContent(), "<*w:rPr>")); }
@Test public void testH1(){ Heading1 h1 = Heading1.with("h1"); assertEquals(1, TestUtils.regexCount(h1.getContent(), "<w:p wsp:rsidR*")); assertEquals(1, TestUtils.regexCount(h1.getContent(), "<w:t>h1</w:t>")); assertEquals(1, TestUtils.regexCount(h1.getContent(), "</w:p>")); assertEquals(1, TestUtils.regexCount(h1.getContent(), "<w:pStyle w:val=\"Heading1\" />")); }
@Test public void testAddEleString(){ Header2004 hd = new Header2004(); hd.addEle("<w:t>p1</w:t>"); assertEquals(2, TestUtils.regexCount(hd.getContent(), "<*w:hdr")); assertEquals(1, TestUtils.regexCount(hd.getContent(), "<w:t>p1</w:t>")); }
@Test public void testAaddEleString(){ Body2004 bd = new Body2004(); bd.addEle("<w:p wsp:rsidR=\"008979E8\" wsp:rsidRDefault=\"008979E8\"/>"); //this is a breakline assertEquals(2, TestUtils.regexCount(bd.getContent(), "<*w:body>")); assertEquals(1, TestUtils.regexCount(bd.getContent(), "<w:p wsp:rsidR=\"008979E8\" wsp:rsidRDefault=\"008979E8\"/>")); }
@Test public void testFooterWithNoPageNumber(){ Footer2004 ft = new Footer2004(); ft.showPageNumber(false); ft.addEle(Paragraph.with("p1")); assertEquals(2, TestUtils.regexCount(ft.getContent(), "<*w:ftr")); assertEquals(1, TestUtils.regexCount(ft.getContent(), "<w:t>p1</w:t>")); assertEquals(0, TestUtils.regexCount(ft.getContent(), "<w:rStyle w:val=\"PageNumber\"/>")); }
@Test public void testDefaultEncodingUTF() { IDocument myDoc = new Document2004(); assertEquals(1, TestUtils.regexCount(myDoc.getContent(), "encoding=\"UTF-8\"")); IDocument myDoc02 = new Document2004(); myDoc02.encoding(Encoding.UTF_8); assertEquals(1, TestUtils.regexCount(myDoc02.getContent(), "encoding=\"UTF-8\"")); }
@Test public void testBody() { IDocument myDoc = new Document2004(); assertEquals(1, TestUtils.regexCount(myDoc.getBody().getContent(), "<w:body>")); assertEquals(1, TestUtils.regexCount(myDoc.getBody().getContent(), "</w:body>")); }
@Test(expected = RuntimeException.class) public void readFileTestException() { String res = Utils.readFile(Utils.getAppRoot() + "/src/test/resources/not_a_file"); assertEquals(1, TestUtils.regexCount(res, "FileNotFoundException")); }
@Test public void testWidthAndHeight() throws IOException { Image img = Image.from_FULL_LOCAL_PATHL(Utils.getAppRoot() + "/src/test/resources/base2logo.png"); img.setWidth("121"); img.setHeight("111"); assertEquals(0, TestUtils.regexCount(img.getContent(), "style=\"width:116pt;height:104pt\"")); assertEquals(1, TestUtils.regexCount(img.getContent(), "style=\"width:121pt;height:111pt\"")); }
@Test public void testBreakTimes() { BreakLine br = BreakLine.times(3).create(); int tot = TestUtils .regexCount(br.getContent(), "(<w:p wsp:rsidR=\"008979E8\" wsp:rsidRDefault=\"008979E8\"/>)"); assertEquals(3, tot); }
@Test public void testPageOrientationLandscape() { IDocument doc = new Document2004(); doc.setPageOrientationLandscape(); assertEquals(1, TestUtils.regexCount(doc.getContent(), "landscape")); }
@Test public void testBidiNoValue(){ ParagraphPiece pieces = ParagraphPiece.with("111"); Paragraph p01 = Paragraph.withPieces(pieces); basicParagraphCheckings(p01, "111", null); assertEquals(0, TestUtils.regexCount(p01.getContent(), "<w:lang w:bidi=\".*\" />")); }
@Test public void testBreakNumberConstructor() { BreakLine br = new BreakLine(1); assertEquals( "\n<w:p wsp:rsidR=\"008979E8\" wsp:rsidRDefault=\"008979E8\"/>", br.getContent()); int tot = TestUtils .regexCount(br.getContent(), "(<w:p wsp:rsidR=\"008979E8\" wsp:rsidRDefault=\"008979E8\"/>)"); assertEquals(1, tot); }
@Test public void testStringOnly() { TableV2 tbl = new TableV2(); tbl.addRow( TableRow.with("str01", "str02").withStyle().repeatTableHeaderOnEveryPage().create() ); assertEquals(1, TestUtils.regexCount(tbl.getContent(), "<w:t>str01</w:t>")); assertEquals(1, TestUtils.regexCount(tbl.getContent(), "<w:t>str02</w:t>")); tableBasicCheckings(tbl.getContent()); }
@Test public void testParagraphIndentStyle() { Paragraph p01 = (Paragraph) Paragraph.with("111").withStyle().indent(ParagraphStyle.Indent.ONE).create(); assertEquals(1, TestUtils.regexCount(p01.getContent(), "w:left=\"540\"")); }
@Test public void testCaps() { IElement par = ParagraphPiece.with("piece01").withStyle().caps().create(); doBasicChecking(par, "piece01"); assertEquals(1, TestUtils.regexCount(par.getContent(), "<w:caps/>")); }
@Test public void testShadow() { IElement par = ParagraphPiece.with("piece01").withStyle().shadow().create(); doBasicChecking(par, "piece01"); assertEquals(1, TestUtils.regexCount(par.getContent(), "<w:shadow/>")); }
@Test public void testVanish() { IElement par = ParagraphPiece.with("piece01").withStyle().vanish().create(); doBasicChecking(par, "piece01"); assertEquals(1, TestUtils.regexCount(par.getContent(), "<w:vanish/>")); }
@Test public void testBidi(){ ParagraphPiece par = ParagraphPiece.with("111").withStyle().bidi("HE").create(); doBasicChecking(par, "111"); assertEquals(1, TestUtils.regexCount(par.getContent(), "<w:lang w:bidi=\".*\" />")); }