Test IO operations with enveloop.

Failed reading file with `readAvaible` (testDataReading)
This commit is contained in:
Mikhail Zelenyy 2019-10-30 18:20:39 +03:00
parent 5ce8ab40d8
commit 72399e852a

View File

@ -1,10 +1,12 @@
package hep.dataforge.io package hep.dataforge.io
import hep.dataforge.context.Global import hep.dataforge.context.Global
import kotlinx.io.core.readAvailable
import org.junit.Test import org.junit.Test
import java.nio.file.Files import java.nio.file.Files
import java.nio.file.Paths import java.nio.file.Paths
import kotlin.test.assertEquals import kotlin.test.assertEquals
import kotlin.test.assertTrue
class BinaryTest { class BinaryTest {
val envelope = Envelope { val envelope = Envelope {
@ -55,4 +57,26 @@ class BinaryTest {
assertEquals(binary.size.toInt(), binary.toBytes().size) assertEquals(binary.size.toInt(), binary.toBytes().size)
} }
@Test
fun testDataReading() {
println(System.getProperty("user.dir"))
val tmpPath = Files.createTempFile("dataforge_test", ".df")
Global.io.writeEnvelopeFile(tmpPath, envelopeFromFile)
val binary = Global.io.readEnvelopeFile(tmpPath).data!!
var sum = 0.0
binary.read {
val dst = DoubleArray(100) { 0.0 }
do {
val flag = readAvailable(dst)
println("$flag : ${dst[0]}")
dst.map {
sum += it
}
} while (flag != -1)
}
assertTrue(sum > 0.0)
}
} }