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
Binary file added app/src/androidTest/assets/spreadsheet-test.ods
Binary file not shown.
32 changes: 32 additions & 0 deletions app/src/androidTest/java/at/tomtasche/reader/test/CoreTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
public class CoreTest {
private File m_testFile;
private File m_passwordTestFile;
private File m_spreadsheetTestFile;

@Before
public void initializeCore() {
Expand All @@ -47,6 +48,10 @@ public void extractTestFile() throws IOException {
try (InputStream inputStream = assetManager.open("password-test.odt")) {
copy(inputStream, m_passwordTestFile);
}
m_spreadsheetTestFile = new File(appCtx.getCacheDir(), "spreadsheet-test.ods");
try (InputStream inputStream = assetManager.open("spreadsheet-test.ods")) {
copy(inputStream, m_spreadsheetTestFile);
}
}

@After
Expand All @@ -57,6 +62,9 @@ public void cleanupTestFile() {
if (null != m_passwordTestFile) {
m_passwordTestFile.delete();
}
if (null != m_spreadsheetTestFile) {
m_spreadsheetTestFile.delete();
}
}

private static void copy(InputStream src, File dst) throws IOException {
Expand Down Expand Up @@ -142,4 +150,28 @@ public void testPasswordProtectedDocumentWithCorrectPassword() {
CoreWrapper.CoreResult coreResult = CoreWrapper.parse(coreOptions);
Assert.assertEquals(0, coreResult.errorCode);
}

@Test
public void testSpreadsheetSheetNames() {
File cacheDir = InstrumentationRegistry.getInstrumentation().getTargetContext().getCacheDir();
File outputPath = new File(cacheDir, "spreadsheet_output");
File cachePath = new File(cacheDir, "spreadsheet_cache");

CoreWrapper.CoreOptions coreOptions = new CoreWrapper.CoreOptions();
coreOptions.inputPath = m_spreadsheetTestFile.getAbsolutePath();
coreOptions.outputPath = outputPath.getPath();
coreOptions.editable = false;
coreOptions.cachePath = cachePath.getPath();

CoreWrapper.CoreResult coreResult = CoreWrapper.parse(coreOptions);
Assert.assertEquals("CoreWrapper should successfully parse the ODS file", 0, coreResult.errorCode);

// Verify we have exactly 3 sheets
Assert.assertEquals("ODS file should contain 3 sheets", 3, coreResult.pageNames.size());

// Verify sheet names match the actual sheet names from the ODS file
Assert.assertEquals("First sheet should be named 'hey'", "hey", coreResult.pageNames.get(0));
Assert.assertEquals("Second sheet should be named 'ho'", "ho", coreResult.pageNames.get(1));
Assert.assertEquals("Third sheet should be named 'Sheet3'", "Sheet3", coreResult.pageNames.get(2));
}
}
13 changes: 13 additions & 0 deletions app/src/main/cpp/core_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,19 @@ Java_at_tomtasche_reader_background_CoreWrapper_parseNative(JNIEnv *env, jclass
std::filesystem::remove_all(cachePathCpp);

for (const odr::HtmlPage &page: html.pages()) {
// Filter out unwanted views based on document type
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was there for HTTP mode already, but missing for file-mode

if (file.is_document_file() && (
(((file.as_document_file().document_type() ==
odr::DocumentType::presentation) ||
(file.as_document_file().document_type() ==
odr::DocumentType::drawing)) &&
(page.name != "document")) ||
((file.as_document_file().document_type() ==
odr::DocumentType::spreadsheet) &&
(page.name == "document")))) {
continue;
}

jstring pageName = env->NewStringUTF(page.name.c_str());
env->CallBooleanMethod(pageNames, addMethod, pageName);

Expand Down
Loading