From 3e114ce7aea16507966cb2082084d03c61f78109 Mon Sep 17 00:00:00 2001 From: Andreas Stefl Date: Mon, 5 Oct 2026 03:19:26 +0200 Subject: [PATCH 1/2] test(jni): consolidate overlapping checks and bound startup waits --- jni/tests/app/opendocument/core/FileTest.java | 22 ++++--------------- .../app/opendocument/core/HttpServerTest.java | 15 ++++++++++--- .../app/opendocument/core/LoggerTest.java | 6 ++--- jni/tests/app/opendocument/core/MetaTest.java | 1 + .../app/opendocument/core/PdfFileTest.java | 17 ++++---------- 5 files changed, 24 insertions(+), 37 deletions(-) diff --git a/jni/tests/app/opendocument/core/FileTest.java b/jni/tests/app/opendocument/core/FileTest.java index 2fd69ef80..72221c693 100644 --- a/jni/tests/app/opendocument/core/FileTest.java +++ b/jni/tests/app/opendocument/core/FileTest.java @@ -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()); @@ -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( @@ -181,11 +174,4 @@ void listFileTypes() throws IOException { 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); - } } diff --git a/jni/tests/app/opendocument/core/HttpServerTest.java b/jni/tests/app/opendocument/core/HttpServerTest.java index bae3ceca0..3b46e9695 100644 --- a/jni/tests/app/opendocument/core/HttpServerTest.java +++ b/jni/tests/app/opendocument/core/HttpServerTest.java @@ -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 diff --git a/jni/tests/app/opendocument/core/LoggerTest.java b/jni/tests/app/opendocument/core/LoggerTest.java index f4bbc4458..39bafa82d 100644 --- a/jni/tests/app/opendocument/core/LoggerTest.java +++ b/jni/tests/app/opendocument/core/LoggerTest.java @@ -22,6 +22,7 @@ private static final class Collecting implements ILogger { final List messages = Collections.synchronizedList(new ArrayList<>()); final List locations = Collections.synchronizedList(new ArrayList<>()); volatile int flushes = 0; + volatile boolean consulted = false; private final LogLevel level; Collecting(LogLevel level) { @@ -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(); } @@ -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 diff --git a/jni/tests/app/opendocument/core/MetaTest.java b/jni/tests/app/opendocument/core/MetaTest.java index c604a3b52..b82146a92 100644 --- a/jni/tests/app/opendocument/core/MetaTest.java +++ b/jni/tests/app/opendocument/core/MetaTest.java @@ -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); } diff --git a/jni/tests/app/opendocument/core/PdfFileTest.java b/jni/tests/app/opendocument/core/PdfFileTest.java index 633a0f23b..43fbe269e 100644 --- a/jni/tests/app/opendocument/core/PdfFileTest.java +++ b/jni/tests/app/opendocument/core/PdfFileTest.java @@ -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 From 702b59f493f2c28b3090d20ab89b9b5dd06155ec Mon Sep 17 00:00:00 2001 From: Andreas Stefl Date: Mon, 5 Oct 2026 22:45:27 +0200 Subject: [PATCH 2/2] style(jni): drop the blank line the removed file test left Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01Gb1fLafqqzehpqPuU6uBfn --- jni/tests/app/opendocument/core/FileTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/jni/tests/app/opendocument/core/FileTest.java b/jni/tests/app/opendocument/core/FileTest.java index 72221c693..5b336aaa8 100644 --- a/jni/tests/app/opendocument/core/FileTest.java +++ b/jni/tests/app/opendocument/core/FileTest.java @@ -173,5 +173,4 @@ void listFileTypes() throws IOException { Path odt = TestFiles.odtFile(tempDir); assertTrue(Odr.listFileTypes(odt.toString()).contains(FileType.OPENDOCUMENT_TEXT)); } - }