Compare commits
8 Commits
master
...
dev-zeleny
Author | SHA1 | Date | |
---|---|---|---|
|
7e74992601 | ||
|
0cf060e93d | ||
|
1dd2b689ca | ||
|
6c4430a5a4 | ||
|
31526c90e1 | ||
|
b36ce57290 | ||
|
9f1cf2fcc3 | ||
|
17fe2f1b66 |
@ -4,6 +4,7 @@ import hep.dataforge.context.Global
|
|||||||
import java.nio.file.Files
|
import java.nio.file.Files
|
||||||
import kotlin.test.Test
|
import kotlin.test.Test
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
class FileBinaryTest {
|
class FileBinaryTest {
|
||||||
val envelope = Envelope {
|
val envelope = Envelope {
|
||||||
@ -53,4 +54,30 @@ class FileBinaryTest {
|
|||||||
assertEquals(binary.size.toInt(), binary.toBytes().size)
|
assertEquals(binary.size.toInt(), binary.toBytes().size)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testMultyPartFileData() {
|
||||||
|
val envelopeList = (0..5).map {
|
||||||
|
val dataFile = Files.createTempFile("dataforge_test_bin_$it", ".bin")
|
||||||
|
dataFile.toFile().writeText(DoubleArray(80000) { it.toDouble() }.joinToString())
|
||||||
|
val envelopeFromFile = Envelope {
|
||||||
|
meta {
|
||||||
|
"a" put "AAA"
|
||||||
|
"b" put 22.2
|
||||||
|
}
|
||||||
|
dataType = "hep.dataforge.satellite"
|
||||||
|
dataID = "cellDepositTest$it" // добавил только что
|
||||||
|
data = dataFile.asBinary()
|
||||||
|
}
|
||||||
|
envelopeFromFile
|
||||||
|
}
|
||||||
|
|
||||||
|
val envelope = Envelope {
|
||||||
|
multipart(TaggedEnvelopeFormat, envelopeList)
|
||||||
|
}
|
||||||
|
println(envelopeList.map { it.data?.size }.joinToString(" "))
|
||||||
|
println(envelope.data?.size)
|
||||||
|
assertTrue { envelope.data!!.size > envelopeList.map { it.data!!.size }.sum() }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -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 {
|
||||||
@ -31,14 +35,68 @@ class FileEnvelopeTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testFileWriteTagged() {
|
||||||
|
val tmpPath = Files.createTempFile("dataforge_test", ".df")
|
||||||
|
Global.io.writeEnvelopeFile(tmpPath, envelope)
|
||||||
|
assertTrue { tmpPath.toFile().length() > 0 }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testFileWriteReadTagged() {
|
||||||
|
val tmpPath = Files.createTempFile("dataforge_test", ".df")
|
||||||
|
Global.io.writeEnvelopeFile(tmpPath, envelope)
|
||||||
|
println(tmpPath.toUri())
|
||||||
|
val restored: Envelope = Global.io.readEnvelopeFile(tmpPath)!!
|
||||||
|
assertTrue { envelope.contentEquals(restored) }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testFileWriteTagless() {
|
||||||
|
val tmpPath = Files.createTempFile("dataforge_test", ".df")
|
||||||
|
Global.io.writeEnvelopeFile(tmpPath, envelope, envelopeFormat = TaglessEnvelopeFormat)
|
||||||
|
assertTrue { tmpPath.toFile().length() > 0 }
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testFileWriteReadTagless() {
|
fun testFileWriteReadTagless() {
|
||||||
Global.io.run {
|
val tmpPath = Files.createTempFile("dataforge_test", ".df")
|
||||||
val tmpPath = Files.createTempFile("dataforge_test_tagless", ".df")
|
Global.io.writeEnvelopeFile(tmpPath, envelope, envelopeFormat = TaglessEnvelopeFormat)
|
||||||
writeEnvelopeFile(tmpPath, envelope, envelopeFormat = TaglessEnvelopeFormat)
|
println(tmpPath.toUri())
|
||||||
println(tmpPath.toUri())
|
val restored: Envelope = Global.io.readEnvelopeFile(tmpPath)!!
|
||||||
val restored: Envelope = readEnvelopeFile(tmpPath)!!
|
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")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user