Skip to content

Commit 7a3250a

Browse files
committed
Add woff2 tests
DEVSIX-1314
1 parent b515e82 commit 7a3250a

File tree

607 files changed

+3924
-0
lines changed

Some content is hidden

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

607 files changed

+3924
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.itextpdf.io.font.woff2;
2+
3+
import org.junit.Assert;
4+
import org.junit.Before;
5+
import org.junit.BeforeClass;
6+
import org.junit.Test;
7+
8+
import java.io.IOException;
9+
10+
public class SimpleWoff2DecodeTest extends Woff2DecodeTest {
11+
12+
private static final String sourceFolder = "./src/test/resources/com/itextpdf/io/font/woff2/SimpleWoff2Decode/";
13+
private static final String targetFolder = "./target/test/com/itextpdf/io/font/woff2/SimpleWoff2Decode/";
14+
15+
@BeforeClass
16+
public static void setUp() {
17+
if (DEBUG) {
18+
createOrClearDestinationFolder(targetFolder);
19+
}
20+
}
21+
22+
@Test
23+
public void simpleTTFTest() throws IOException {
24+
runTest("NotoSansCJKtc-Regular");
25+
}
26+
27+
@Test
28+
public void bigTTCTest() throws IOException {
29+
runTest("NotoSansCJK-Regular");
30+
}
31+
32+
private void runTest(String fontName) throws IOException {
33+
runTest(fontName, sourceFolder, targetFolder, true);
34+
}
35+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.itextpdf.io.font.woff2;
2+
3+
import com.itextpdf.test.ExtendedITextTest;
4+
import com.itextpdf.test.annotations.type.UnitTest;
5+
import org.junit.Assert;
6+
import org.junit.experimental.categories.Category;
7+
8+
import java.io.BufferedOutputStream;
9+
import java.io.FileOutputStream;
10+
import java.io.IOException;
11+
import java.io.OutputStream;
12+
13+
@Category(UnitTest.class)
14+
public abstract class Woff2DecodeTest extends ExtendedITextTest {
15+
protected static boolean DEBUG = true;
16+
17+
protected boolean isDebug() {
18+
return DEBUG;
19+
}
20+
21+
protected final void runTest(String fileName, String sourceFolder, String targetFolder, boolean isFontValid) throws IOException {
22+
final String inFile = fileName + ".woff2";
23+
final String outFile = fileName + ".ttf";
24+
final String cmpFile = "cmp_" + fileName + ".ttf";
25+
byte[] in = null;
26+
byte[] out = null;
27+
byte[] cmp = null;
28+
try {
29+
in = readFile(sourceFolder + inFile);
30+
if (isFontValid) {
31+
Assert.assertTrue(Woff2Converter.isWoff2Font(in));
32+
}
33+
out = Woff2Converter.convert(in);
34+
cmp = readFile(sourceFolder + cmpFile);
35+
Assert.assertTrue("Only valid fonts should reach this", isFontValid);
36+
Assert.assertArrayEquals(cmp, out);
37+
} catch (FontCompressionException e) {
38+
if (isFontValid) {
39+
throw e;
40+
}
41+
} finally {
42+
if (isDebug()) {
43+
saveFile(in, targetFolder + inFile);
44+
saveFile(out, targetFolder + outFile);
45+
saveFile(cmp, targetFolder + cmpFile);
46+
}
47+
}
48+
}
49+
50+
protected final void saveFile(byte[] content, String fileName) throws IOException {
51+
if (content != null) {
52+
OutputStream os = new FileOutputStream(fileName);
53+
os.write(content);
54+
os.close();
55+
}
56+
}
57+
58+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.itextpdf.io.font.woff2.w3c;
2+
3+
import com.itextpdf.io.font.woff2.Woff2DecodeTest;
4+
import org.junit.Before;
5+
import org.junit.Test;
6+
7+
import java.io.BufferedOutputStream;
8+
import java.io.File;
9+
import java.io.FileOutputStream;
10+
import java.io.IOException;
11+
import java.io.OutputStream;
12+
13+
public abstract class W3CWoff2DecodeTest extends Woff2DecodeTest{
14+
private static final String baseSourceFolder = "./src/test/resources/com/itextpdf/io/font/woff2/w3c/";
15+
private static final String baseDestinationFolder = "./target/test/com/itextpdf/io/font/woff2/w3c/";
16+
17+
protected abstract String getFontName();
18+
19+
protected abstract String getTestInfo();
20+
21+
protected abstract boolean isFontValid();
22+
23+
@Before
24+
public void setUp() {
25+
if (isDebug()) {
26+
createOrClearDestinationFolder(getDestinationFolder());
27+
}
28+
}
29+
30+
@Test
31+
public void runTest() throws IOException{
32+
System.out.print("\n" + getTestInfo() + "\n");
33+
runTest(getFontName(), getSourceFolder(), getDestinationFolder(), isFontValid());
34+
}
35+
36+
private String getDestinationFolder() {
37+
String localPackage = getLocalPackage();
38+
return baseDestinationFolder + localPackage + File.separatorChar + getTestClassName() + File.separatorChar;
39+
}
40+
41+
private String getSourceFolder() {
42+
String localPackage = getLocalPackage();
43+
return baseSourceFolder + localPackage + File.separatorChar;
44+
}
45+
46+
private String getTestClassName() {
47+
return getClass().getSimpleName();
48+
}
49+
50+
private String getLocalPackage() {
51+
String packageName = getClass().getPackage().getName();
52+
String basePackageName = W3CWoff2DecodeTest.class.getPackage().getName();
53+
return packageName.substring(basePackageName.length()).replace('.', File.separatorChar);
54+
}
55+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.itextpdf.io.font.woff2.w3c.decoder;
2+
3+
import com.itextpdf.io.font.woff2.w3c.W3CWoff2DecodeTest;
4+
5+
public class ValidationChecksum001Test extends W3CWoff2DecodeTest {
6+
@Override
7+
protected String getFontName() {
8+
return "validation-checksum-001";
9+
}
10+
@Override
11+
protected String getTestInfo() {
12+
return "Valid CFF flavored WOFF file, the output file is put through an OFF validator to check the validity of table checksums.";
13+
}
14+
@Override
15+
protected boolean isFontValid() {
16+
return true;
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.itextpdf.io.font.woff2.w3c.decoder;
2+
3+
import com.itextpdf.io.font.woff2.w3c.W3CWoff2DecodeTest;
4+
5+
public class ValidationChecksum002Test extends W3CWoff2DecodeTest {
6+
@Override
7+
protected String getFontName() {
8+
return "validation-checksum-002";
9+
}
10+
@Override
11+
protected String getTestInfo() {
12+
return "Valid CFF flavored WOFF file, the output file is put through an OFF validator to check the validity of head table checkSumAdjustment.";
13+
}
14+
@Override
15+
protected boolean isFontValid() {
16+
return true;
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.itextpdf.io.font.woff2.w3c.decoder;
2+
3+
import com.itextpdf.io.font.woff2.w3c.W3CWoff2DecodeTest;
4+
5+
public class ValidationLocaFormat001Test extends W3CWoff2DecodeTest {
6+
@Override
7+
protected String getFontName() {
8+
return "validation-loca-format-001";
9+
}
10+
@Override
11+
protected String getTestInfo() {
12+
return "Valid TTF flavored WOFF with simple composite glyphs where the loca table uses the short format, to check loca reconstruction";
13+
}
14+
@Override
15+
protected boolean isFontValid() {
16+
return true;
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.itextpdf.io.font.woff2.w3c.decoder;
2+
3+
import com.itextpdf.io.font.woff2.w3c.W3CWoff2DecodeTest;
4+
5+
public class ValidationLocaFormat002Test extends W3CWoff2DecodeTest {
6+
@Override
7+
protected String getFontName() {
8+
return "validation-loca-format-002";
9+
}
10+
@Override
11+
protected String getTestInfo() {
12+
return "Valid TTF flavored WOFF with simple composite glyphs where the loca table uses the long format, to check loca reconstruction";
13+
}
14+
@Override
15+
protected boolean isFontValid() {
16+
return true;
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.itextpdf.io.font.woff2.w3c.decoder;
2+
3+
import com.itextpdf.io.font.woff2.w3c.W3CWoff2DecodeTest;
4+
5+
public class ValidationOff001Test extends W3CWoff2DecodeTest {
6+
@Override
7+
protected String getFontName() {
8+
return "validation-off-001";
9+
}
10+
@Override
11+
protected String getTestInfo() {
12+
return "Valid WOFF file from the fire format tests, the decoded file should run through a font validator to confirm the OFF structure validity.";
13+
}
14+
@Override
15+
protected boolean isFontValid() {
16+
return true;
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.itextpdf.io.font.woff2.w3c.decoder;
2+
3+
import com.itextpdf.io.font.woff2.w3c.W3CWoff2DecodeTest;
4+
5+
public class ValidationOff002Test extends W3CWoff2DecodeTest {
6+
@Override
7+
protected String getFontName() {
8+
return "validation-off-002";
9+
}
10+
@Override
11+
protected String getTestInfo() {
12+
return "Valid WOFF file from the fire format tests, the decoded file should run through a font validator to confirm the OFF structure validity.";
13+
}
14+
@Override
15+
protected boolean isFontValid() {
16+
return true;
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.itextpdf.io.font.woff2.w3c.decoder;
2+
3+
import com.itextpdf.io.font.woff2.w3c.W3CWoff2DecodeTest;
4+
5+
public class ValidationOff003Test extends W3CWoff2DecodeTest {
6+
@Override
7+
protected String getFontName() {
8+
return "validation-off-003";
9+
}
10+
@Override
11+
protected String getTestInfo() {
12+
return "Valid WOFF file from the fire format tests, the decoded file should run through a font validator to confirm the OFF structure validity.";
13+
}
14+
@Override
15+
protected boolean isFontValid() {
16+
return true;
17+
}
18+
}

0 commit comments

Comments
 (0)