Skip to content

Commit

Permalink
added unit tests to test serialization and cached model3d content
Browse files Browse the repository at this point in the history
  • Loading branch information
rahelarnold98 committed Aug 28, 2024
1 parent 7e6b509 commit d9ac61b
Showing 1 changed file with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package org.vitrivr.engine.model3d

import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.vitrivr.engine.core.model.content.impl.cache.CachedModel3dContent
import org.vitrivr.engine.core.model.mesh.texturemodel.Material
import org.vitrivr.engine.core.model.mesh.texturemodel.Model3d
import java.io.File
import kotlin.io.path.Path

/**
* Unit tests to check the serialization of 3D models.
*
* @author Rahel Arnold
* @version 1.0.0
*/
class SerializationTest {
/*
* Tests if a 3D model is identical to after serialization and deserialization.
*/
@Test
fun serialization() {
val loader = ModelLoader()
val model = this::class.java.getResourceAsStream("/bunny.obj").use { inp ->
loader.loadModel("bunny", inp!!)
} ?: Assertions.fail("Failed to load model.")

/* Serialize and deserialize model. */
val serialized = Json.encodeToString(model)
val deserialized = Json.decodeFromString<Model3d>(serialized)

/* Check if original and deserialized models are the same. */
Assertions.assertEquals(model, deserialized)
}

/**
* Tests if a 3D model is identical to reloaded one from cache.
*/
@Test
fun cachedModel() {
val tmpPath = Path("./model.json")/* Load model. */
val loader = ModelLoader()
val model = this::class.java.getResourceAsStream("/bunny.obj").use { inp ->
loader.loadModel("bunny", inp!!)
} ?: Assertions.fail("Failed to load model.")

/* Serialize and deserialize model. */
val cachedModel3dContent = CachedModel3dContent(tmpPath, model)
val file = File(tmpPath.toString())
file.delete()

/* Check if original and deserialized models are the same. */
Assertions.assertEquals(model, cachedModel3dContent.content)
}
}

0 comments on commit d9ac61b

Please sign in to comment.