Split test for tagged and tagless format. Fix flush in tagless format.

This commit is contained in:
Mikhail Zelenyy 2019-11-05 03:05:31 +03:00
parent be79272ad2
commit d4168fb4d5
2 changed files with 25 additions and 1 deletions

View File

@ -43,6 +43,7 @@ class TaglessEnvelopeFormat(
writeText(dataStart + "\r\n") writeText(dataStart + "\r\n")
writeFully(data.toBytes()) writeFully(data.toBytes())
} }
flush()
} }
override fun Input.readObject(): Envelope { override fun Input.readObject(): Envelope {

View File

@ -21,11 +21,34 @@ class FileEnvelopeTest {
} }
@Test @Test
fun testFileWriteRead() { 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") val tmpPath = Files.createTempFile("dataforge_test", ".df")
Global.io.writeEnvelopeFile(tmpPath,envelope) Global.io.writeEnvelopeFile(tmpPath,envelope)
println(tmpPath.toUri()) println(tmpPath.toUri())
val restored: Envelope = Global.io.readEnvelopeFile(tmpPath) val restored: Envelope = Global.io.readEnvelopeFile(tmpPath)
assertTrue { envelope.contentEquals(restored) } assertTrue { envelope.contentEquals(restored) }
} }
@Test
fun testFileWriteTagless() {
val tmpPath = Files.createTempFile("dataforge_test", ".df")
Global.io.writeEnvelopeFile(tmpPath, envelope, formatFactory = TaglessEnvelopeFormat)
assertTrue { tmpPath.toFile().length() > 0 }
}
@Test
fun testFileWriteReadTagless() {
val tmpPath = Files.createTempFile("dataforge_test", ".df")
Global.io.writeEnvelopeFile(tmpPath, envelope, formatFactory = TaglessEnvelopeFormat)
println(tmpPath.toUri())
val restored: Envelope = Global.io.readEnvelopeFile(tmpPath, formatFactory = TaglessEnvelopeFormat)
assertTrue { envelope.contentEquals(restored) }
}
} }