Skip to content

Commit 11770a6

Browse files
authored
Merge pull request #44 from levigo/feature/JF-1083_more_consistent_config
Feature/jf 1083 more consistent config
2 parents 8e8af5f + f74cc99 commit 11770a6

File tree

9 files changed

+4372
-4351
lines changed

9 files changed

+4372
-4351
lines changed

src/main/resources/magic-all.xml

Lines changed: 3532 additions & 3532 deletions
Large diffs are not rendered by default.

src/main/resources/magic.xml

Lines changed: 789 additions & 815 deletions
Large diffs are not rendered by default.

src/test/java/TestRTFMatcher.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public static void init() throws AnalyzerException {
3535
void testRtfEmbeddedFiles() throws IOException {
3636
for (File f : nullSafe(EMBEDDED_FILES_FOLDER.listFiles())) {
3737
final Map<String, Object> result = ANALYZER.analyze(f);
38+
TestVariousTypes.printResult(result);
3839
assertNotNull(result, f + " could not be analyzed");
3940
assertEquals("text/rtf", result.get(MimeTypeAction.KEY), f + " is recognized as RTF");
4041
assertValidDetails(result);
@@ -46,6 +47,7 @@ void testRtfEmbeddedFiles() throws IOException {
4647
void testNormalRtfFiles() throws IOException {
4748
for (File f : nullSafe(NORMAL_FOLDER.listFiles())) {
4849
final Map<String, Object> result = ANALYZER.analyze(f);
50+
TestVariousTypes.printResult(result);
4951
assertNotNull(result, f + " could not be analyzed");
5052
assertEquals("text/rtf", result.get(MimeTypeAction.KEY), f + " is recognized as RTF");
5153
assertValidDetails(result);

src/test/java/TestVariousTypes.java

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,37 @@ void testEmptyStream() throws Exception {
6161
assertNotNull(results, "empty stream could not be analyzed");
6262
assertEquals("text/plain", results.get(MimeTypeAction.KEY));
6363
assertEquals("txt", results.get(ExtensionAction.KEY));
64-
assertEquals("Binary data, ASCII Text Document", results.get(DescriptionAction.KEY));
64+
assertEquals("ASCII Text Document", results.get(DescriptionAction.KEY));
6565
}
6666

67-
public static Stream<Arguments> dataProvider() {
67+
public static Stream<Arguments> dataProviderVarious() {
68+
return Stream.of(
69+
arguments("/various_types/test.png", "image/png", "PNG image data, colormap,", "png"),
70+
arguments("/various_types/File-PNG_8pbc_GRAY.png", "image/png", "PNG image data, grayscale,", "png"),
71+
arguments("/various_types/File-PNG_8bpc_RGBA.png", "image/png", "PNG image data, \\b/color RGBA,", "png"),
72+
arguments("/various_types/File-PNG_16bpc_RGBA.png", "image/png", "PNG image data, \\b/color RGBA,", "png"),
73+
arguments("/various_types/sample-rtf-files-sample2.rtf", "text/rtf", "Rich Text Format data", "rtf")
74+
);
75+
}
76+
77+
@ParameterizedTest
78+
@MethodSource("dataProviderVarious")
79+
void testVariousTypesExplicitly(String resource, String expectedMimeType, String expectedDescription, String expectedExtension) throws Exception {
80+
final URL url = getClass().getResource(resource);
81+
assertNotNull(url);
82+
final File file = new File(url.toURI());
83+
final Map<String, Object> results = analyzer.analyze(file);
84+
printResult(results);
85+
assertNotNull(results, file + " could not be analyzed");
86+
assertNotNull(results.get(MimeTypeAction.KEY), "mimeType missing");
87+
assertEquals(expectedMimeType, results.get(MimeTypeAction.KEY), "wrong mimeType");
88+
assertNotNull(results.get(DescriptionAction.KEY), "description missing");
89+
assertEquals(expectedDescription, results.get(DescriptionAction.KEY), "wrong description");
90+
assertNotNull(results.get(ExtensionAction.KEY), "could not be analyzed");
91+
assertEquals(expectedExtension, results.get(ExtensionAction.KEY), "wrong extension");
92+
}
93+
94+
public static Stream<Arguments> dataProviderXRechnung() {
6895
return Stream.of(
6996
arguments("/various_types/BASIC_Einfach.pdf", "application/pdf"),
7097
arguments("/various_types/EN16931_Einfach.pdf", "application/pdf"),
@@ -75,7 +102,7 @@ public static Stream<Arguments> dataProvider() {
75102
}
76103

77104
@ParameterizedTest
78-
@MethodSource("dataProvider")
105+
@MethodSource("dataProviderXRechnung")
79106
void testXRechnung(String resource, String expectedMimeType) throws Exception {
80107
final URL url = getClass().getResource(resource);
81108
assertNotNull(url);
@@ -109,7 +136,7 @@ private void ensureXRechnungIsTrue(final Map<String, Object> results, final Stri
109136
}
110137

111138

112-
private static void printResult(final Map<String, Object> results) {
139+
public static void printResult(final Map<String, Object> results) {
113140
for (final Map.Entry<String, Object> e : results.entrySet()) {
114141
LOGGER.info(" {}={}", e.getKey(), e.getValue());
115142
}
81.1 KB
Loading
65.7 KB
Loading
27.7 KB
Loading
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{\rtf1\mac\deff2 {\fonttbl{\f0\fswiss Chicago;}{\f2\froman New York;}{\f3\fswiss Geneva;}{\f4\fmodern Monaco;}{\f11\fnil Cairo;}{\f13\fnil Zapf Dingbats;}{\f14\fnil Bookman;}{\f15\fnil N Helvetica Narrow;}{\f16\fnil Palatino;}{\f18\fnil Zapf Chancery;}
2+
{\f20\froman Times;}{\f21\fswiss Helvetica;}{\f22\fmodern Courier;}{\f23\ftech Symbol;}{\f33\fnil Avant Garde;}{\f34\fnil New Century Schlbk;}{\f1297\fnil GoudyHundred;}{\f1602\fnil BlackChancery;}{\f2515\fnil MT Extra;}{\f4950\fnil TTYFont;}
3+
{\f11132\fnil InsigniaLQmono;}{\f11133\fnil InsigniaLQprop;}{\f32500\fnil VT320;}{\f32525\fnil VT100;}}{\colortbl\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;\red0\green255\blue0;\red255\green0\blue255;\red255\green0\blue0;
4+
\red255\green255\blue0;\red255\green255\blue255;}{\stylesheet{\s250\li720 \f21\fs20\ul \sbasedon0\snext0 heading 6;}{\s251\li720 \b\f21\fs20 \sbasedon0\snext0 heading 5;}{\s252\li360 \f21\ul \sbasedon0\snext0 heading 4;}{\s253\li360 \b\f21
5+
\sbasedon0\snext0 heading 3;}{\s254\sb120 \b\f21 \sbasedon0\snext0 heading 2;}{\s255\sb240 \b\f21\ul \sbasedon0\snext0 heading 1;}{\f21 \sbasedon222\snext0 Normal;}{\s2 \b\f21\cf1 \sbasedon0\snext2 Anchor;}}{\info{\author Chuck Shotton}}
6+
\margl720\margr720\ftnbj\fracwidth \sectd \sbknone\linemod0\linex0\cols1\endnhere \pard\plain \s255\sb240 \b\f21\ul Heading 1\par
7+
\pard\plain \f21 This is the first normal paragraph!\par
8+
\pard\plain \s254\sb120 \b\f21 Heading 2\par
9+
\pard\plain \s253\li360 \b\f21 Heading 3\par
10+
\pard\plain \s252\li360 \f21\ul Heading 4\par
11+
\pard\plain \s251\li720 \b\f21\fs20 Heading 5\par
12+
\pard\plain \s250\li720 \f21\fs20\ul Heading 6\par
13+
\pard\plain \f21 This is a chunk of normal text.\par
14+
This is a chunk of normal text with specials, &, <, and >.\par
15+
This is a second paragraph.\par
16+
This is text with embedded {\b bold}, {\i italic}, and {\ul underline} styles.\par
17+
Here is the {\cf1 anchor} style. And here is the {\cf5 Image} style.\par
18+
}
3.43 KB
Loading

0 commit comments

Comments
 (0)