Skip to content
Merged
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
23 changes: 4 additions & 19 deletions jni/tests/app/opendocument/core/FileTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ void openOdt() throws IOException {
assertEquals(FileCategory.DOCUMENT, file.fileCategory());
assertTrue(file.isDocumentFile());
assertFalse(file.passwordEncrypted());
FileMeta meta = file.fileMeta();
assertEquals(FileType.OPENDOCUMENT_TEXT, meta.type);
assertFalse(meta.passwordEncrypted);
assertEquals(DocumentType.TEXT, meta.documentType);

DocumentFile documentFile = file.asDocumentFile();
assertEquals(DocumentType.TEXT, documentFile.documentType());
Expand Down Expand Up @@ -140,17 +144,6 @@ void decodeAnOpenFile() throws IOException {
}
}

@Test
void fileMeta() throws IOException {
Path odt = TestFiles.odtFile(tempDir);
try (DecodedFile file = Odr.open(odt.toString())) {
FileMeta meta = file.fileMeta();
assertEquals(FileType.OPENDOCUMENT_TEXT, meta.type);
assertFalse(meta.passwordEncrypted);
assertEquals(DocumentType.TEXT, meta.documentType);
}
}

@Test
void openMissingFileThrows() {
assertThrows(
Expand Down Expand Up @@ -180,12 +173,4 @@ void listFileTypes() throws IOException {
Path odt = TestFiles.odtFile(tempDir);
assertTrue(Odr.listFileTypes(odt.toString()).contains(FileType.OPENDOCUMENT_TEXT));
}

@Test
void documentFileByPath() throws IOException {
Path odt = TestFiles.odtFile(tempDir);
DecodedFile file = Odr.open(odt.toString());
assertEquals(FileType.OPENDOCUMENT_TEXT, file.fileType());
assertEquals(FileType.OPENDOCUMENT_TEXT, file.fileMeta().type);
}
}
15 changes: 12 additions & 3 deletions jni/tests/app/opendocument/core/HttpServerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,19 @@ private static Thread listenInBackground(HttpServer server) throws InterruptedEx
Thread thread = new Thread(server::listen);
thread.setDaemon(true);
thread.start();
while (!server.isRunning()) {
Thread.sleep(1);
long deadline = System.nanoTime() + Duration.ofSeconds(5).toNanos();
try {
while (!server.isRunning()) {
if (!thread.isAlive() || System.nanoTime() >= deadline) {
throw new AssertionError("server did not start listening");
}
Thread.sleep(1);
}
return thread;
} catch (InterruptedException | AssertionError failure) {
server.stop();
throw failure;
}
return thread;
}

@Test
Expand Down
6 changes: 3 additions & 3 deletions jni/tests/app/opendocument/core/LoggerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ private static final class Collecting implements ILogger {
final List<String> messages = Collections.synchronizedList(new ArrayList<>());
final List<SourceLocation> locations = Collections.synchronizedList(new ArrayList<>());
volatile int flushes = 0;
volatile boolean consulted = false;
private final LogLevel level;

Collecting(LogLevel level) {
Expand All @@ -30,6 +31,7 @@ private static final class Collecting implements ILogger {

@Override
public boolean willLog(LogLevel level) {
consulted = true;
return level.ordinal() >= this.level.ordinal();
}

Expand Down Expand Up @@ -88,9 +90,7 @@ void customSinkIsUsableWhileOpening() throws IOException {
DecodedFile file = Odr.open(odt.toString(), logger)) {
assertEquals(FileType.OPENDOCUMENT_TEXT, file.fileType());
}
// The sink survived the native call; whether anything was logged is up to
// the backend, so only the fact that it did not crash is asserted here.
assertNotNull(sink.messages);
assertTrue(sink.consulted);
}

@Test
Expand Down
1 change: 1 addition & 0 deletions jni/tests/app/opendocument/core/MetaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ void capabilitiesByFileType() {
// a pdf renders, but paints its own page backgrounds
FileTypeCapabilities pdf = Odr.capabilitiesByFileType(FileType.PORTABLE_DOCUMENT_FORMAT);
assertTrue(pdf.translateHtml);
assertTrue(pdf.annotate);
assertFalse(pdf.colorScheme);
}

Expand Down
17 changes: 4 additions & 13 deletions jni/tests/app/opendocument/core/PdfFileTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,16 @@ class PdfFileTest {
+ " \"quads\": [[72, 700, 300, 700, 72, 688, 300, 688]],"
+ " \"color\": [1, 0.9, 0.2]}]}";

@Test
void annotateIsDeclaredForPdf() {
assertTrue(Odr.capabilitiesByFileType(FileType.PORTABLE_DOCUMENT_FORMAT).annotate);
}

@Test
void anUnencryptedPdfStatesNoPermissions() throws IOException {
try (DecodedFile file = Odr.open(TestFiles.pdfFile(tempDir).toString())) {
assertNull(file.asPdfFile().permissions());
}
}

@Test
void annotateAppendsToTheSource() throws IOException {
Path pdf = TestFiles.pdfFile(tempDir);
byte[] source = Files.readAllBytes(pdf);

try (DecodedFile file = Odr.open(pdf.toString())) {
byte[] result = file.asPdfFile().annotate(HIGHLIGHT);
PdfFile pdfFile = file.asPdfFile();
assertNull(pdfFile.permissions());
assertTrue(pdfFile.isAnnotatable());
byte[] result = pdfFile.annotate(HIGHLIGHT);

assertTrue(result.length > source.length);
// the source is copied and the annotation appended after it
Expand Down
Loading