22
33import android .content .Context ;
44import android .content .res .AssetManager ;
5- import android .util .Log ;
65
76import androidx .test .ext .junit .runners .AndroidJUnit4 ;
87import androidx .test .filters .LargeTest ;
1514import org .junit .runner .RunWith ;
1615
1716import java .io .File ;
18- import java .io .FileInputStream ;
1917import java .io .FileOutputStream ;
2018import java .io .IOException ;
2119import java .io .InputStream ;
2826public class CoreTest {
2927 private File m_testFile ;
3028 private File m_passwordTestFile ;
31- private File m_coreLibTestFile ;
3229
3330 @ Before
3431 public void initializeCore () {
@@ -41,7 +38,6 @@ public void extractTestFile() throws IOException {
4138 Context appCtx = InstrumentationRegistry .getInstrumentation ().getTargetContext ();
4239 m_testFile = new File (appCtx .getCacheDir (), "test.odt" );
4340 m_passwordTestFile = new File (appCtx .getCacheDir (), "password-test.odt" );
44- m_coreLibTestFile = new File (appCtx .getCacheDir (), "style-various-1.odt" );
4541
4642 Context testCtx = InstrumentationRegistry .getInstrumentation ().getContext ();
4743 AssetManager assetManager = testCtx .getAssets ();
@@ -51,9 +47,6 @@ public void extractTestFile() throws IOException {
5147 try (InputStream inputStream = assetManager .open ("password-test.odt" )) {
5248 copy (inputStream , m_passwordTestFile );
5349 }
54- try (InputStream inputStream = assetManager .open ("style-various-1.odt" )) {
55- copy (inputStream , m_coreLibTestFile );
56- }
5750 }
5851
5952 @ After
@@ -64,9 +57,6 @@ public void cleanupTestFile() {
6457 if (null != m_passwordTestFile ) {
6558 m_passwordTestFile .delete ();
6659 }
67- if (null != m_coreLibTestFile ) {
68- m_coreLibTestFile .delete ();
69- }
7060 }
7161
7262 private static void copy (InputStream src , File dst ) throws IOException {
@@ -152,72 +142,4 @@ public void testPasswordProtectedDocumentWithCorrectPassword() {
152142 CoreWrapper .CoreResult coreResult = CoreWrapper .parse (coreOptions );
153143 Assert .assertEquals (0 , coreResult .errorCode );
154144 }
155-
156- @ Test
157- public void testCoreLibraryEditFormat () {
158- // This test exactly mirrors the core library's edit_odt_diff test
159- File cacheDir = InstrumentationRegistry .getInstrumentation ().getTargetContext ().getCacheDir ();
160- File outputPath = new File (cacheDir , "core_output_style" );
161- File cachePath = new File (cacheDir , "core_cache_style" );
162-
163- // Parse the document with editable=true
164- CoreWrapper .CoreOptions coreOptions = new CoreWrapper .CoreOptions ();
165- coreOptions .inputPath = m_coreLibTestFile .getAbsolutePath ();
166- coreOptions .outputPath = outputPath .getPath ();
167- coreOptions .editable = true ;
168- coreOptions .cachePath = cachePath .getPath ();
169-
170- CoreWrapper .CoreResult parseResult = CoreWrapper .parse (coreOptions );
171- Assert .assertEquals ("Parse should succeed" , 0 , parseResult .errorCode );
172-
173- // Use the exact same diff format as the core library test
174- String htmlDiff = "{\" modifiedText\" :{\" /child:16/child:0\" :\" Outasdfsdafdline\" ,\" /child:24/child:0\" :\" Colorasdfasdfasdfed Line\" ,\" /child:6/child:0\" :\" Text hello world!\" }}" ;
175-
176- // Set output path for the edited file
177- File editedFile = new File (cacheDir , "style-various-1_edit_diff" );
178- coreOptions .outputPath = editedFile .getPath ();
179-
180- // Perform the edit
181- CoreWrapper .CoreResult editResult = CoreWrapper .backtranslate (coreOptions , htmlDiff );
182- Assert .assertEquals ("Edit should succeed" , 0 , editResult .errorCode );
183-
184- // Verify the file was created
185- File outputFile = new File (editResult .outputPath );
186- Log .e ("CoreTest" , "Edited file saved to: " + outputFile .getAbsolutePath ());
187- Log .e ("CoreTest" , "File size: " + outputFile .length () + " bytes" );
188- Assert .assertTrue ("Edited file should exist" , outputFile .exists ());
189- Assert .assertTrue ("Edited file should have content" , outputFile .length () > 0 );
190-
191- // Let's verify the edit actually worked by re-parsing the edited file
192- CoreWrapper .CoreOptions verifyOptions = new CoreWrapper .CoreOptions ();
193- verifyOptions .inputPath = outputFile .getAbsolutePath ();
194- File verifyOutput = new File (cacheDir , "verify_output" );
195- verifyOptions .outputPath = verifyOutput .getPath ();
196- verifyOptions .editable = false ;
197- verifyOptions .cachePath = cachePath .getPath ();
198-
199- CoreWrapper .CoreResult verifyResult = CoreWrapper .parse (verifyOptions );
200- Assert .assertEquals ("Edited file should be parseable" , 0 , verifyResult .errorCode );
201- Log .e ("CoreTest" , "Successfully verified edited file can be reopened" );
202-
203- // Try to copy to app's external files directory which should be accessible
204- try {
205- Context appContext = InstrumentationRegistry .getInstrumentation ().getTargetContext ();
206- File externalFilesDir = appContext .getExternalFilesDir (null );
207- if (externalFilesDir != null ) {
208- File externalCopy = new File (externalFilesDir , "edited_test_output.odt" );
209- copy (new java .io .FileInputStream (outputFile ), externalCopy );
210- Log .e ("CoreTest" , "Copied to external: " + externalCopy .getAbsolutePath ());
211-
212- // Also try to make it world-readable
213- externalCopy .setReadable (true , false );
214-
215- // Keep file available for 10 seconds so we can pull it
216- Log .e ("CoreTest" , "Waiting 10 seconds - pull the file now!" );
217- Thread .sleep (10000 );
218- }
219- } catch (Exception e ) {
220- Log .e ("CoreTest" , "Failed to copy to external: " + e .getMessage ());
221- }
222- }
223145}
0 commit comments