Add test for checking data size in DF02 and DF03

This commit is contained in:
Mikhail Zelenyy 2019-11-06 16:10:43 +03:00
parent 9f1cf2fcc3
commit b36ce57290

View File

@ -1,9 +1,13 @@
package hep.dataforge.io package hep.dataforge.io
import hep.dataforge.context.Global import hep.dataforge.context.Global
import java.nio.ByteBuffer
import java.nio.file.Files import java.nio.file.Files
import java.util.*
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue import kotlin.test.assertTrue
import kotlin.test.fail
class FileEnvelopeTest { class FileEnvelopeTest {
@ -61,4 +65,36 @@ class FileEnvelopeTest {
assertTrue { envelope.contentEquals(restored) } assertTrue { envelope.contentEquals(restored) }
} }
@Test
fun testDataSize() {
val tmpPath = Files.createTempFile("dataforge_test", ".df")
Global.io.writeEnvelopeFile(tmpPath, envelope)
println(tmpPath.toUri())
val scan = Scanner(tmpPath.toFile().inputStream()).useDelimiter("\n").nextLine()
println(scan)
val format = scan.slice(2..5)
when (format) {
"DF03" -> {
val buff = ByteBuffer.allocate(4)
buff.put(scan.slice(12..19).toByteArray())
buff.flip()
val size = buff.long
println(size)
assertEquals(8, size)
}
"DF02" -> {
val buff = ByteBuffer.allocate(4)
buff.put(scan.slice(12..15).toByteArray())
buff.flip()
val size = buff.int
println(size)
assertEquals(8, size)
}
else -> {
fail("Format $format don't have test")
}
}
}
} }