Skip to content

Commit 7d5ea9a

Browse files
committed
try fix unit test
1 parent 84a260a commit 7d5ea9a

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

app/src/androidTest/java/at/tomtasche/reader/test/CoreTest.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.io.IOException;
1919
import java.io.InputStream;
2020
import java.io.OutputStream;
21+
import java.nio.file.Files;
2122

2223
import at.tomtasche.reader.background.CoreWrapper;
2324

@@ -27,6 +28,12 @@ public class CoreTest {
2728

2829
private File m_testFile;
2930

31+
@Before
32+
public void initializeCore() {
33+
Context testCtx = InstrumentationRegistry.getInstrumentation().getContext();
34+
CoreWrapper.initialize(testCtx);
35+
}
36+
3037
@Before
3138
public void extractTestFile() throws IOException {
3239
Context appCtx = InstrumentationRegistry.getInstrumentation().getTargetContext();
@@ -47,7 +54,7 @@ public void cleanupTestFile() {
4754
}
4855

4956
private static void copy(InputStream src, File dst) throws IOException {
50-
try (OutputStream out = new FileOutputStream(dst)) {
57+
try (OutputStream out = Files.newOutputStream(dst.toPath())) {
5158
byte[] buf = new byte[1024];
5259
int len;
5360
while ((len = src.read(buf)) > 0) {
@@ -58,8 +65,6 @@ private static void copy(InputStream src, File dst) throws IOException {
5865

5966
@Test
6067
public void test() {
61-
CoreWrapper core = new CoreWrapper();
62-
6368
File cacheDir = InstrumentationRegistry.getInstrumentation().getTargetContext().getCacheDir();
6469
File htmlFile = new File(cacheDir, "html");
6570

@@ -68,15 +73,15 @@ public void test() {
6873
coreOptions.outputPath = htmlFile.getPath();
6974
coreOptions.editable = true;
7075

71-
CoreWrapper.CoreResult coreResult = core.parse(coreOptions);
76+
CoreWrapper.CoreResult coreResult = CoreWrapper.parse(coreOptions);
7277
Assert.assertEquals(0, coreResult.errorCode);
7378

7479
File resultFile = new File(cacheDir, "result");
7580
coreOptions.outputPath = resultFile.getPath();
7681

7782
String htmlDiff = "{\"modifiedText\":{\"3\":\"This is a simple test document to demonstrate the DocumentLoadewwwwr example!\"}}";
7883

79-
CoreWrapper.CoreResult result = core.backtranslate(coreOptions, htmlDiff);
84+
CoreWrapper.CoreResult result = CoreWrapper.backtranslate(coreOptions, htmlDiff);
8085
Assert.assertEquals(0, coreResult.errorCode);
8186
}
8287
}

app/src/main/java/at/tomtasche/reader/background/CoreWrapper.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@
99
import java.util.List;
1010

1111
public class CoreWrapper {
12-
1312
static {
1413
System.loadLibrary("odr-core");
1514
}
1615

1716
public static class GlobalParams {
18-
1917
public String coreDataPath;
2018
public String fontconfigDataPath;
2119
public String popplerDataPath;
@@ -47,7 +45,6 @@ public static void initialize(Context context) {
4745
}
4846

4947
public static class CoreOptions {
50-
5148
public boolean ooxml;
5249
public boolean txt;
5350
public boolean pdf;
@@ -68,27 +65,21 @@ public static CoreResult parse(CoreOptions options) {
6865
switch (result.errorCode) {
6966
case 0:
7067
break;
71-
7268
case -1:
7369
result.exception = new CoreCouldNotOpenException();
7470
break;
75-
7671
case -2:
7772
result.exception = new CoreEncryptedException();
7873
break;
79-
8074
case -3:
8175
result.exception = new CoreUnknownErrorException();
8276
break;
83-
8477
case -4:
8578
result.exception = new CoreCouldNotTranslateException();
8679
break;
87-
8880
case -5:
8981
result.exception = new CoreUnexpectedFormatException();
9082
break;
91-
9283
default:
9384
result.exception = new CoreUnexpectedErrorCodeException();
9485
}
@@ -140,7 +131,6 @@ public static void close() {
140131
public static native void stopServer();
141132

142133
public static class CoreResult {
143-
144134
public int errorCode;
145135

146136
public Exception exception;
@@ -168,5 +158,4 @@ public static class CoreUnknownErrorException extends RuntimeException {}
168158
public static class CoreCouldNotEditException extends RuntimeException {}
169159

170160
public static class CoreCouldNotSaveException extends RuntimeException {}
171-
172161
}

0 commit comments

Comments
 (0)