-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b27ceeb
commit 9496ae9
Showing
12 changed files
with
740 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
POM_NAME=PdfiumAndroid | ||
POM_ARTIFACT_ID=pdfiumandroid | ||
POM_PACKAGING=aar | ||
|
28 changes: 28 additions & 0 deletions
28
PdfiumAndroid/arrow/src/androidTest/java/io/legere/pdfiumandroid/arrow/BasePDFTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package io.legere.pdfiumandroid.arrow | ||
|
||
import android.graphics.RectF | ||
import android.util.Log | ||
import androidx.test.platform.app.InstrumentationRegistry | ||
|
||
@Suppress("unused") | ||
open class BasePDFTest { | ||
|
||
// set to true to skip tests that are not implemented yet | ||
// set to false to force unimplemented tests to fail | ||
val notImplementedAssetValue = false | ||
|
||
val noResultRect = RectF(-1f, -1f, -1f, -1f) | ||
|
||
fun getPdfBytes(filename: String): ByteArray? { | ||
val appContext = InstrumentationRegistry.getInstrumentation().context | ||
val assetManager = appContext.assets | ||
try { | ||
val input = assetManager.open(filename) | ||
return input.readBytes() | ||
} catch (e: Exception) { | ||
Log.e(BasePDFTest::class.simpleName, "Ugh", e) | ||
} | ||
assetManager.close() | ||
return null | ||
} | ||
} |
22 changes: 0 additions & 22 deletions
22
...droid/arrow/src/androidTest/java/io/legere/pdfiumandroid/arrow/ExampleInstrumentedTest.kt
This file was deleted.
Oops, something went wrong.
122 changes: 122 additions & 0 deletions
122
PdfiumAndroid/arrow/src/androidTest/java/io/legere/pdfiumandroid/arrow/PdfDocumentKtFTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
package io.legere.pdfiumandroid.arrow | ||
|
||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import arrow.core.raise.either | ||
import com.google.common.truth.Truth | ||
import io.legere.pdfiumandroid.PdfWriteCallback | ||
import junit.framework.TestCase | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.runBlocking | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.After | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class PdfDocumentKtFTest : BasePDFTest() { | ||
|
||
private lateinit var pdfDocument: PdfDocumentKtF | ||
private var pdfBytes: ByteArray? = null | ||
|
||
@Before | ||
fun setUp() = runBlocking { | ||
pdfBytes = getPdfBytes("f01.pdf") | ||
|
||
TestCase.assertNotNull(pdfBytes) | ||
|
||
pdfDocument = PdfiumCoreKtF(Dispatchers.Unconfined).newDocument(pdfBytes).getOrNull()!! | ||
} | ||
|
||
@After | ||
fun tearDown() = runTest { | ||
pdfDocument.close() | ||
} | ||
|
||
@Test | ||
fun getPageCount() = runTest { | ||
either { | ||
val pageCount = pdfDocument.getPageCount().bind() | ||
|
||
assert(pageCount == 4) { "Page count should be 4" } | ||
} | ||
} | ||
|
||
@Test | ||
fun openPage() = runTest { | ||
either { | ||
val page = pdfDocument.openPage(0).bind() | ||
|
||
TestCase.assertNotNull(page) | ||
} | ||
} | ||
|
||
@Test | ||
fun openPages() = runTest { | ||
either { | ||
val page = pdfDocument.openPages(0, 3).bind() | ||
|
||
assert(page.size == 4) { "Page count should be 4" } | ||
} | ||
} | ||
|
||
@Test | ||
fun getDocumentMeta() = runTest { | ||
either { | ||
val meta = pdfDocument.getDocumentMeta().bind() | ||
|
||
TestCase.assertNotNull(meta) | ||
} | ||
} | ||
|
||
@Test | ||
fun getTableOfContents() = runTest { | ||
either { | ||
// I don't think this test document has a table of contents | ||
val toc = pdfDocument.getTableOfContents().bind() | ||
|
||
TestCase.assertNotNull(toc) | ||
Truth.assertThat(toc.size).isEqualTo(0) | ||
} | ||
} | ||
|
||
@Test | ||
fun openTextPage() = runTest { | ||
either { | ||
val page = pdfDocument.openPage(0).bind() | ||
val textPage = page.openTextPage().bind() | ||
TestCase.assertNotNull(textPage) | ||
} | ||
} | ||
|
||
@Test | ||
fun openTextPages() = runTest { | ||
either { | ||
val textPages = pdfDocument.openTextPages(0, 3).bind() | ||
Truth.assertThat(textPages.size).isEqualTo(4) | ||
} | ||
} | ||
|
||
@Test | ||
fun saveAsCopy() = runTest { | ||
pdfDocument.saveAsCopy(object : PdfWriteCallback { | ||
override fun WriteBlock(data: ByteArray?): Int { | ||
// Truth.assertThat(data?.size).isEqualTo(pdfBytes?.size) | ||
// Truth.assertThat(data).isEqualTo(pdfBytes) | ||
return data?.size ?: 0 | ||
} | ||
}) | ||
} | ||
|
||
fun close() = runTest { | ||
either { | ||
var documentAfterClose: PdfDocumentKtF? | ||
PdfiumCoreKtF(Dispatchers.Unconfined).newDocument(pdfBytes).bind().use { | ||
documentAfterClose = it | ||
} | ||
documentAfterClose?.openPage(0) | ||
}.mapLeft { | ||
Truth.assertThat(it).isInstanceOf(PdfiumKtFErrors.AlreadyClosed::class.java) | ||
} | ||
} | ||
} |
Oops, something went wrong.